finance.jsx 21 KB

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