finance.jsx 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  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. this.state.financeUrl = 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. fileList={this.state.fileList}
  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. this.setState({ fileList: info.fileList.slice(-1) });
  311. }}
  312. >
  313. <Button><Icon type="upload" /> 上传财务报表 </Button>
  314. </Upload>
  315. <p style={{ marginTop: '10px' }}>{theData.financeUrl ?
  316. <span className="download-file">
  317. <a onClick={newDownloadFile.bind(null, this.props.data.id, 'finance', '/api/admin/downloadFinance')}>{theData.financeDownloadFileName}</a>
  318. <a onClick={() => {
  319. var newTab = window.open('about:blank'); getPreview(theData.id, 'finance', 'finance', function (data) { newTab.location.href = data; });
  320. }}><Icon style={{ fontSize: '16px' }} type="eye-o" /></a>
  321. </span>
  322. : <span><Icon type="exclamation-circle" style={{ color: '#ffbf00', marginRight: '6px' }} />未上传!</span>}</p>
  323. </div>
  324. <FormItem style={{ marginTop: '20px' }}>
  325. <Button className="set-submit" type="primary" htmlType="submit">保存</Button>
  326. <Button type="ghost" style={{ marginLeft: '20px' }} onClick={this.props.closeModal}>取消</Button>
  327. </FormItem>
  328. </Form >
  329. );
  330. },
  331. }));
  332. const FinanceDesc = React.createClass({
  333. getInitialState() {
  334. return {
  335. visible: false,
  336. loading: false
  337. };
  338. },
  339. componentWillReceiveProps(nextProps) {
  340. this.state.visible = nextProps.showDesc
  341. },
  342. showModal() {
  343. this.setState({
  344. visible: true,
  345. });
  346. },
  347. handleOk() {
  348. this.setState({
  349. visible: false,
  350. });
  351. this.props.closeDesc(false, true);
  352. },
  353. handleCancel(e) {
  354. this.setState({
  355. visible: false,
  356. });
  357. this.props.closeDesc(false);
  358. },
  359. spinChange(e) {
  360. this.setState({
  361. loading: e
  362. });
  363. },
  364. render() {
  365. return (
  366. <div className="patent-addNew">
  367. <Modal maskClosable={false} title="财务报表信息" visible={this.state.visible}
  368. onOk={this.handleOk} onCancel={this.handleCancel}
  369. width='800px'
  370. footer='' >
  371. <Spin spinning={this.state.loading} className='spin-box'>
  372. <FinanceDescFrom
  373. uid={this.props.uid}
  374. data={this.props.data}
  375. visible={this.state.visible}
  376. spinState={this.spinChange} closeModal={this.handleCancel} clickOk={this.handleOk} />
  377. </Spin>
  378. </Modal>
  379. </div>
  380. );
  381. },
  382. });
  383. const Finance = React.createClass({
  384. loadData(pageNo) {
  385. this.state.data = [];
  386. this.setState({
  387. loading: true
  388. });
  389. $.ajax({
  390. method: "post",
  391. dataType: "json",
  392. crossDomain: false,
  393. url: globalConfig.context + "/api/admin/finance",
  394. data: {
  395. pageNo: pageNo || 1,
  396. pageSize: this.state.pagination.pageSize,
  397. uid: this.props.data.uid
  398. }
  399. }).done((data) => {
  400. if (data.error.length || !data.data || !data.data.list) {
  401. message.warning(data.error[0].message);
  402. return;
  403. };
  404. this.state.data = [];
  405. for (let i = 0; i < data.data.list.length; i++) {
  406. let thisdata = data.data.list[i];
  407. this.state.data.push({
  408. key: i,
  409. id: thisdata.id,
  410. uid: thisdata.uid,
  411. mainBusinessIncome: thisdata.mainBusinessIncome,
  412. managementCost: thisdata.managementCost,
  413. researchCost: thisdata.researchCost,
  414. operatingProfit: thisdata.operatingProfit,
  415. variousTax: thisdata.variousTax,
  416. currentAsset: thisdata.currentAsset,
  417. netFixedAsset: thisdata.netFixedAsset,
  418. totalAsset: thisdata.totalAsset,
  419. netAsset: thisdata.netAsset,
  420. grossProfit: thisdata.grossProfit,
  421. netProfit: thisdata.netProfit,
  422. salesRevenue: thisdata.salesRevenue,
  423. year: thisdata.year,
  424. financeUrl: thisdata.financeUrl,
  425. financeDownloadFileName: thisdata.financeDownloadFileName,
  426. finance: [thisdata.id, thisdata.financeDownloadFileName]
  427. });
  428. };
  429. this.state.pagination.current = data.data.pageNo;
  430. this.state.pagination.total = data.data.totalCount;
  431. this.setState({
  432. dataSource: this.state.data,
  433. pagination: this.state.pagination
  434. });
  435. }).always(function () {
  436. this.setState({
  437. loading: false
  438. });
  439. }.bind(this));
  440. let _me = this;
  441. getProportion(this.props.data.uid, function (data) { _me.setState({ proportion: data }); });
  442. },
  443. getInitialState() {
  444. return {
  445. selectedRowKeys: [],
  446. selectedRows: [],
  447. loading: false,
  448. pagination: {
  449. defaultCurrent: 1,
  450. defaultPageSize: 10,
  451. showQuickJumper: true,
  452. pageSize: 10,
  453. onChange: function (page) {
  454. this.loadData(page);
  455. }.bind(this),
  456. showTotal: function (total) {
  457. return '共' + total + '条数据';
  458. }
  459. },
  460. columns: [
  461. {
  462. title: '年份',
  463. dataIndex: 'year',
  464. key: 'year'
  465. }, {
  466. title: '主营业务收入(万元)',
  467. dataIndex: 'mainBusinessIncome',
  468. key: 'mainBusinessIncome'
  469. }, {
  470. title: '管理费用(万元)',
  471. dataIndex: 'managementCost',
  472. key: 'managementCost'
  473. }, {
  474. title: '营业利润(万元)',
  475. dataIndex: 'operatingProfit',
  476. key: 'operatingProfit',
  477. }, {
  478. title: '支付的各项税费(万元)',
  479. dataIndex: 'variousTax',
  480. key: 'variousTax',
  481. }, {
  482. title: '资产总额(万元)',
  483. dataIndex: 'totalAsset',
  484. key: 'totalAsset',
  485. }, {
  486. title: '所有者权益(净资产)(万元)',
  487. dataIndex: 'netAsset',
  488. key: 'netAsset',
  489. }, {
  490. title: '相关附件',
  491. dataIndex: 'finance',
  492. key: 'finance',
  493. render: (text) => {
  494. return <a onClick={newDownloadFile.bind(null, text[0], 'finance', '/api/admin/downloadFinance')}>{text[1]}</a>
  495. }
  496. }
  497. ],
  498. dataSource: []
  499. };
  500. },
  501. componentWillMount() {
  502. this.loadData();
  503. },
  504. tableRowClick(record, index) {
  505. this.state.RowData = record;
  506. this.setState({
  507. showDesc: true
  508. });
  509. },
  510. delectRow() {
  511. let deletedIds = [];
  512. for (let idx = 0; idx < this.state.selectedRows.length; idx++) {
  513. let rowItem = this.state.selectedRows[idx];
  514. if (rowItem.id) {
  515. deletedIds.push(rowItem.id)
  516. }
  517. }
  518. this.setState({
  519. selectedRowKeys: [],
  520. loading: deletedIds.length > 0
  521. });
  522. $.ajax({
  523. method: "POST",
  524. dataType: "json",
  525. crossDomain: false,
  526. url: globalConfig.context + "/api/admin/deleteFinance",
  527. data: {
  528. ids: deletedIds
  529. }
  530. }).done(function (data) {
  531. if (!data.error.length) {
  532. message.success('删除成功!');
  533. this.setState({
  534. loading: false,
  535. });
  536. } else {
  537. message.warning(data.error[0].message);
  538. };
  539. this.loadData();
  540. }.bind(this));
  541. },
  542. closeDesc(e, s) {
  543. this.state.showDesc = e;
  544. if (s) {
  545. this.loadData();
  546. };
  547. },
  548. search() {
  549. this.loadData();
  550. },
  551. reset() {
  552. this.loadData();
  553. },
  554. render() {
  555. const rowSelection = {
  556. selectedRowKeys: this.state.selectedRowKeys,
  557. onChange: (selectedRowKeys, selectedRows) => {
  558. this.setState({
  559. selectedRows: selectedRows,
  560. selectedRowKeys: selectedRowKeys
  561. });
  562. }
  563. };
  564. const hasSelected = this.state.selectedRowKeys.length > 0;
  565. return (
  566. <div className="user-content" >
  567. <div className="content-title">
  568. <span>财务报表信息</span>
  569. <span className="proportion"> 是否已完成:</span>
  570. <Switch
  571. checked={this.state.proportion && this.state.proportion.finance == 1 ? true : false}
  572. checkedChildren={'已完成'}
  573. unCheckedChildren={'未完成'}
  574. onChange={(e) => {
  575. e ? this.state.proportion.finance = 1 : this.state.proportion.finance = 0;
  576. saveProportion(this.state.proportion.id, this.props.data.uid, 'finance', this.state.proportion.finance);
  577. this.setState({ proportion: this.state.proportion });
  578. }} />
  579. </div>
  580. <div className="user-search">
  581. <p>
  582. <Button style={{ background: "#ea0862", border: "none", color: "#fff" }}
  583. onClick={this.tableRowClick}>添加<Icon type="plus" /></Button>
  584. <Button style={{ background: "#3fcf9e", border: "none", color: "#fff" }}
  585. disabled={!hasSelected}
  586. onClick={this.delectRow}>删除<Icon type="minus" /></Button>
  587. </p>
  588. </div>
  589. <div className="patent-table">
  590. <Spin spinning={this.state.loading}>
  591. <Table columns={this.state.columns}
  592. dataSource={this.state.dataSource}
  593. pagination={this.state.pagination}
  594. rowSelection={rowSelection}
  595. style={{
  596. cursor: 'pointer',
  597. }}
  598. onRowClick={this.tableRowClick} />
  599. </Spin>
  600. </div>
  601. <FinanceDesc
  602. uid={this.props.data.uid}
  603. data={this.state.RowData}
  604. showDesc={this.state.showDesc} closeDesc={this.closeDesc} />
  605. </div >
  606. );
  607. }
  608. });
  609. export default Finance;