finance.jsx 24 KB

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