activity.jsx 29 KB

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