finance.jsx 20 KB

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