finance.jsx 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503
  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.closeModal();
  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. message.success(`${info.file.name} 文件上传成功!`);
  224. this.state.financeUrl = info.file.response.data;
  225. } else if (info.file.status === 'error') {
  226. message.error(`${info.file.name} 文件上传失败。`);
  227. }
  228. }}
  229. >
  230. <Button><Icon type="upload" /> 上传文件 </Button>
  231. </Upload>
  232. </div>
  233. <FormItem style={{ marginTop: '20px' }}>
  234. <Button className="set-submit" type="primary" htmlType="submit">保存</Button>
  235. <Button type="ghost" style={{ marginLeft: '20px' }} onClick={this.props.closeModal}>取消</Button>
  236. </FormItem>
  237. </Form >
  238. );
  239. },
  240. }));
  241. const FinanceDesc = React.createClass({
  242. getInitialState() {
  243. return {
  244. visible: false,
  245. loading: false
  246. };
  247. },
  248. componentWillReceiveProps(nextProps) {
  249. this.state.visible = nextProps.showDesc
  250. },
  251. showModal() {
  252. this.setState({
  253. visible: true,
  254. });
  255. },
  256. handleOk() {
  257. this.setState({
  258. visible: false,
  259. });
  260. this.props.closeDesc(false);
  261. },
  262. handleCancel(e) {
  263. this.setState({
  264. visible: false,
  265. });
  266. this.props.closeDesc(false);
  267. },
  268. spinChange(e) {
  269. this.setState({
  270. loading: e
  271. });
  272. },
  273. render() {
  274. return (
  275. <div className="patent-addNew">
  276. <Spin spinning={this.state.loading} className='spin-box'>
  277. <Modal title="财务报表信息" visible={this.state.visible}
  278. onOk={this.handleOk} onCancel={this.handleCancel}
  279. width='800px'
  280. footer=''
  281. >
  282. <FinanceDescFrom
  283. uid={this.props.uid}
  284. data={this.props.data}
  285. spinState={this.spinChange} closeModal={this.handleCancel} />
  286. </Modal>
  287. </Spin>
  288. </div>
  289. );
  290. },
  291. });
  292. const Finance = React.createClass({
  293. loadData(pageNo) {
  294. this.state.data = [];
  295. this.setState({
  296. loading: true
  297. });
  298. $.ajax({
  299. method: "post",
  300. dataType: "json",
  301. crossDomain: false,
  302. url: globalConfig.context + "/api/admin/finance",
  303. data: {
  304. pageNo: pageNo || 1,
  305. pageSize: this.state.pagination.pageSize,
  306. uid: this.props.data.uid
  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) {
  448. this.state.showDesc = e;
  449. this.loadData();
  450. },
  451. search() {
  452. this.loadData();
  453. },
  454. reset() {
  455. this.loadData();
  456. },
  457. render() {
  458. const rowSelection = {
  459. selectedRowKeys: this.state.selectedRowKeys,
  460. onChange: (selectedRowKeys, selectedRows) => {
  461. this.setState({
  462. selectedRows: selectedRows,
  463. selectedRowKeys: selectedRowKeys
  464. });
  465. }
  466. };
  467. const hasSelected = this.state.selectedRowKeys.length > 0;
  468. return (
  469. <div className="user-content" >
  470. <div className="content-title">
  471. <span>财务报表信息</span>
  472. </div>
  473. <div className="user-search">
  474. <p>
  475. <Button style={{ background: "#ea0862", border: "none", color: "#fff" }}
  476. onClick={this.tableRowClick}>添加<Icon type="plus" /></Button>
  477. <Button style={{ background: "#3fcf9e", border: "none", color: "#fff" }}
  478. disabled={!hasSelected}
  479. onClick={this.delectRow}>删除<Icon type="minus" /></Button>
  480. </p>
  481. </div>
  482. <div className="patent-table">
  483. <Spin spinning={this.state.loading}>
  484. <Table columns={this.state.columns}
  485. dataSource={this.state.dataSource}
  486. pagination={this.state.pagination}
  487. rowSelection={rowSelection}
  488. onRowClick={this.tableRowClick} />
  489. </Spin>
  490. </div>
  491. <FinanceDesc
  492. uid={this.props.data.uid}
  493. data={this.state.RowData}
  494. showDesc={this.state.showDesc} closeDesc={this.closeDesc} />
  495. </div >
  496. );
  497. }
  498. });
  499. export default Finance;