activity.jsx 26 KB

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