activity.jsx 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  1. import React from 'react';
  2. import { Icon, Button, Upload, Input, Spin, Table, message, Select, Modal, DatePicker, Cascader, Transfer, InputNumber, Switch } from 'antd';
  3. import { technicalSourceList } from '../../../../dataDic.js';
  4. import { techFieldList } from '../../../../DicTechFieldList.js';
  5. import { getTechField, getTechnicalSource, beforeUploadFile, newDownloadFile, getProportion, saveProportion } 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. 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 style={{ marginTop: '10px' }}>
  181. <p>知识产权编号:</p>
  182. <Transfer
  183. dataSource={this.props.mockData}
  184. listStyle={{
  185. width: 300,
  186. height: 300,
  187. }}
  188. titles={['未选择', '已选择']}
  189. targetKeys={this.state.targetKeys}
  190. selectedKeys={this.state.selectedKeys}
  191. onChange={this.intellectualChange}
  192. onSelectChange={this.intellectualSelectChange}
  193. render={item => `${item.name}-${item.key}`}
  194. />
  195. </div>
  196. <div>
  197. <p>研发经费总预算(万元):</p>
  198. <InputNumber value={this.state.budget || 0}
  199. onChange={(e) => { this.setState({ budget: e }); }} />
  200. </div>
  201. <div className="clearfix" >
  202. <p>研发经费近三年总支出(万元):</p>
  203. <div className="half-div">
  204. <span>总计(万元):</span>
  205. <span>{
  206. (this.state.firstYearExpenditure || 0) +
  207. (this.state.secondYearExpenditure || 0) +
  208. (this.state.thirdYearExpenditure || 0)
  209. }</span>
  210. </div>
  211. <div className="half-div">
  212. <span>其中(前一年):</span>
  213. <span>{this.state.firstYearExpenditure}
  214. </span>
  215. </div>
  216. <div className="half-div">
  217. <span>其中(前二年):</span>
  218. <span>{this.state.secondYearExpenditure}</span>
  219. </div>
  220. <div className="half-div">
  221. <span>其中(前三年):</span>
  222. <span>{this.state.thirdYearExpenditure}</span>
  223. </div>
  224. </div>
  225. <div className="clearfix">
  226. <div className="half-div">
  227. <p>目的及组织实施方式(限400字):</p>
  228. <Input type="textarea" rows={6}
  229. value={this.state.implement}
  230. onChange={(e) => {
  231. if (e.target.value.length > 400) {
  232. return;
  233. }
  234. this.setState({ implement: e.target.value });
  235. }} />
  236. </div>
  237. <div className="half-div">
  238. <p>核心技术及创新点(限400字):</p>
  239. <Input type="textarea" rows={6}
  240. value={this.state.technologyInnovation}
  241. onChange={(e) => {
  242. if (e.target.value.length > 400) {
  243. return;
  244. }
  245. this.setState({ technologyInnovation: e.target.value });
  246. }} />
  247. </div>
  248. <div className="half-div">
  249. <p>取得的阶段性成果(限400字):</p>
  250. <Input type="textarea" rows={6}
  251. value={this.state.achievement}
  252. onChange={(e) => {
  253. if (e.target.value.length > 400) {
  254. return;
  255. }
  256. this.setState({ achievement: e.target.value });
  257. }} />
  258. </div>
  259. </div>
  260. <Select style={{ width: 120 }}
  261. placeholder='请选择立项类型'
  262. value={this.state.projectMode}
  263. onChange={(e) => { this.setState({ projectMode: e }); }}>
  264. <Select.Option value='1'>内部立项</Select.Option>
  265. <Select.Option value='2'>外部立项</Select.Option>
  266. </Select>
  267. <div style={{ width: '50%' }}>
  268. <Upload
  269. name="ratepay"
  270. action={globalConfig.context + "/api/admin/uploadProof"}
  271. data={{ 'sign': 'proof', 'uid': this.props.uid }}
  272. beforeUpload={beforeUploadFile}
  273. showUploadList={false}
  274. onChange={(info) => {
  275. if (info.file.status !== 'uploading') {
  276. console.log(info.file, info.fileList);
  277. }
  278. if (info.file.status === 'done') {
  279. if (!info.file.response.error.length) {
  280. message.success(`${info.file.name} 文件上传成功!`);
  281. } else {
  282. message.warning(info.file.response.error[0].message);
  283. return;
  284. };
  285. this.state.proofUrl = info.file.response.data;
  286. } else if (info.file.status === 'error') {
  287. message.error(`${info.file.name} 文件上传失败。`);
  288. }
  289. }}
  290. >
  291. <Button><Icon type="upload" /> 上传立项证明材料 </Button>
  292. </Upload>
  293. <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>
  294. </div>
  295. </Modal>
  296. </div>
  297. );
  298. } else {
  299. return <div></div>
  300. }
  301. },
  302. });
  303. const Activity = React.createClass({
  304. loadData(pageNo) {
  305. this.state.data = [];
  306. this.setState({
  307. loading: true
  308. });
  309. $.when($.ajax({
  310. method: "post",
  311. dataType: "json",
  312. crossDomain: false,
  313. url: globalConfig.context + "/api/admin/activityList",
  314. data: {
  315. pageNo: pageNo || 1,
  316. pageSize: this.state.pagination.pageSize,
  317. uid: this.props.data.uid,
  318. activityNumber: this.state.activityNumber,
  319. activityName: this.state.activityName,
  320. startDateFormattedDate: this.state.startDateFormattedDate,
  321. endDateFormattedDate: this.state.endDateFormattedDate
  322. }
  323. }), $.ajax({
  324. method: "post",
  325. dataType: "json",
  326. crossDomain: false,
  327. url: globalConfig.context + "/api/admin/intellectualList",
  328. data: {
  329. uid: this.props.data.uid,
  330. pageNo: pageNo || 1,
  331. pageSize: 99,
  332. }
  333. })).done((data1, data2) => {
  334. let data = data1[0];
  335. let intellectualList = data2[0];
  336. if (data.error.length || !data.data || !data.data.list) {
  337. message.warning(data.error[0].message);
  338. return;
  339. };
  340. if (intellectualList.error.length || !intellectualList.data || !intellectualList.data.list) {
  341. message.warning(intellectualList.error[0].message);
  342. return;
  343. };
  344. let theArr = [];
  345. for (let i = 0; i < intellectualList.data.list.length; i++) {
  346. theArr.push({
  347. key: intellectualList.data.list[i].intellectualPropertyNumber,
  348. name: intellectualList.data.list[i].intellectualPropertyName
  349. });
  350. };
  351. this.state.mockData = theArr;
  352. for (let i = 0; i < data.data.list.length; i++) {
  353. let thisdata = data.data.list[i];
  354. this.state.data.push({
  355. key: i,
  356. id: thisdata.id,
  357. uid: thisdata.uid,
  358. activityNumber: thisdata.activityNumber,
  359. activityName: thisdata.activityName,
  360. startDate: thisdata.startDate,
  361. endDate: thisdata.endDate,
  362. mockData: this.state.mockData,
  363. techField: [Number(thisdata.technicalField1), Number(thisdata.technicalField2), Number(thisdata.technicalField3)],
  364. technicalField: getTechField(thisdata.technicalField1, thisdata.technicalField2, thisdata.technicalField3),
  365. technicalField1: thisdata.technicalField1,
  366. technicalField2: thisdata.technicalField2,
  367. technicalField3: thisdata.technicalField3,
  368. technicalSource: thisdata.technicalSource ? String(thisdata.technicalSource) : undefined,
  369. intellectualPropertyNumber: thisdata.intellectualPropertyNumber ? thisdata.intellectualPropertyNumber.split(",") : [],
  370. budget: thisdata.budget,
  371. firstYearExpenditure: thisdata.firstYearExpenditure,
  372. secondYearExpenditure: thisdata.secondYearExpenditure,
  373. thirdYearExpenditure: thisdata.thirdYearExpenditure,
  374. implement: thisdata.implement,
  375. technologyInnovation: thisdata.technologyInnovation,
  376. achievement: thisdata.achievement,
  377. internalLaborCost: thisdata.internalLaborCost,
  378. internalDirectCost: thisdata.internalDirectCost,
  379. internalDepreciationCost: thisdata.internalDepreciationCost,
  380. internalAmortizationCost: thisdata.internalAmortizationCost,
  381. internalDesignCost: thisdata.internalDesignCost,
  382. internalEquipmentCost: thisdata.internalEquipmentCost,
  383. internalOtherCost: thisdata.internalOtherCost,
  384. externalTotalCost: thisdata.externalTotalCost,
  385. externalAbroadCost: thisdata.externalAbroadCost,
  386. enterpriseFiller: thisdata.enterpriseFiller,
  387. signDate: thisdata.signDate,
  388. sortNumber: thisdata.sortNumber,
  389. startDateFormattedDate: thisdata.startDateFormattedDate,
  390. endDateFormattedDate: thisdata.endDateFormattedDate,
  391. projectMode: thisdata.projectMode,
  392. proofUrl: thisdata.proofUrl,
  393. proofDownloadFileName: thisdata.proofDownloadFileName
  394. });
  395. };
  396. this.state.pagination.current = data.data.pageNo;
  397. this.state.pagination.total = data.data.totalCount;
  398. this.setState({
  399. dataSource: this.state.data,
  400. pagination: this.state.pagination
  401. });
  402. }).always(function () {
  403. this.setState({
  404. loading: false
  405. });
  406. }.bind(this));
  407. let _me = this;
  408. getProportion(this.props.data.uid, function (data) { _me.setState({ proportion: data }); });
  409. },
  410. getInitialState() {
  411. return {
  412. mockData: [],
  413. selectedRowKeys: [],
  414. selectedRows: [],
  415. loading: false,
  416. pagination: {
  417. defaultCurrent: 1,
  418. defaultPageSize: 10,
  419. showQuickJumper: true,
  420. pageSize: 10,
  421. onChange: function (page) {
  422. this.loadData(page);
  423. }.bind(this),
  424. showTotal: function (total) {
  425. return '共' + total + '条数据';
  426. }
  427. },
  428. columns: [
  429. {
  430. title: '研发活动编号',
  431. dataIndex: 'activityNumber',
  432. key: 'activityNumber'
  433. }, {
  434. title: '研发活动名称',
  435. dataIndex: 'activityName',
  436. key: 'activityName'
  437. }, {
  438. title: '技术领域',
  439. dataIndex: 'technicalField',
  440. key: 'technicalField'
  441. }, {
  442. title: '技术来源',
  443. dataIndex: 'technicalSource',
  444. key: 'technicalSource',
  445. render: (text) => { return getTechnicalSource(text) }
  446. }, {
  447. title: '知识产权编号',
  448. dataIndex: 'intellectualPropertyNumber',
  449. key: 'intellectualPropertyNumber'
  450. }, {
  451. title: '开始时间',
  452. dataIndex: 'startDateFormattedDate',
  453. key: 'startDateFormattedDate'
  454. }, {
  455. title: '结束时间',
  456. dataIndex: 'endDateFormattedDate',
  457. key: 'endDateFormattedDate'
  458. }
  459. ],
  460. dataSource: []
  461. };
  462. },
  463. componentWillMount() {
  464. this.loadData();
  465. },
  466. tableRowClick(record, index) {
  467. this.state.RowData = record;
  468. this.setState({
  469. showDesc: true
  470. });
  471. },
  472. delectRow() {
  473. let deletedIds = [];
  474. for (let idx = 0; idx < this.state.selectedRows.length; idx++) {
  475. let rowItem = this.state.selectedRows[idx];
  476. if (rowItem.id) {
  477. deletedIds.push(rowItem.id)
  478. }
  479. }
  480. this.setState({
  481. selectedRowKeys: [],
  482. loading: deletedIds.length > 0
  483. });
  484. $.ajax({
  485. method: "post",
  486. dataType: "json",
  487. crossDomain: false,
  488. url: globalConfig.context + "/api/admin/deleteActivity",
  489. data: {
  490. ids: deletedIds
  491. }
  492. }).done(function (data) {
  493. if (!data.error.length) {
  494. message.success('保存成功!');
  495. this.setState({
  496. loading: false,
  497. });
  498. } else {
  499. message.warning(data.error[0].message);
  500. };
  501. this.loadData();
  502. }.bind(this));
  503. },
  504. closeDesc(e, s) {
  505. this.state.showDesc = e;
  506. if (s) {
  507. this.loadData();
  508. };
  509. },
  510. search() {
  511. this.loadData();
  512. },
  513. reset() {
  514. this.state.activityName = undefined;
  515. this.state.activityNumber = undefined;
  516. this.state.startDateFormattedDate = undefined;
  517. this.state.endDateFormattedDate = undefined;
  518. this.loadData();
  519. },
  520. render() {
  521. const rowSelection = {
  522. selectedRowKeys: this.state.selectedRowKeys,
  523. onChange: (selectedRowKeys, selectedRows) => {
  524. this.setState({
  525. selectedRows: selectedRows,
  526. selectedRowKeys: selectedRowKeys
  527. });
  528. }
  529. };
  530. const hasSelected = this.state.selectedRowKeys.length > 0;
  531. return (
  532. <div className="user-content" >
  533. <div className="content-title">
  534. <span>企业研究开发活动情况表</span>
  535. <span className="proportion"> 是否已完成:</span>
  536. <Switch
  537. checked={this.state.proportion && this.state.proportion.activity == 1 ? true : false}
  538. checkedChildren={'已完成'}
  539. unCheckedChildren={'未完成'}
  540. onChange={(e) => {
  541. e ? this.state.proportion.activity = 1 : this.state.proportion.activity = 0;
  542. saveProportion(this.state.proportion.id, 'activity', this.state.proportion.activity);
  543. this.setState({ proportion: this.state.proportion });
  544. }} />
  545. </div>
  546. <div className="user-search">
  547. <Input placeholder="研发活动名称" value={this.state.activityName}
  548. onChange={(e) => { this.setState({ activityName: e.target.value }); }} />
  549. <Input placeholder="研发活动编号" value={this.state.activityNumber}
  550. onChange={(e) => { this.setState({ activityNumber: e.target.value }); }} />
  551. <span>开始日期:</span>
  552. <DatePicker
  553. value={this.state.startDateFormattedDate ? moment(this.state.startDateFormattedDate) : null}
  554. onChange={(data, dataString) => { this.setState({ startDateFormattedDate: dataString }); }} />
  555. <span>结束日期:</span>
  556. <DatePicker
  557. value={this.state.endDateFormattedDate ? moment(this.state.endDateFormattedDate) : null}
  558. onChange={(data, dataString) => { this.setState({ endDateFormattedDate: dataString }); }} />
  559. <Button type="primary" onClick={this.search}>搜索</Button>
  560. <Button onClick={this.reset}>重置</Button>
  561. <p>
  562. <Button style={{ background: "#ea0862", border: "none", color: "#fff" }}
  563. onClick={this.tableRowClick}>添加<Icon type="plus" /></Button>
  564. <Button style={{ background: "#3fcf9e", border: "none", color: "#fff" }}
  565. disabled={!hasSelected}
  566. onClick={this.delectRow}>删除<Icon type="minus" /></Button>
  567. </p>
  568. </div>
  569. <div className="patent-table" >
  570. <Spin spinning={this.state.loading}>
  571. <Table columns={this.state.columns}
  572. dataSource={this.state.dataSource}
  573. pagination={this.state.pagination}
  574. rowSelection={rowSelection}
  575. onRowClick={this.tableRowClick} />
  576. </Spin>
  577. </div>
  578. <ActivityDesc data={this.state.RowData}
  579. uid={this.props.data.uid}
  580. mockData={this.state.mockData}
  581. showDesc={this.state.showDesc} closeDesc={this.closeDesc} />
  582. </div >
  583. );
  584. }
  585. });
  586. export default Activity;