finance.jsx 21 KB

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