activity.jsx 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  1. import React from 'react';
  2. import { Icon, Button, Upload, Input, Spin, Table, message, Select, Modal, DatePicker, Cascader, Transfer, InputNumber, Switch, Form } from 'antd';
  3. import { technicalSourceList } from '../../dataDic.js';
  4. import { techFieldList } from '../../DicTechFieldList.js';
  5. import { getTechField, getTechnicalSource, beforeUploadFile, newDownloadFile } from '../../tools.js';
  6. import './activity.less';
  7. import moment from 'moment';
  8. import ajax from 'jquery/src/ajax/xhr.js';
  9. import $ from 'jquery/src/ajax';
  10. const ActivityForm = Form.create()(React.createClass({
  11. getInitialState() {
  12. return {
  13. loading: false,
  14. targetKeys: [],
  15. selectedKeys: []
  16. };
  17. },
  18. loadData(id) {
  19. this.setState({ loading: true });
  20. $.ajax({
  21. method: "get",
  22. dataType: "json",
  23. crossDomain: false,
  24. url: globalConfig.context + "/api/user/cognizance/activityDetail",
  25. data: {
  26. id: id || this.props.data.id
  27. }
  28. }).done(function (data) {
  29. if (!data.data) {
  30. if (data.error && data.error.length) {
  31. message.warning(data.error[0].message);
  32. };
  33. } else {
  34. this.setState({
  35. data: data.data,
  36. targetKeys: data.data.intellectualPropertyNumber ? data.data.intellectualPropertyNumber.split(",") : [],
  37. techField: [Number(data.data.technicalField1), data.data.technicalField2 ? Number(data.data.technicalField2) : null, data.data.technicalField3 ? Number(data.data.technicalField3) : null]
  38. });
  39. };
  40. }.bind(this)).always(function (data) {
  41. this.setState({ loading: false });
  42. }.bind(this));
  43. },
  44. handleSubmit(e) {
  45. e.preventDefault();
  46. this.props.form.validateFields((err, values) => {
  47. if (!err) {
  48. this.setState({ loading: true });
  49. $.ajax({
  50. method: "POST",
  51. dataType: "json",
  52. crossDomain: false,
  53. url: globalConfig.context + "/api/user/cognizance/activity",
  54. data: {
  55. id: this.props.data.id,
  56. uid: this.props.uid,
  57. activityName: values.activityName,
  58. activityNumber: values.activityNumber,
  59. projectMode: values.projectMode,
  60. startDateFormattedDate: values.startDate ? values.startDate.format("YYYY-MM-DD") : null,
  61. endDateFormattedDate: values.endDate ? values.endDate.format("YYYY-MM-DD") : null,
  62. technicalField1: values.techField[0],
  63. technicalField2: values.techField[1],
  64. technicalField3: values.techField[2],
  65. technicalSource: values.technicalSource,
  66. intellectualPropertyNumber: this.state.targetKeys.join(","),
  67. budget: values.budget,
  68. implement: values.implement,
  69. technologyInnovation: values.technologyInnovation,
  70. achievement: values.achievement,
  71. proofUrl: this.state.proofUrl
  72. }
  73. }).done(function (data) {
  74. if (!data.error.length) {
  75. message.success('保存成功!');
  76. this.props.closeModal(true);
  77. } else {
  78. message.warning(data.error[0].message);
  79. };
  80. this.setState({ loading: false });
  81. }.bind(this));
  82. }
  83. });
  84. },
  85. componentWillMount() {
  86. if (this.props.data.id) {
  87. this.loadData();
  88. } else {
  89. this.state.data = {};
  90. this.state.targetKeys = [];
  91. this.state.techField = undefined;
  92. };
  93. },
  94. componentWillReceiveProps(nextProps) {
  95. if (!this.props.visible && nextProps.visible) {
  96. this.state.mockData = nextProps.data.mockData;
  97. this.props.form.resetFields();
  98. if (nextProps.data.id) {
  99. this.loadData(nextProps.data.id);
  100. } else {
  101. this.state.data = {};
  102. this.state.targetKeys = [];
  103. this.state.techField = undefined;
  104. };
  105. };
  106. },
  107. intellectualChange(nextTargetKeys, direction, moveKeys) {
  108. this.setState({ targetKeys: nextTargetKeys });
  109. },
  110. intellectualSelectChange(sourceSelectedKeys, targetSelectedKeys) {
  111. this.setState({ selectedKeys: [...sourceSelectedKeys, ...targetSelectedKeys] });
  112. },
  113. render() {
  114. const FormItem = Form.Item;
  115. const { getFieldDecorator } = this.props.form;
  116. const theData = this.state.data;
  117. const formItemLayout = {
  118. labelCol: { span: 6 },
  119. wrapperCol: { span: 12 },
  120. };
  121. if (theData) {
  122. return (
  123. <Spin spinning={this.state.loading} className='spin-box'>
  124. <Form onSubmit={this.handleSubmit} id="admin-desc-content">
  125. <div className="clearfix">
  126. <FormItem className="half-item"
  127. {...formItemLayout}
  128. label="研发活动编号"
  129. >
  130. {getFieldDecorator('activityNumber', {
  131. initialValue: theData.activityNumber
  132. })(
  133. <Input />
  134. )}
  135. </FormItem>
  136. <FormItem className="half-item"
  137. {...formItemLayout}
  138. label="研发活动名称"
  139. >
  140. {getFieldDecorator('activityName', {
  141. initialValue: theData.activityName
  142. })(
  143. <Input />
  144. )}
  145. </FormItem>
  146. <FormItem className="half-item"
  147. {...formItemLayout}
  148. label="开始日期"
  149. >
  150. {getFieldDecorator('startDate', {
  151. initialValue: theData.startDateFormattedDate ? moment(theData.startDateFormattedDate) : null
  152. })(
  153. <DatePicker />
  154. )}
  155. </FormItem>
  156. <FormItem className="half-item"
  157. {...formItemLayout}
  158. label="结束日期"
  159. >
  160. {getFieldDecorator('endDate', {
  161. initialValue: theData.endDateFormattedDate ? moment(theData.endDateFormattedDate) : null
  162. })(
  163. <DatePicker />
  164. )}
  165. </FormItem>
  166. </div>
  167. <div className="clearfix">
  168. <FormItem className="half-item"
  169. {...formItemLayout}
  170. label="技术领域"
  171. >
  172. {getFieldDecorator('techField', {
  173. initialValue: this.state.techField
  174. })(
  175. <Cascader
  176. style={{ width: 500 }}
  177. options={techFieldList}
  178. placeholder="选择技术领域"
  179. showSearch
  180. />
  181. )}
  182. </FormItem>
  183. </div>
  184. <div className="clearfix">
  185. <FormItem className="half-item"
  186. {...formItemLayout}
  187. label="技术来源"
  188. >
  189. {getFieldDecorator('technicalSource', {
  190. initialValue: theData.technicalSource ? String(theData.technicalSource) : undefined,
  191. })(
  192. <Select placeholder="选择技术来源" style={{ width: 230 }}>
  193. {
  194. technicalSourceList.map(function (item, i) {
  195. return <Select.Option key={1000 + i} value={item.value} >{item.key}</Select.Option>
  196. })
  197. }
  198. </Select>
  199. )}
  200. </FormItem>
  201. <FormItem className="half-item"
  202. {...formItemLayout}
  203. label="立项类型"
  204. >
  205. {getFieldDecorator('projectMode', {
  206. initialValue: theData.projectMode
  207. })(
  208. <Select style={{ width: 120 }}>
  209. <Select.Option value='0'>内部立项</Select.Option>
  210. <Select.Option value='1'>外部立项</Select.Option>
  211. </Select>
  212. )}
  213. </FormItem>
  214. </div>
  215. <div style={{ marginBottom: '20px' }}>
  216. <p>知识产权编号:</p>
  217. <Transfer
  218. dataSource={this.props.mockData}
  219. listStyle={{
  220. width: 300,
  221. height: 300,
  222. }}
  223. titles={['未选择', '已选择']}
  224. targetKeys={this.state.targetKeys}
  225. selectedKeys={this.state.selectedKeys}
  226. onChange={this.intellectualChange}
  227. onSelectChange={this.intellectualSelectChange}
  228. render={item => `${item.name}-${item.key}`}
  229. />
  230. </div>
  231. <FormItem className="half-div"
  232. labelCol={{ span: 8 }}
  233. wrapperCol={{ span: 12 }}
  234. label="研发经费总预算"
  235. >
  236. {getFieldDecorator('budget', {
  237. initialValue: theData.budget
  238. })(
  239. <InputNumber />
  240. )}
  241. <span>万元</span>
  242. </FormItem>
  243. <div className="clearfix" >
  244. <p>研发经费近三年总支出:</p>
  245. <FormItem className="half-item"
  246. labelCol={{ span: 8 }}
  247. wrapperCol={{ span: 12 }}
  248. label="总计"
  249. >
  250. <span>{
  251. (theData.firstYearExpenditure || 0) +
  252. (theData.secondYearExpenditure || 0) +
  253. (theData.thirdYearExpenditure || 0)
  254. }</span>
  255. <span>万元</span>
  256. </FormItem>
  257. <FormItem className="half-item"
  258. labelCol={{ span: 8 }}
  259. wrapperCol={{ span: 12 }}
  260. label="其中(前一年)"
  261. >
  262. <span>{theData.firstYearExpenditure}</span>
  263. <span>万元</span>
  264. </FormItem>
  265. <FormItem className="half-item"
  266. labelCol={{ span: 8 }}
  267. wrapperCol={{ span: 12 }}
  268. label="其中(前二年)"
  269. >
  270. <span>{theData.secondYearExpenditure}</span>
  271. <span>万元</span>
  272. </FormItem>
  273. <FormItem className="half-item"
  274. labelCol={{ span: 8 }}
  275. wrapperCol={{ span: 12 }}
  276. label="其中(前三年)"
  277. >
  278. <span>{theData.thirdYearExpenditure}</span>
  279. <span>万元</span>
  280. </FormItem>
  281. </div>
  282. <div className="clearfix">
  283. <div className="half-div">
  284. <p>目的及组织实施方式(限400字):</p>
  285. {getFieldDecorator('implement', {
  286. initialValue: theData.implement
  287. })(
  288. <Input type="textarea" rows={6} />
  289. )}
  290. </div>
  291. <div className="half-div">
  292. <p>核心技术及创新点(限400字):</p>
  293. {getFieldDecorator('technologyInnovation', {
  294. initialValue: theData.technologyInnovation
  295. })(
  296. <Input type="textarea" rows={6} />
  297. )}
  298. </div>
  299. <div className="half-div">
  300. <p>取得的阶段性成果(限400字):</p>
  301. {getFieldDecorator('achievement', {
  302. initialValue: theData.achievement
  303. })(
  304. <Input type="textarea" rows={6} />
  305. )}
  306. </div>
  307. </div>
  308. <div style={{ width: '50%' }}>
  309. <Upload
  310. name="ratepay"
  311. action={globalConfig.context + "/api/admin/uploadProof"}
  312. data={{ 'sign': 'proof', 'uid': this.props.uid }}
  313. beforeUpload={beforeUploadFile}
  314. showUploadList={false}
  315. onChange={(info) => {
  316. if (info.file.status !== 'uploading') {
  317. console.log(info.file, info.fileList);
  318. }
  319. if (info.file.status === 'done') {
  320. if (!info.file.response.error.length) {
  321. message.success(`${info.file.name} 文件上传成功!`);
  322. } else {
  323. message.warning(info.file.response.error[0].message);
  324. return;
  325. };
  326. this.state.proofUrl = info.file.response.data;
  327. } else if (info.file.status === 'error') {
  328. message.error(`${info.file.name} 文件上传失败。`);
  329. }
  330. }}
  331. >
  332. <Button><Icon type="upload" /> 上传立项证明材料 </Button>
  333. </Upload>
  334. <p>{theData.proofUrl ? <a onClick={newDownloadFile.bind(null, theData.id, 'proof', '/api/admin/downloadProof')}>{theData.proofDownloadFileName}</a> : <span><Icon type="exclamation-circle" style={{ color: '#ffbf00', marginRight: '6px' }} />未上传!</span>}</p>
  335. </div>
  336. <FormItem style={{ marginTop: '20px' }}>
  337. <Button className="set-submit" type="primary" htmlType="submit">保存</Button>
  338. <Button type="ghost" style={{ marginLeft: '20px' }} onClick={this.props.closeModal}>取消</Button>
  339. </FormItem>
  340. </Form >
  341. </Spin >
  342. )
  343. } else {
  344. return (<div></div>)
  345. };
  346. }
  347. }));
  348. const ActivityDesc = React.createClass({
  349. getInitialState() {
  350. return {
  351. visible: false,
  352. loading: false
  353. };
  354. },
  355. handleCancel(e) {
  356. this.setState({
  357. visible: false,
  358. });
  359. this.props.closeDesc(false);
  360. if (e) {
  361. this.props.closeDesc(false, true);
  362. };
  363. },
  364. componentWillReceiveProps(nextProps) {
  365. this.state.visible = nextProps.showDesc;
  366. },
  367. render() {
  368. return (
  369. <div className="admin-desc">
  370. <Modal title="企业研究开发活动情况详情"
  371. visible={this.state.visible}
  372. onCancel={this.handleCancel}
  373. width='800px'
  374. footer=''
  375. className="admin-desc-content">
  376. <ActivityForm
  377. visible={this.state.visible}
  378. data={this.props.data}
  379. uid={this.props.uid}
  380. mockData={this.props.mockData}
  381. spinState={this.spinChange}
  382. closeModal={this.handleCancel} />
  383. </Modal>
  384. </div>
  385. );
  386. },
  387. });
  388. const Activity = React.createClass({
  389. loadData(pageNo) {
  390. this.state.data = [];
  391. this.setState({
  392. loading: true
  393. });
  394. $.when($.ajax({
  395. method: "post",
  396. dataType: "json",
  397. crossDomain: false,
  398. url: globalConfig.context + "/api/user/cognizance/activityList",
  399. data: {
  400. pageNo: pageNo || 1,
  401. pageSize: this.state.pagination.pageSize,
  402. activityNumber: this.state.activityNumber,
  403. activityName: this.state.activityName
  404. }
  405. }), $.ajax({
  406. method: "get",
  407. dataType: "json",
  408. crossDomain: false,
  409. url: globalConfig.context + "/api/user/cognizance/intellectualList",
  410. data: {
  411. pageNo: pageNo || 1,
  412. pageSize: 99,
  413. }
  414. })).done((data1, data2) => {
  415. let data = data1[0];
  416. let intellectualList = data2[0];
  417. if (data.error.length || !data.data || !data.data.list) {
  418. message.warning(data.error[0].message);
  419. return;
  420. };
  421. if (intellectualList.error.length || !intellectualList.data || !intellectualList.data.list) {
  422. message.warning(intellectualList.error[0].message);
  423. return;
  424. };
  425. let theArr = [];
  426. for (let i = 0; i < intellectualList.data.list.length; i++) {
  427. theArr.push({
  428. key: intellectualList.data.list[i].intellectualPropertyNumber,
  429. name: intellectualList.data.list[i].intellectualPropertyName
  430. });
  431. };
  432. this.state.mockData = theArr;
  433. for (let i = 0; i < data.data.list.length; i++) {
  434. let thisdata = data.data.list[i];
  435. this.state.data.push({
  436. key: i,
  437. id: thisdata.id,
  438. uid: thisdata.uid,
  439. activityNumber: thisdata.activityNumber,
  440. activityName: thisdata.activityName,
  441. startDate: thisdata.startDate,
  442. endDate: thisdata.endDate,
  443. mockData: this.state.mockData,
  444. techField: [Number(thisdata.technicalField1), Number(thisdata.technicalField2), Number(thisdata.technicalField3)],
  445. technicalField: getTechField(thisdata.technicalField1, thisdata.technicalField2, thisdata.technicalField3),
  446. technicalField1: thisdata.technicalField1,
  447. technicalField2: thisdata.technicalField2,
  448. technicalField3: thisdata.technicalField3,
  449. technicalSource: String(thisdata.technicalSource),
  450. intellectualPropertyNumber: thisdata.intellectualPropertyNumber ? thisdata.intellectualPropertyNumber.split(",") : [],
  451. intellectualPropertyNumberText: thisdata.intellectualPropertyNumber,
  452. budget: thisdata.budget,
  453. firstYearExpenditure: thisdata.firstYearExpenditure,
  454. secondYearExpenditure: thisdata.secondYearExpenditure,
  455. thirdYearExpenditure: thisdata.thirdYearExpenditure,
  456. implement: thisdata.implement,
  457. technologyInnovation: thisdata.technologyInnovation,
  458. achievement: thisdata.achievement,
  459. internalLaborCost: thisdata.internalLaborCost,
  460. internalDirectCost: thisdata.internalDirectCost,
  461. internalDepreciationCost: thisdata.internalDepreciationCost,
  462. internalAmortizationCost: thisdata.internalAmortizationCost,
  463. internalDesignCost: thisdata.internalDesignCost,
  464. internalEquipmentCost: thisdata.internalEquipmentCost,
  465. internalOtherCost: thisdata.internalOtherCost,
  466. externalTotalCost: thisdata.externalTotalCost,
  467. externalAbroadCost: thisdata.externalAbroadCost,
  468. enterpriseFiller: thisdata.enterpriseFiller,
  469. signDate: thisdata.signDate,
  470. sortNumber: thisdata.sortNumber,
  471. startDateFormattedDate: thisdata.startDateFormattedDate,
  472. endDateFormattedDate: thisdata.endDateFormattedDate,
  473. projectMode: thisdata.projectMode,
  474. proofUrl: thisdata.proofUrl,
  475. proofDownloadFileName: thisdata.proofDownloadFileName
  476. });
  477. };
  478. this.state.pagination.current = data.data.pageNo;
  479. this.state.pagination.total = data.data.totalCount;
  480. this.setState({
  481. dataSource: this.state.data,
  482. pagination: this.state.pagination
  483. });
  484. }).always(function () {
  485. this.setState({
  486. loading: false
  487. });
  488. }.bind(this));
  489. },
  490. getInitialState() {
  491. return {
  492. mockData: [],
  493. selectedRowKeys: [],
  494. selectedRows: [],
  495. loading: false,
  496. pagination: {
  497. defaultCurrent: 1,
  498. defaultPageSize: 10,
  499. showQuickJumper: true,
  500. pageSize: 10,
  501. onChange: function (page) {
  502. this.loadData(page);
  503. }.bind(this),
  504. showTotal: function (total) {
  505. return '共' + total + '条数据';
  506. }
  507. },
  508. columns: [
  509. {
  510. title: '研发活动编号',
  511. dataIndex: 'activityNumber',
  512. key: 'activityNumber'
  513. }, {
  514. title: '研发活动名称',
  515. dataIndex: 'activityName',
  516. key: 'activityName'
  517. }, {
  518. title: '技术领域',
  519. dataIndex: 'technicalField',
  520. key: 'technicalField'
  521. }, {
  522. title: '技术来源',
  523. dataIndex: 'technicalSource',
  524. key: 'technicalSource',
  525. render: (text) => { return getTechnicalSource(text) }
  526. }, {
  527. title: '知识产权编号',
  528. dataIndex: 'intellectualPropertyNumberText',
  529. key: 'intellectualPropertyNumberText'
  530. }, {
  531. title: '开始时间',
  532. dataIndex: 'startDateFormattedDate',
  533. key: 'startDateFormattedDate'
  534. }, {
  535. title: '结束时间',
  536. dataIndex: 'endDateFormattedDate',
  537. key: 'endDateFormattedDate'
  538. }
  539. ],
  540. dataSource: []
  541. };
  542. },
  543. componentWillMount() {
  544. this.loadData();
  545. },
  546. tableRowClick(record, index) {
  547. this.state.RowData = record;
  548. this.setState({
  549. showDesc: true
  550. });
  551. },
  552. delectRow() {
  553. let deletedIds = [];
  554. for (let idx = 0; idx < this.state.selectedRows.length; idx++) {
  555. let rowItem = this.state.selectedRows[idx];
  556. if (rowItem.id) {
  557. deletedIds.push(rowItem.id)
  558. }
  559. }
  560. this.setState({
  561. selectedRowKeys: [],
  562. loading: deletedIds.length > 0
  563. });
  564. $.ajax({
  565. method: "POST",
  566. dataType: "json",
  567. crossDomain: false,
  568. url: globalConfig.context + "/api/user/cognizance/deleteActivity",
  569. data: {
  570. ids: deletedIds
  571. }
  572. }).done(function (data) {
  573. if (!data.error.length) {
  574. message.success('保存成功!');
  575. this.setState({
  576. loading: false,
  577. });
  578. } else {
  579. message.warning(data.error[0].message);
  580. };
  581. this.loadData();
  582. }.bind(this));
  583. },
  584. closeDesc(e, s) {
  585. this.state.showDesc = e;
  586. if (s) {
  587. this.loadData();
  588. };
  589. },
  590. search() {
  591. this.loadData();
  592. },
  593. reset() {
  594. this.state.activityName = undefined;
  595. this.state.activityNumber = undefined;
  596. this.loadData();
  597. },
  598. render() {
  599. const rowSelection = {
  600. selectedRowKeys: this.state.selectedRowKeys,
  601. onChange: (selectedRowKeys, selectedRows) => {
  602. this.setState({
  603. selectedRows: selectedRows,
  604. selectedRowKeys: selectedRowKeys
  605. });
  606. }
  607. };
  608. const hasSelected = this.state.selectedRowKeys.length > 0;
  609. return (
  610. <div className="user-content" >
  611. <div className="content-title">
  612. <span>企业研究开发活动情况表</span>
  613. </div>
  614. <div className="user-search">
  615. <Input placeholder="研发活动名称" value={this.state.activityName}
  616. onChange={(e) => { this.setState({ activityName: e.target.value }); }} />
  617. <Input placeholder="研发活动编号" value={this.state.activityNumber}
  618. onChange={(e) => { this.setState({ activityNumber: e.target.value }); }} />
  619. <Button type="primary" onClick={this.search}>搜索</Button>
  620. <Button onClick={this.reset}>重置</Button>
  621. <p>
  622. <Button style={{ background: "#ea0862", border: "none", color: "#fff" }}
  623. onClick={this.tableRowClick}>添加<Icon type="plus" /></Button>
  624. <Button style={{ background: "#3fcf9e", border: "none", color: "#fff" }}
  625. disabled={!hasSelected}
  626. onClick={this.delectRow}>删除<Icon type="minus" /></Button>
  627. </p>
  628. </div>
  629. <div className="patent-table">
  630. <Spin spinning={this.state.loading}>
  631. <Table columns={this.state.columns}
  632. dataSource={this.state.dataSource}
  633. pagination={this.state.pagination}
  634. rowSelection={rowSelection}
  635. onRowClick={this.tableRowClick} />
  636. </Spin>
  637. </div>
  638. <ActivityDesc data={this.state.RowData}
  639. mockData={this.state.mockData}
  640. showDesc={this.state.showDesc} closeDesc={this.closeDesc} />
  641. </div >
  642. );
  643. }
  644. });
  645. export default Activity;