finance.jsx 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  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. <Spin spinning={this.state.loading} className='spin-box'>
  367. <Modal title="财务报表信息" visible={this.state.visible}
  368. onOk={this.handleOk} onCancel={this.handleCancel}
  369. width='800px'
  370. footer=''
  371. >
  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. </Modal>
  378. </Spin>
  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. onRowClick={this.tableRowClick} />
  596. </Spin>
  597. </div>
  598. <FinanceDesc
  599. uid={this.props.data.uid}
  600. data={this.state.RowData}
  601. showDesc={this.state.showDesc} closeDesc={this.closeDesc} />
  602. </div >
  603. );
  604. }
  605. });
  606. export default Finance;