finance.jsx 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  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.closeModal();
  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. message.success(`${info.file.name} 文件上传成功!`);
  221. this.state.financeUrl = info.file.response.data;
  222. } else if (info.file.status === 'error') {
  223. message.error(`${info.file.name} 文件上传失败。`);
  224. }
  225. }}
  226. >
  227. <Button><Icon type="upload" /> 上传文件 </Button>
  228. </Upload>
  229. </div>
  230. <FormItem style={{ marginTop: '20px' }}>
  231. <Button className="set-submit" type="primary" htmlType="submit">保存</Button>
  232. <Button type="ghost" style={{ marginLeft: '20px' }} onClick={this.props.closeModal}>取消</Button>
  233. </FormItem>
  234. </Form >
  235. );
  236. },
  237. }));
  238. const FinanceDesc = React.createClass({
  239. getInitialState() {
  240. return {
  241. visible: false,
  242. loading: false
  243. };
  244. },
  245. componentWillReceiveProps(nextProps) {
  246. this.state.visible = nextProps.showDesc
  247. },
  248. showModal() {
  249. this.setState({
  250. visible: true,
  251. });
  252. },
  253. handleOk() {
  254. this.setState({
  255. visible: false,
  256. });
  257. this.props.closeDesc(false);
  258. },
  259. handleCancel(e) {
  260. this.setState({
  261. visible: false,
  262. });
  263. this.props.closeDesc(false);
  264. },
  265. spinChange(e) {
  266. this.setState({
  267. loading: e
  268. });
  269. },
  270. render() {
  271. return (
  272. <div className="patent-addNew">
  273. <Spin spinning={this.state.loading} className='spin-box'>
  274. <Modal title="财务报表信息" visible={this.state.visible}
  275. onOk={this.handleOk} onCancel={this.handleCancel}
  276. width='800px'
  277. footer=''
  278. >
  279. <FinanceDescFrom
  280. data={this.props.data}
  281. spinState={this.spinChange} closeModal={this.handleCancel} />
  282. </Modal>
  283. </Spin>
  284. </div>
  285. );
  286. },
  287. });
  288. const Finance = React.createClass({
  289. loadData(pageNo) {
  290. this.state.data = [];
  291. this.setState({
  292. loading: true
  293. });
  294. $.ajax({
  295. method: "get",
  296. dataType: "json",
  297. crossDomain: false,
  298. url: globalConfig.context + "/techservice/cognizance/finance",
  299. data: {
  300. pageNo: pageNo || 1,
  301. pageSize: this.state.pagination.pageSize,
  302. }
  303. }).done((data) => {
  304. if (data.error.length || !data.data || !data.data.list) {
  305. message.warning(data.error[0].message);
  306. return;
  307. };
  308. for (let i = 0; i < data.data.list.length; i++) {
  309. let thisdata = data.data.list[i];
  310. this.state.data.push({
  311. key: i,
  312. id: thisdata.id,
  313. uid: thisdata.uid,
  314. mainBusinessIncome: thisdata.mainBusinessIncome,
  315. managementCost: thisdata.managementCost,
  316. operatingProfit: thisdata.operatingProfit,
  317. variousTax: thisdata.variousTax,
  318. currentAsset: thisdata.currentAsset,
  319. netFixedAsset: thisdata.netFixedAsset,
  320. totalAsset: thisdata.totalAsset,
  321. netAsset: thisdata.netAsset,
  322. grossProfit: thisdata.grossProfit,
  323. netProfit: thisdata.netProfit,
  324. salesRevenue: thisdata.salesRevenue,
  325. year: thisdata.year,
  326. financeUrl: thisdata.financeUrl
  327. });
  328. };
  329. this.state.pagination.current = data.data.pageNo;
  330. this.state.pagination.total = data.data.totalCount;
  331. this.setState({
  332. dataSource: this.state.data,
  333. pagination: this.state.pagination
  334. });
  335. }).always(function () {
  336. this.setState({
  337. loading: false
  338. });
  339. }.bind(this));
  340. },
  341. getInitialState() {
  342. return {
  343. selectedRowKeys: [],
  344. selectedRows: [],
  345. loading: false,
  346. pagination: {
  347. defaultCurrent: 1,
  348. defaultPageSize: 10,
  349. showQuickJumper: true,
  350. pageSize: 10,
  351. onChange: function (page) {
  352. this.loadData(page);
  353. }.bind(this),
  354. showTotal: function (total) {
  355. return '共' + total + '条数据';
  356. }
  357. },
  358. columns: [
  359. {
  360. title: '年份',
  361. dataIndex: 'year',
  362. key: 'year'
  363. }, {
  364. title: '主营业务收入(万元)',
  365. dataIndex: 'mainBusinessIncome',
  366. key: 'mainBusinessIncome'
  367. }, {
  368. title: '管理费用(万元)',
  369. dataIndex: 'managementCost',
  370. key: 'managementCost'
  371. }, {
  372. title: '营业利润(万元)',
  373. dataIndex: 'operatingProfit',
  374. key: 'operatingProfit',
  375. }, {
  376. title: '支付的各项税费(万元)',
  377. dataIndex: 'variousTax',
  378. key: 'variousTax',
  379. }, {
  380. title: '资产总额(万元)',
  381. dataIndex: 'totalAsset',
  382. key: 'totalAsset',
  383. }, {
  384. title: '所有者权益(净资产)(万元)',
  385. dataIndex: 'netAsset',
  386. key: 'netAsset',
  387. }, {
  388. title: '相关附件',
  389. dataIndex: 'financeUrl',
  390. key: 'financeUrl',
  391. render: (text) => {
  392. <a href="" onClick={() => {
  393. window.open(globalConfig.context + "/techservice/patent/downloadFile?path=" + text + "&sign=" + "type")
  394. }}></a>
  395. }
  396. }
  397. ],
  398. dataSource: []
  399. };
  400. },
  401. componentWillMount() {
  402. this.loadData();
  403. },
  404. tableRowClick(record, index) {
  405. this.state.RowData = record;
  406. this.setState({
  407. showDesc: true
  408. });
  409. },
  410. delectRow() {
  411. let deletedIds = [];
  412. for (let idx = 0; idx < this.state.selectedRows.length; idx++) {
  413. let rowItem = this.state.selectedRows[idx];
  414. if (rowItem.id) {
  415. deletedIds.push(rowItem.id)
  416. }
  417. }
  418. this.setState({
  419. selectedRowKeys: [],
  420. loading: deletedIds.length > 0
  421. });
  422. $.ajax({
  423. method: "POST",
  424. dataType: "json",
  425. crossDomain: false,
  426. url: globalConfig.context + "/techservice/cognizance/deleteFinance",
  427. data: {
  428. ids: deletedIds
  429. }
  430. }).done(function (data) {
  431. if (!data.error.length) {
  432. message.success('保存成功!');
  433. this.setState({
  434. loading: false,
  435. });
  436. } else {
  437. message.warning(data.error[0].message);
  438. };
  439. this.loadData();
  440. }.bind(this));
  441. },
  442. closeDesc(e) {
  443. this.state.showDesc = e;
  444. this.loadData();
  445. },
  446. search() {
  447. this.loadData();
  448. },
  449. reset() {
  450. this.loadData();
  451. },
  452. render() {
  453. const rowSelection = {
  454. selectedRowKeys: this.state.selectedRowKeys,
  455. onChange: (selectedRowKeys, selectedRows) => {
  456. this.setState({
  457. selectedRows: selectedRows,
  458. selectedRowKeys: selectedRowKeys
  459. });
  460. }
  461. };
  462. const hasSelected = this.state.selectedRowKeys.length > 0;
  463. return (
  464. <div className="user-content" >
  465. <div className="content-title">
  466. <span>财务报表信息</span>
  467. </div>
  468. <div className="user-search">
  469. <p>
  470. <Button style={{ background: "#ea0862", border: "none", color: "#fff" }}
  471. onClick={this.tableRowClick}>添加<Icon type="plus" /></Button>
  472. <Button style={{ background: "#3fcf9e", border: "none", color: "#fff" }}
  473. disabled={!hasSelected}
  474. onClick={this.delectRow}>删除<Icon type="minus" /></Button>
  475. </p>
  476. </div>
  477. <div className="patent-table">
  478. <Spin spinning={this.state.loading}>
  479. <Table columns={this.state.columns}
  480. dataSource={this.state.dataSource}
  481. pagination={this.state.pagination}
  482. rowSelection={rowSelection}
  483. onRowClick={this.tableRowClick} />
  484. </Spin>
  485. </div>
  486. <FinanceDesc
  487. data={this.state.RowData}
  488. showDesc={this.state.showDesc} closeDesc={this.closeDesc} />
  489. </div >
  490. );
  491. }
  492. });
  493. export default Finance;