finance.jsx 20 KB

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