finance.jsx 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519
  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. this.state.data = [];
  327. for (let i = 0; i < data.data.list.length; i++) {
  328. let thisdata = data.data.list[i];
  329. this.state.data.push({
  330. key: i,
  331. id: thisdata.id,
  332. uid: thisdata.uid,
  333. mainBusinessIncome: thisdata.mainBusinessIncome,
  334. managementCost: thisdata.managementCost,
  335. operatingProfit: thisdata.operatingProfit,
  336. variousTax: thisdata.variousTax,
  337. currentAsset: thisdata.currentAsset,
  338. netFixedAsset: thisdata.netFixedAsset,
  339. totalAsset: thisdata.totalAsset,
  340. netAsset: thisdata.netAsset,
  341. grossProfit: thisdata.grossProfit,
  342. netProfit: thisdata.netProfit,
  343. salesRevenue: thisdata.salesRevenue,
  344. year: thisdata.year,
  345. financeUrl: thisdata.financeUrl,
  346. financeDownloadFileName: thisdata.financeDownloadFileName,
  347. finance: [thisdata.id, thisdata.financeDownloadFileName]
  348. });
  349. };
  350. this.state.pagination.current = data.data.pageNo;
  351. this.state.pagination.total = data.data.totalCount;
  352. this.setState({
  353. dataSource: this.state.data,
  354. pagination: this.state.pagination
  355. });
  356. }).always(function () {
  357. this.setState({
  358. loading: false
  359. });
  360. }.bind(this));
  361. },
  362. getInitialState() {
  363. return {
  364. selectedRowKeys: [],
  365. selectedRows: [],
  366. loading: false,
  367. pagination: {
  368. defaultCurrent: 1,
  369. defaultPageSize: 10,
  370. showQuickJumper: true,
  371. pageSize: 10,
  372. onChange: function (page) {
  373. this.loadData(page);
  374. }.bind(this),
  375. showTotal: function (total) {
  376. return '共' + total + '条数据';
  377. }
  378. },
  379. columns: [
  380. {
  381. title: '年份',
  382. dataIndex: 'year',
  383. key: 'year'
  384. }, {
  385. title: '主营业务收入(万元)',
  386. dataIndex: 'mainBusinessIncome',
  387. key: 'mainBusinessIncome'
  388. }, {
  389. title: '管理费用(万元)',
  390. dataIndex: 'managementCost',
  391. key: 'managementCost'
  392. }, {
  393. title: '营业利润(万元)',
  394. dataIndex: 'operatingProfit',
  395. key: 'operatingProfit',
  396. }, {
  397. title: '支付的各项税费(万元)',
  398. dataIndex: 'variousTax',
  399. key: 'variousTax',
  400. }, {
  401. title: '资产总额(万元)',
  402. dataIndex: 'totalAsset',
  403. key: 'totalAsset',
  404. }, {
  405. title: '所有者权益(净资产)(万元)',
  406. dataIndex: 'netAsset',
  407. key: 'netAsset',
  408. }, {
  409. title: '相关附件',
  410. dataIndex: 'finance',
  411. key: 'finance',
  412. render: (text) => {
  413. return <a onClick={newDownloadFile.bind(null, text[0], 'finance', '/api/admin/downloadFinance')}>{text[1]}</a>
  414. }
  415. }
  416. ],
  417. dataSource: []
  418. };
  419. },
  420. componentWillMount() {
  421. this.loadData();
  422. },
  423. tableRowClick(record, index) {
  424. this.state.RowData = record;
  425. this.setState({
  426. showDesc: true
  427. });
  428. },
  429. delectRow() {
  430. let deletedIds = [];
  431. for (let idx = 0; idx < this.state.selectedRows.length; idx++) {
  432. let rowItem = this.state.selectedRows[idx];
  433. if (rowItem.id) {
  434. deletedIds.push(rowItem.id)
  435. }
  436. }
  437. this.setState({
  438. selectedRowKeys: [],
  439. loading: deletedIds.length > 0
  440. });
  441. $.ajax({
  442. method: "POST",
  443. dataType: "json",
  444. crossDomain: false,
  445. url: globalConfig.context + "/api/admin/deleteFinance",
  446. data: {
  447. ids: deletedIds
  448. }
  449. }).done(function (data) {
  450. if (!data.error.length) {
  451. message.success('保存成功!');
  452. this.setState({
  453. loading: false,
  454. });
  455. } else {
  456. message.warning(data.error[0].message);
  457. };
  458. this.loadData();
  459. }.bind(this));
  460. },
  461. closeDesc(e, s) {
  462. this.state.showDesc = e;
  463. if (s) {
  464. this.loadData();
  465. };
  466. },
  467. search() {
  468. this.loadData();
  469. },
  470. reset() {
  471. this.loadData();
  472. },
  473. render() {
  474. const rowSelection = {
  475. selectedRowKeys: this.state.selectedRowKeys,
  476. onChange: (selectedRowKeys, selectedRows) => {
  477. this.setState({
  478. selectedRows: selectedRows,
  479. selectedRowKeys: selectedRowKeys
  480. });
  481. }
  482. };
  483. const hasSelected = this.state.selectedRowKeys.length > 0;
  484. return (
  485. <div className="user-content" >
  486. <div className="content-title">
  487. <span>财务报表信息</span>
  488. </div>
  489. <div className="user-search">
  490. <p>
  491. <Button style={{ background: "#ea0862", border: "none", color: "#fff" }}
  492. onClick={this.tableRowClick}>添加<Icon type="plus" /></Button>
  493. <Button style={{ background: "#3fcf9e", border: "none", color: "#fff" }}
  494. disabled={!hasSelected}
  495. onClick={this.delectRow}>删除<Icon type="minus" /></Button>
  496. </p>
  497. </div>
  498. <div className="patent-table">
  499. <Spin spinning={this.state.loading}>
  500. <Table columns={this.state.columns}
  501. dataSource={this.state.dataSource}
  502. pagination={this.state.pagination}
  503. rowSelection={rowSelection}
  504. onRowClick={this.tableRowClick} />
  505. </Spin>
  506. </div>
  507. <FinanceDesc
  508. uid={this.props.data.uid}
  509. data={this.state.RowData}
  510. showDesc={this.state.showDesc} closeDesc={this.closeDesc} />
  511. </div >
  512. );
  513. }
  514. });
  515. export default Finance;