finance.jsx 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  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. this.state.financeUrl = undefined;
  116. };
  117. },
  118. checkResearchCost(rule, value, callback) {
  119. const form = this.props.form;
  120. if (value > form.getFieldValue('managementCost')) {
  121. callback('管理费用小于研发费用!');
  122. } else {
  123. callback();
  124. }
  125. },
  126. render() {
  127. const FormItem = Form.Item;
  128. const { getFieldDecorator } = this.props.form;
  129. const theData = this.props.data;
  130. const formItemLayout = {
  131. labelCol: { span: 8 },
  132. wrapperCol: { span: 16 },
  133. };
  134. const _me = this;
  135. return (
  136. <Form onSubmit={this.handleSubmit} className="activityCost-form">
  137. <div className="activityCost-title"><span>年份: </span>
  138. {
  139. theData.year ? <span>{theData.year}</span> :
  140. <Select placeholder="请选择年份" style={{ width: 200 }}
  141. onSelect={(e, n) => { this.state.year = e, this.loadData(e); }}>
  142. {this.state.yearOption}
  143. </Select>
  144. }
  145. </div>
  146. <div className="clearfix">
  147. <FormItem className="half-item"
  148. {...formItemLayout}
  149. label="主营业务收入(万元)"
  150. >
  151. {getFieldDecorator('mainBusinessIncome', {
  152. rules: [{ type: 'number', required: true, message: '此项为必填项!' }],
  153. initialValue: theData.mainBusinessIncome
  154. })(
  155. <InputNumber min={0} max={999999} step={0.01} />
  156. )}
  157. </FormItem>
  158. <FormItem className="half-item"
  159. {...formItemLayout}
  160. label="管理费用(万元)"
  161. >
  162. {getFieldDecorator('managementCost', {
  163. rules: [{ type: 'number', required: true, message: '此项为必填项!' }],
  164. initialValue: theData.managementCost
  165. })(
  166. <InputNumber min={0} max={999999} step={0.01} />
  167. )}
  168. {this.state.managementCost && this.state.managementCost != this.props.form.getFieldValue('managementCost') ? <span style={{ color: '#f50' }}>与财务报表不一致!</span> : <span></span>}
  169. </FormItem>
  170. <FormItem className="half-item"
  171. {...formItemLayout}
  172. label="研发费用(万元)"
  173. >
  174. {getFieldDecorator('researchCost', {
  175. rules: [
  176. { type: 'number', required: true, message: '此项为必填项!' }, {
  177. validator: this.checkResearchCost,
  178. }],
  179. initialValue: theData.researchCost
  180. })(
  181. <InputNumber min={0} max={999999} step={0.01} />
  182. )}
  183. {this.state.researchCost && this.state.researchCost != this.props.form.getFieldValue('researchCost') ? <span style={{ color: '#f50' }}>与财务报表不一致!</span> : <span></span>}
  184. </FormItem>
  185. <FormItem className="half-item"
  186. {...formItemLayout}
  187. label="营业利润(万元)"
  188. >
  189. {getFieldDecorator('operatingProfit', {
  190. rules: [{ type: 'number', required: true, message: '此项为必填项!' }],
  191. initialValue: theData.operatingProfit
  192. })(
  193. <InputNumber min={0} max={999999} step={0.01} />
  194. )}
  195. {this.state.operatingProfit && this.state.operatingProfit != this.props.form.getFieldValue('operatingProfit') ? <span style={{ color: '#f50' }}>与财务报表不一致!</span> : <span></span>}
  196. </FormItem>
  197. <FormItem className="half-item"
  198. {...formItemLayout}
  199. label="支付的各项税费(万元)"
  200. >
  201. {getFieldDecorator('variousTax', {
  202. rules: [{ type: 'number', required: true, message: '此项为必填项!' }],
  203. initialValue: theData.variousTax
  204. })(
  205. <InputNumber min={0} max={999999} step={0.01} />
  206. )}
  207. </FormItem>
  208. <FormItem className="half-item"
  209. {...formItemLayout}
  210. label="流动资产(万元)"
  211. >
  212. {getFieldDecorator('currentAsset', {
  213. rules: [{ type: 'number', required: true, message: '此项为必填项!' }],
  214. initialValue: theData.currentAsset
  215. })(
  216. <InputNumber min={0} max={999999} step={0.01} />
  217. )}
  218. </FormItem>
  219. <FormItem className="half-item"
  220. {...formItemLayout}
  221. label="固定资产净额(万元)"
  222. >
  223. {getFieldDecorator('netFixedAsset', {
  224. rules: [{ type: 'number', required: true, message: '此项为必填项!' }],
  225. initialValue: theData.netFixedAsset
  226. })(
  227. <InputNumber min={0} max={999999} step={0.01} />
  228. )}
  229. </FormItem>
  230. <FormItem className="half-item"
  231. {...formItemLayout}
  232. label="资产总额(万元)"
  233. >
  234. {getFieldDecorator('totalAsset', {
  235. rules: [{ type: 'number', required: true, message: '此项为必填项!' }],
  236. initialValue: theData.totalAsset
  237. })(
  238. <InputNumber min={0} max={999999} step={0.01} />
  239. )}
  240. </FormItem>
  241. <FormItem className="half-item"
  242. {...formItemLayout}
  243. label="所有者权益合计(万元)"
  244. >
  245. {getFieldDecorator('netAsset', {
  246. rules: [{ type: 'number', required: true, message: '此项为必填项!' }],
  247. initialValue: theData.netAsset
  248. })(
  249. <InputNumber min={0} max={999999} step={0.01} />
  250. )}
  251. </FormItem>
  252. <FormItem className="half-item"
  253. {...formItemLayout}
  254. label="利润总额(万元)"
  255. >
  256. {getFieldDecorator('grossProfit', {
  257. rules: [{ type: 'number', required: true, message: '此项为必填项!' }],
  258. initialValue: theData.grossProfit
  259. })(
  260. <InputNumber min={0} max={999999} step={0.01} />
  261. )}
  262. {this.state.grossProfit && this.state.grossProfit != this.props.form.getFieldValue('grossProfit') ? <span style={{ color: '#f50' }}>与财务报表不一致!</span> : <span></span>}
  263. </FormItem>
  264. <FormItem className="half-item"
  265. {...formItemLayout}
  266. label="净利润(万元)"
  267. >
  268. {getFieldDecorator('netProfit', {
  269. rules: [{ type: 'number', required: true, message: '此项为必填项!' }],
  270. initialValue: theData.netProfit
  271. })(
  272. <InputNumber min={0} max={999999} step={0.01} />
  273. )}
  274. </FormItem>
  275. <FormItem className="half-item"
  276. {...formItemLayout}
  277. label="销售收入(万元)"
  278. >
  279. {getFieldDecorator('salesRevenue', {
  280. rules: [{ type: 'number', required: true, message: '此项为必填项!' }],
  281. initialValue: theData.salesRevenue
  282. })(
  283. <InputNumber min={0} max={999999} step={0.01} />
  284. )}
  285. </FormItem>
  286. </div>
  287. <div className="hrSituation-roster">
  288. <Upload
  289. name="ratepay"
  290. action={globalConfig.context + "/api/user/cognizance/uploadFinance"}
  291. data={{ 'sign': 'finance', year: this.state.year || theData.year }}
  292. beforeUpload={beforeUploadFile}
  293. fileList={this.state.fileList}
  294. onChange={(info) => {
  295. if (info.file.status !== 'uploading') {
  296. // console.log(info.file, info.fileList);
  297. }
  298. if (info.file.status === 'done') {
  299. if (!info.file.response.error.length) {
  300. message.success(`${info.file.name} 文件上传成功!`);
  301. } else {
  302. message.warning(info.file.response.error[0].message);
  303. return;
  304. };
  305. this.state.financeUrl = info.file.response.data;
  306. } else if (info.file.status === 'error') {
  307. message.error(`${info.file.name} 文件上传失败。`);
  308. };
  309. this.setState({ fileList: info.fileList.slice(-1) });
  310. }}
  311. >
  312. <Button><Icon type="upload" /> 上传企业财务报表 </Button>
  313. </Upload>
  314. <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>
  315. </div>
  316. <FormItem style={{ marginTop: '20px' }}>
  317. <Button className="set-submit" type="primary" htmlType="submit">保存</Button>
  318. <Button type="ghost" style={{ marginLeft: '20px' }} onClick={this.props.closeModal}>取消</Button>
  319. </FormItem>
  320. </Form >
  321. );
  322. },
  323. }));
  324. const FinanceDesc = React.createClass({
  325. getInitialState() {
  326. return {
  327. visible: false,
  328. loading: false
  329. };
  330. },
  331. componentWillReceiveProps(nextProps) {
  332. this.state.visible = nextProps.showDesc
  333. },
  334. showModal() {
  335. this.setState({
  336. visible: true,
  337. });
  338. },
  339. handleOk() {
  340. this.setState({
  341. visible: false,
  342. });
  343. this.props.closeDesc(false, true);
  344. },
  345. handleCancel(e) {
  346. this.setState({
  347. visible: false,
  348. });
  349. this.props.closeDesc(false);
  350. },
  351. spinChange(e) {
  352. this.setState({
  353. loading: e
  354. });
  355. },
  356. render() {
  357. return (
  358. <div className="patent-addNew">
  359. <Modal maskClosable={false} title="财务报表信息" visible={this.state.visible}
  360. onOk={this.handleOk} onCancel={this.handleCancel}
  361. width='800px'
  362. footer='' >
  363. <Spin spinning={this.state.loading} className='spin-box'>
  364. <FinanceDescFrom
  365. visible={this.state.visible}
  366. data={this.props.data}
  367. spinState={this.spinChange} closeModal={this.handleCancel} clickOk={this.handleOk} />
  368. </Spin>
  369. </Modal>
  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 size="middle" columns={this.state.columns}
  573. dataSource={this.state.dataSource}
  574. pagination={this.state.pagination}
  575. rowSelection={rowSelection}
  576. style={{
  577. cursor: 'pointer',
  578. }}
  579. onRowClick={this.tableRowClick} />
  580. </Spin>
  581. </div>
  582. <FinanceDesc
  583. data={this.state.RowData}
  584. showDesc={this.state.showDesc} closeDesc={this.closeDesc} />
  585. </div >
  586. );
  587. }
  588. });
  589. export default Finance;