activity.jsx 29 KB

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