finance.jsx 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  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 />
  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 />
  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 />
  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 />
  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 />
  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 />
  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 />
  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 />
  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 />
  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 />
  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 />
  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 />
  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. <Spin spinning={this.state.loading} className='spin-box'>
  359. <Modal title="财务报表信息" visible={this.state.visible}
  360. onOk={this.handleOk} onCancel={this.handleCancel}
  361. width='800px'
  362. footer=''
  363. >
  364. <FinanceDescFrom
  365. visible={this.state.visible}
  366. data={this.props.data}
  367. spinState={this.spinChange} closeModal={this.handleCancel} clickOk={this.handleOk} />
  368. </Modal>
  369. </Spin>
  370. </div>
  371. );
  372. },
  373. });
  374. const Finance = React.createClass({
  375. loadData(pageNo) {
  376. this.state.data = [];
  377. this.setState({
  378. loading: true
  379. });
  380. $.ajax({
  381. method: "get",
  382. dataType: "json",
  383. crossDomain: false,
  384. url: globalConfig.context + "/api/user/cognizance/finance",
  385. data: {
  386. pageNo: pageNo || 1,
  387. pageSize: this.state.pagination.pageSize,
  388. }
  389. }).done((data) => {
  390. if (!data.data) {
  391. if (data.error && data.error.length) {
  392. message.warning(data.error[0].message);
  393. this.state.ButtonDisabled = true;
  394. }
  395. return;
  396. };
  397. for (let i = 0; i < data.data.list.length; i++) {
  398. let thisdata = data.data.list[i];
  399. this.state.data.push({
  400. key: i,
  401. id: thisdata.id,
  402. uid: thisdata.uid,
  403. mainBusinessIncome: thisdata.mainBusinessIncome,
  404. managementCost: thisdata.managementCost,
  405. operatingProfit: thisdata.operatingProfit,
  406. variousTax: thisdata.variousTax,
  407. currentAsset: thisdata.currentAsset,
  408. netFixedAsset: thisdata.netFixedAsset,
  409. totalAsset: thisdata.totalAsset,
  410. netAsset: thisdata.netAsset,
  411. grossProfit: thisdata.grossProfit,
  412. netProfit: thisdata.netProfit,
  413. salesRevenue: thisdata.salesRevenue,
  414. researchCost: thisdata.researchCost,
  415. year: thisdata.year,
  416. financeUrl: thisdata.financeUrl,
  417. financeDownloadFileName: thisdata.financeDownloadFileName,
  418. finance: [thisdata.id, thisdata.financeDownloadFileName]
  419. });
  420. };
  421. this.state.pagination.current = data.data.pageNo;
  422. this.state.pagination.total = data.data.totalCount;
  423. this.setState({
  424. dataSource: this.state.data,
  425. pagination: this.state.pagination
  426. });
  427. }).always(function () {
  428. this.setState({
  429. loading: false
  430. });
  431. }.bind(this));
  432. },
  433. getInitialState() {
  434. return {
  435. selectedRowKeys: [],
  436. selectedRows: [],
  437. loading: false,
  438. pagination: {
  439. defaultCurrent: 1,
  440. defaultPageSize: 10,
  441. showQuickJumper: true,
  442. pageSize: 10,
  443. onChange: function (page) {
  444. this.loadData(page);
  445. }.bind(this),
  446. showTotal: function (total) {
  447. return '共' + total + '条数据';
  448. }
  449. },
  450. columns: [
  451. {
  452. title: '年份',
  453. dataIndex: 'year',
  454. key: 'year'
  455. }, {
  456. title: '主营业务收入(万元)',
  457. dataIndex: 'mainBusinessIncome',
  458. key: 'mainBusinessIncome'
  459. }, {
  460. title: '管理费用(万元)',
  461. dataIndex: 'managementCost',
  462. key: 'managementCost'
  463. }, {
  464. title: '营业利润(万元)',
  465. dataIndex: 'operatingProfit',
  466. key: 'operatingProfit',
  467. }, {
  468. title: '支付的各项税费(万元)',
  469. dataIndex: 'variousTax',
  470. key: 'variousTax',
  471. }, {
  472. title: '资产总额(万元)',
  473. dataIndex: 'totalAsset',
  474. key: 'totalAsset',
  475. }, {
  476. title: '所有者权益(净资产)(万元)',
  477. dataIndex: 'netAsset',
  478. key: 'netAsset',
  479. }, {
  480. title: '相关附件',
  481. dataIndex: 'finance',
  482. key: 'finance',
  483. render: (text) => {
  484. return <a onClick={newDownloadFile.bind(null, text[0], 'finance', '/api/user/cognizance/downloadFinance')}>{text[1]}</a>
  485. }
  486. }
  487. ],
  488. dataSource: []
  489. };
  490. },
  491. componentWillMount() {
  492. this.loadData();
  493. },
  494. tableRowClick(record, index) {
  495. this.state.RowData = record;
  496. this.setState({
  497. showDesc: true
  498. });
  499. },
  500. delectRow() {
  501. let deletedIds = [];
  502. for (let idx = 0; idx < this.state.selectedRows.length; idx++) {
  503. let rowItem = this.state.selectedRows[idx];
  504. if (rowItem.id) {
  505. deletedIds.push(rowItem.id)
  506. }
  507. }
  508. this.setState({
  509. selectedRowKeys: [],
  510. loading: deletedIds.length > 0
  511. });
  512. $.ajax({
  513. method: "POST",
  514. dataType: "json",
  515. crossDomain: false,
  516. url: globalConfig.context + "/api/user/cognizance/deleteFinance",
  517. data: {
  518. ids: deletedIds
  519. }
  520. }).done(function (data) {
  521. if (!data.error.length) {
  522. message.success('删除成功!');
  523. this.setState({
  524. loading: false,
  525. });
  526. } else {
  527. message.warning(data.error[0].message);
  528. };
  529. this.loadData();
  530. }.bind(this));
  531. },
  532. closeDesc(e, s) {
  533. this.state.showDesc = e;
  534. if (s) {
  535. this.loadData();
  536. };
  537. },
  538. search() {
  539. this.loadData();
  540. },
  541. reset() {
  542. this.loadData();
  543. },
  544. render() {
  545. const rowSelection = {
  546. selectedRowKeys: this.state.selectedRowKeys,
  547. onChange: (selectedRowKeys, selectedRows) => {
  548. this.setState({
  549. selectedRows: selectedRows,
  550. selectedRowKeys: selectedRowKeys
  551. });
  552. }
  553. };
  554. const hasSelected = this.state.selectedRowKeys.length > 0;
  555. return (
  556. <div className="user-content" >
  557. <div className="content-title">
  558. <span>财务报表信息</span>
  559. </div>
  560. <div className="user-search">
  561. <p>
  562. <Button style={{ background: "#ea0862", border: "none", color: "#fff" }}
  563. disabled={this.state.ButtonDisabled}
  564. onClick={this.tableRowClick}>添加<Icon type="plus" /></Button>
  565. <Button style={{ background: "#3fcf9e", border: "none", color: "#fff" }}
  566. disabled={!hasSelected}
  567. onClick={this.delectRow}>删除<Icon type="minus" /></Button>
  568. </p>
  569. </div>
  570. <div className="patent-table">
  571. <Spin spinning={this.state.loading}>
  572. <Table columns={this.state.columns}
  573. dataSource={this.state.dataSource}
  574. pagination={this.state.pagination}
  575. rowSelection={rowSelection}
  576. onRowClick={this.tableRowClick} />
  577. </Spin>
  578. </div>
  579. <FinanceDesc
  580. data={this.state.RowData}
  581. showDesc={this.state.showDesc} closeDesc={this.closeDesc} />
  582. </div >
  583. );
  584. }
  585. });
  586. export default Finance;