finance.jsx 25 KB

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