finance.jsx 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  1. import React from 'react';
  2. import { Icon, Form, Button, Input, Spin, Table, message, Select, Modal, InputNumber, Upload } from 'antd';
  3. import './techProduct.less';
  4. import { beforeUploadFile, newDownloadFile } from '../../tools.js';
  5. import moment from 'moment';
  6. import ajax from 'jquery/src/ajax/xhr.js';
  7. import $ from 'jquery/src/ajax';
  8. const FinanceDescFrom = Form.create()(React.createClass({
  9. loadData(year) {
  10. this.setState({
  11. loading: true
  12. });
  13. $.ajax({
  14. method: "get",
  15. dataType: "json",
  16. crossDomain: false,
  17. url: globalConfig.context + "/api/user/cognizance/financeDetail",
  18. data: {
  19. year: year != undefined ? year : this.props.data.year
  20. }
  21. }).done((data) => {
  22. if (!data.data) {
  23. if (data.error && data.error.length) {
  24. message.warning(data.error[0].message);
  25. };
  26. return;
  27. };
  28. this.setState({
  29. managementCost: data.data.managementCost,
  30. researchCost: data.data.researchCost,
  31. grossProfit: data.data.grossProfit,
  32. operatingProfit: data.data.operatingProfit
  33. });
  34. }).always(function () {
  35. this.setState({
  36. loading: false
  37. });
  38. }.bind(this));
  39. },
  40. getInitialState() {
  41. return {
  42. loading: false,
  43. yearOption: [],
  44. };
  45. },
  46. componentWillMount() {
  47. let d = new Date();
  48. let _me = this;
  49. d = d.getFullYear();
  50. for (let i = d; i > d - 20; i--) {
  51. _me.state.yearOption.push(
  52. <Select.Option value={i.toString()} key={i}>{i}</Select.Option>
  53. )
  54. };
  55. if (this.props.data.year) {
  56. this.loadData();
  57. };
  58. },
  59. handleSubmit(e) {
  60. e.preventDefault();
  61. if (!this.state.year && !this.props.data.year) {
  62. message.warning("请选择一个年份!")
  63. return;
  64. };
  65. this.props.form.validateFields((err, values) => {
  66. if (!err) {
  67. this.props.spinState(true);
  68. $.ajax({
  69. method: "POST",
  70. dataType: "json",
  71. crossDomain: false,
  72. url: globalConfig.context + "/api/user/cognizance/disposeFinance",
  73. data: {
  74. id: this.props.data.id,
  75. mainBusinessIncome: values.mainBusinessIncome,
  76. managementCost: values.managementCost,
  77. researchCost: values.researchCost,
  78. operatingProfit: values.operatingProfit,
  79. variousTax: values.variousTax,
  80. currentAsset: values.currentAsset,
  81. netFixedAsset: values.netFixedAsset,
  82. totalAsset: values.totalAsset,
  83. netAsset: values.netAsset,
  84. grossProfit: values.grossProfit,
  85. netProfit: values.netProfit,
  86. salesRevenue: values.salesRevenue,
  87. year: this.state.year || this.props.data.year,
  88. financeUrl: this.state.financeUrl
  89. }
  90. }).done(function (data) {
  91. if (!data.error.length) {
  92. message.success('保存成功!');
  93. this.props.clickOk();
  94. this.props.spinState(false);
  95. this.props.form.resetFields();
  96. } else {
  97. message.warning(data.error[0].message);
  98. this.props.spinState(false);
  99. }
  100. }.bind(this));
  101. }
  102. });
  103. },
  104. componentWillReceiveProps(nextProps) {
  105. if (!this.props.visible && nextProps.visible) {
  106. if (nextProps.data.year) {
  107. this.loadData(nextProps.data.year);
  108. };
  109. this.props.form.resetFields();
  110. this.state.managementCost = undefined;
  111. this.state.researchCost = undefined;
  112. this.state.grossProfit = undefined;
  113. this.state.operatingProfit = undefined;
  114. this.state.fileList = [];
  115. };
  116. },
  117. checkResearchCost(rule, value, callback) {
  118. const form = this.props.form;
  119. if (value > form.getFieldValue('managementCost')) {
  120. callback('管理费用小于研发费用!');
  121. } else {
  122. callback();
  123. }
  124. },
  125. render() {
  126. const FormItem = Form.Item;
  127. const { getFieldDecorator } = this.props.form;
  128. const theData = this.props.data;
  129. const formItemLayout = {
  130. labelCol: { span: 8 },
  131. wrapperCol: { span: 16 },
  132. };
  133. const _me = this;
  134. return (
  135. <Form onSubmit={this.handleSubmit} className="activityCost-form">
  136. <div className="activityCost-title"><span>年份: </span>
  137. {
  138. theData.year ? <span>{theData.year}</span> :
  139. <Select placeholder="请选择年份" style={{ width: 200 }}
  140. onSelect={(e, n) => { this.state.year = e, this.loadData(e); }}>
  141. {this.state.yearOption}
  142. </Select>
  143. }
  144. </div>
  145. <div className="clearfix">
  146. <FormItem className="half-item"
  147. {...formItemLayout}
  148. label="主营业务收入(万元)"
  149. >
  150. {getFieldDecorator('mainBusinessIncome', {
  151. rules: [{ type: 'number', required: true, message: '此项为必填项!' }],
  152. initialValue: theData.mainBusinessIncome
  153. })(
  154. <InputNumber min={0} max={999999} step={0.01} />
  155. )}
  156. </FormItem>
  157. <FormItem className="half-item"
  158. {...formItemLayout}
  159. label="管理费用(万元)"
  160. >
  161. {getFieldDecorator('managementCost', {
  162. rules: [{ type: 'number', required: true, message: '此项为必填项!' }],
  163. initialValue: theData.managementCost
  164. })(
  165. <InputNumber min={0} max={999999} step={0.01} />
  166. )}
  167. {this.state.managementCost && this.state.managementCost != this.props.form.getFieldValue('managementCost') ? <span style={{ color: '#f50' }}>与财务报表不一致!</span> : <span></span>}
  168. </FormItem>
  169. <FormItem className="half-item"
  170. {...formItemLayout}
  171. label="研发费用(万元)"
  172. >
  173. {getFieldDecorator('researchCost', {
  174. rules: [
  175. { type: 'number', required: true, message: '此项为必填项!' }, {
  176. validator: this.checkResearchCost,
  177. }],
  178. initialValue: theData.researchCost
  179. })(
  180. <InputNumber min={0} max={999999} step={0.01} />
  181. )}
  182. {this.state.researchCost && this.state.researchCost != this.props.form.getFieldValue('researchCost') ? <span style={{ color: '#f50' }}>与财务报表不一致!</span> : <span></span>}
  183. </FormItem>
  184. <FormItem className="half-item"
  185. {...formItemLayout}
  186. label="营业利润(万元)"
  187. >
  188. {getFieldDecorator('operatingProfit', {
  189. rules: [{ type: 'number', required: true, message: '此项为必填项!' }],
  190. initialValue: theData.operatingProfit
  191. })(
  192. <InputNumber min={0} max={999999} step={0.01} />
  193. )}
  194. {this.state.operatingProfit && this.state.operatingProfit != this.props.form.getFieldValue('operatingProfit') ? <span style={{ color: '#f50' }}>与财务报表不一致!</span> : <span></span>}
  195. </FormItem>
  196. <FormItem className="half-item"
  197. {...formItemLayout}
  198. label="支付的各项税费(万元)"
  199. >
  200. {getFieldDecorator('variousTax', {
  201. rules: [{ type: 'number', required: true, message: '此项为必填项!' }],
  202. initialValue: theData.variousTax
  203. })(
  204. <InputNumber min={0} max={999999} step={0.01} />
  205. )}
  206. </FormItem>
  207. <FormItem className="half-item"
  208. {...formItemLayout}
  209. label="流动资产(万元)"
  210. >
  211. {getFieldDecorator('currentAsset', {
  212. rules: [{ type: 'number', required: true, message: '此项为必填项!' }],
  213. initialValue: theData.currentAsset
  214. })(
  215. <InputNumber min={0} max={999999} step={0.01} />
  216. )}
  217. </FormItem>
  218. <FormItem className="half-item"
  219. {...formItemLayout}
  220. label="固定资产净额(万元)"
  221. >
  222. {getFieldDecorator('netFixedAsset', {
  223. rules: [{ type: 'number', required: true, message: '此项为必填项!' }],
  224. initialValue: theData.netFixedAsset
  225. })(
  226. <InputNumber min={0} max={999999} step={0.01} />
  227. )}
  228. </FormItem>
  229. <FormItem className="half-item"
  230. {...formItemLayout}
  231. label="资产总额(万元)"
  232. >
  233. {getFieldDecorator('totalAsset', {
  234. rules: [{ type: 'number', required: true, message: '此项为必填项!' }],
  235. initialValue: theData.totalAsset
  236. })(
  237. <InputNumber min={0} max={999999} step={0.01} />
  238. )}
  239. </FormItem>
  240. <FormItem className="half-item"
  241. {...formItemLayout}
  242. label="所有者权益合计(万元)"
  243. >
  244. {getFieldDecorator('netAsset', {
  245. rules: [{ type: 'number', required: true, message: '此项为必填项!' }],
  246. initialValue: theData.netAsset
  247. })(
  248. <InputNumber min={0} max={999999} step={0.01} />
  249. )}
  250. </FormItem>
  251. <FormItem className="half-item"
  252. {...formItemLayout}
  253. label="利润总额(万元)"
  254. >
  255. {getFieldDecorator('grossProfit', {
  256. rules: [{ type: 'number', required: true, message: '此项为必填项!' }],
  257. initialValue: theData.grossProfit
  258. })(
  259. <InputNumber min={0} max={999999} step={0.01} />
  260. )}
  261. {this.state.grossProfit && this.state.grossProfit != this.props.form.getFieldValue('grossProfit') ? <span style={{ color: '#f50' }}>与财务报表不一致!</span> : <span></span>}
  262. </FormItem>
  263. <FormItem className="half-item"
  264. {...formItemLayout}
  265. label="净利润(万元)"
  266. >
  267. {getFieldDecorator('netProfit', {
  268. rules: [{ type: 'number', required: true, message: '此项为必填项!' }],
  269. initialValue: theData.netProfit
  270. })(
  271. <InputNumber min={0} max={999999} step={0.01} />
  272. )}
  273. </FormItem>
  274. <FormItem className="half-item"
  275. {...formItemLayout}
  276. label="销售收入(万元)"
  277. >
  278. {getFieldDecorator('salesRevenue', {
  279. rules: [{ type: 'number', required: true, message: '此项为必填项!' }],
  280. initialValue: theData.salesRevenue
  281. })(
  282. <InputNumber min={0} max={999999} step={0.01} />
  283. )}
  284. </FormItem>
  285. </div>
  286. <div className="hrSituation-roster">
  287. <Upload
  288. name="ratepay"
  289. action={globalConfig.context + "/api/user/cognizance/uploadFinance"}
  290. data={{ 'sign': 'finance', year: this.state.year || theData.year }}
  291. beforeUpload={beforeUploadFile}
  292. fileList={this.state.fileList}
  293. onChange={(info) => {
  294. if (info.file.status !== 'uploading') {
  295. console.log(info.file, info.fileList);
  296. }
  297. if (info.file.status === 'done') {
  298. if (!info.file.response.error.length) {
  299. message.success(`${info.file.name} 文件上传成功!`);
  300. } else {
  301. message.warning(info.file.response.error[0].message);
  302. return;
  303. };
  304. this.state.financeUrl = info.file.response.data;
  305. } else if (info.file.status === 'error') {
  306. message.error(`${info.file.name} 文件上传失败。`);
  307. };
  308. this.setState({ fileList: info.fileList.slice(-1) });
  309. }}
  310. >
  311. <Button><Icon type="upload" /> 上传企业财务报表 </Button>
  312. </Upload>
  313. <p style={{ marginTop: '10px' }}>{theData.financeUrl ? <a onClick={newDownloadFile.bind(null, theData.id, 'finance', '/api/user/cognizance/downloadFinance')}>{theData.financeDownloadFileName}</a> : <span><Icon type="exclamation-circle" style={{ color: '#ffbf00', marginRight: '6px' }} />未上传!</span>}</p>
  314. </div>
  315. <FormItem style={{ marginTop: '20px' }}>
  316. <Button className="set-submit" type="primary" htmlType="submit">保存</Button>
  317. <Button type="ghost" style={{ marginLeft: '20px' }} onClick={this.props.closeModal}>取消</Button>
  318. </FormItem>
  319. </Form >
  320. );
  321. },
  322. }));
  323. const FinanceDesc = React.createClass({
  324. getInitialState() {
  325. return {
  326. visible: false,
  327. loading: false
  328. };
  329. },
  330. componentWillReceiveProps(nextProps) {
  331. this.state.visible = nextProps.showDesc
  332. },
  333. showModal() {
  334. this.setState({
  335. visible: true,
  336. });
  337. },
  338. handleOk() {
  339. this.setState({
  340. visible: false,
  341. });
  342. this.props.closeDesc(false, true);
  343. },
  344. handleCancel(e) {
  345. this.setState({
  346. visible: false,
  347. });
  348. this.props.closeDesc(false);
  349. },
  350. spinChange(e) {
  351. this.setState({
  352. loading: e
  353. });
  354. },
  355. render() {
  356. return (
  357. <div className="patent-addNew">
  358. <Modal maskClosable={false} title="财务报表信息" visible={this.state.visible}
  359. onOk={this.handleOk} onCancel={this.handleCancel}
  360. width='800px'
  361. footer='' >
  362. <Spin spinning={this.state.loading} className='spin-box'>
  363. <FinanceDescFrom
  364. visible={this.state.visible}
  365. data={this.props.data}
  366. spinState={this.spinChange} closeModal={this.handleCancel} clickOk={this.handleOk} />
  367. </Spin>
  368. </Modal>
  369. </div>
  370. );
  371. },
  372. });
  373. const Finance = React.createClass({
  374. loadData(pageNo) {
  375. this.state.data = [];
  376. this.setState({
  377. loading: true
  378. });
  379. $.ajax({
  380. method: "get",
  381. dataType: "json",
  382. crossDomain: false,
  383. url: globalConfig.context + "/api/user/cognizance/finance",
  384. data: {
  385. pageNo: pageNo || 1,
  386. pageSize: this.state.pagination.pageSize,
  387. }
  388. }).done((data) => {
  389. if (!data.data) {
  390. if (data.error && data.error.length) {
  391. message.warning(data.error[0].message);
  392. this.state.ButtonDisabled = true;
  393. }
  394. return;
  395. };
  396. for (let i = 0; i < data.data.list.length; i++) {
  397. let thisdata = data.data.list[i];
  398. this.state.data.push({
  399. key: i,
  400. id: thisdata.id,
  401. uid: thisdata.uid,
  402. mainBusinessIncome: thisdata.mainBusinessIncome,
  403. managementCost: thisdata.managementCost,
  404. operatingProfit: thisdata.operatingProfit,
  405. variousTax: thisdata.variousTax,
  406. currentAsset: thisdata.currentAsset,
  407. netFixedAsset: thisdata.netFixedAsset,
  408. totalAsset: thisdata.totalAsset,
  409. netAsset: thisdata.netAsset,
  410. grossProfit: thisdata.grossProfit,
  411. netProfit: thisdata.netProfit,
  412. salesRevenue: thisdata.salesRevenue,
  413. researchCost: thisdata.researchCost,
  414. year: thisdata.year,
  415. financeUrl: thisdata.financeUrl,
  416. financeDownloadFileName: thisdata.financeDownloadFileName,
  417. finance: [thisdata.id, thisdata.financeDownloadFileName]
  418. });
  419. };
  420. this.state.pagination.current = data.data.pageNo;
  421. this.state.pagination.total = data.data.totalCount;
  422. this.setState({
  423. dataSource: this.state.data,
  424. pagination: this.state.pagination
  425. });
  426. }).always(function () {
  427. this.setState({
  428. loading: false
  429. });
  430. }.bind(this));
  431. },
  432. getInitialState() {
  433. return {
  434. selectedRowKeys: [],
  435. selectedRows: [],
  436. loading: false,
  437. pagination: {
  438. defaultCurrent: 1,
  439. defaultPageSize: 10,
  440. showQuickJumper: true,
  441. pageSize: 10,
  442. onChange: function (page) {
  443. this.loadData(page);
  444. }.bind(this),
  445. showTotal: function (total) {
  446. return '共' + total + '条数据';
  447. }
  448. },
  449. columns: [
  450. {
  451. title: '年份',
  452. dataIndex: 'year',
  453. key: 'year'
  454. }, {
  455. title: '主营业务收入(万元)',
  456. dataIndex: 'mainBusinessIncome',
  457. key: 'mainBusinessIncome'
  458. }, {
  459. title: '管理费用(万元)',
  460. dataIndex: 'managementCost',
  461. key: 'managementCost'
  462. }, {
  463. title: '营业利润(万元)',
  464. dataIndex: 'operatingProfit',
  465. key: 'operatingProfit',
  466. }, {
  467. title: '支付的各项税费(万元)',
  468. dataIndex: 'variousTax',
  469. key: 'variousTax',
  470. }, {
  471. title: '资产总额(万元)',
  472. dataIndex: 'totalAsset',
  473. key: 'totalAsset',
  474. }, {
  475. title: '所有者权益(净资产)(万元)',
  476. dataIndex: 'netAsset',
  477. key: 'netAsset',
  478. }, {
  479. title: '相关附件',
  480. dataIndex: 'finance',
  481. key: 'finance',
  482. render: (text) => {
  483. return <a onClick={newDownloadFile.bind(null, text[0], 'finance', '/api/user/cognizance/downloadFinance')}>{text[1]}</a>
  484. }
  485. }
  486. ],
  487. dataSource: []
  488. };
  489. },
  490. componentWillMount() {
  491. this.loadData();
  492. },
  493. tableRowClick(record, index) {
  494. this.state.RowData = record;
  495. this.setState({
  496. showDesc: true
  497. });
  498. },
  499. delectRow() {
  500. let deletedIds = [];
  501. for (let idx = 0; idx < this.state.selectedRows.length; idx++) {
  502. let rowItem = this.state.selectedRows[idx];
  503. if (rowItem.id) {
  504. deletedIds.push(rowItem.id)
  505. }
  506. }
  507. this.setState({
  508. selectedRowKeys: [],
  509. loading: deletedIds.length > 0
  510. });
  511. $.ajax({
  512. method: "POST",
  513. dataType: "json",
  514. crossDomain: false,
  515. url: globalConfig.context + "/api/user/cognizance/deleteFinance",
  516. data: {
  517. ids: deletedIds
  518. }
  519. }).done(function (data) {
  520. if (!data.error.length) {
  521. message.success('删除成功!');
  522. this.setState({
  523. loading: false,
  524. });
  525. } else {
  526. message.warning(data.error[0].message);
  527. };
  528. this.loadData();
  529. }.bind(this));
  530. },
  531. closeDesc(e, s) {
  532. this.state.showDesc = e;
  533. if (s) {
  534. this.loadData();
  535. };
  536. },
  537. search() {
  538. this.loadData();
  539. },
  540. reset() {
  541. this.loadData();
  542. },
  543. render() {
  544. const rowSelection = {
  545. selectedRowKeys: this.state.selectedRowKeys,
  546. onChange: (selectedRowKeys, selectedRows) => {
  547. this.setState({
  548. selectedRows: selectedRows,
  549. selectedRowKeys: selectedRowKeys
  550. });
  551. }
  552. };
  553. const hasSelected = this.state.selectedRowKeys.length > 0;
  554. return (
  555. <div className="user-content" >
  556. <div className="content-title">
  557. <span>财务报表信息</span>
  558. </div>
  559. <div className="user-search">
  560. <p>
  561. <Button style={{ background: "#ea0862", border: "none", color: "#fff" }}
  562. disabled={this.state.ButtonDisabled}
  563. onClick={this.tableRowClick}>添加<Icon type="plus" /></Button>
  564. <Button style={{ background: "#3fcf9e", border: "none", color: "#fff" }}
  565. disabled={!hasSelected}
  566. onClick={this.delectRow}>删除<Icon type="minus" /></Button>
  567. </p>
  568. </div>
  569. <div className="patent-table">
  570. <Spin spinning={this.state.loading}>
  571. <Table columns={this.state.columns}
  572. dataSource={this.state.dataSource}
  573. pagination={this.state.pagination}
  574. rowSelection={rowSelection}
  575. onRowClick={this.tableRowClick} />
  576. </Spin>
  577. </div>
  578. <FinanceDesc
  579. data={this.state.RowData}
  580. showDesc={this.state.showDesc} closeDesc={this.closeDesc} />
  581. </div >
  582. );
  583. }
  584. });
  585. export default Finance;