finance.jsx 24 KB

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