finance.jsx 25 KB

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