activity.jsx 26 KB

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