activity.jsx 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  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, downloadFile } from '../../tools.js';
  5. import './activity.less';
  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 + "/techservice/cognizance/activity",
  27. data: {
  28. id: this.props.data.id,
  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. projectMode: this.state.projectMode
  48. }
  49. }).done(function (data) {
  50. if (!data.error.length) {
  51. message.success('保存成功!');
  52. this.setState({
  53. loading: false,
  54. visible: false
  55. });
  56. this.props.closeDesc(false, true);
  57. } else {
  58. message.warning(data.error[0].message);
  59. this.setState({
  60. loading: false
  61. });
  62. };
  63. }.bind(this));
  64. },
  65. handleCancel(e) {
  66. this.setState({
  67. visible: false,
  68. });
  69. this.props.closeDesc(false);
  70. },
  71. componentWillReceiveProps(nextProps) {
  72. this.state.visible = nextProps.showDesc;
  73. if (!this.props.showDesc && nextProps.showDesc) {
  74. this.state.activityName = nextProps.data.activityName;
  75. this.state.activityNumber = nextProps.data.activityNumber;
  76. this.state.startDateFormattedDate = nextProps.data.startDateFormattedDate;
  77. this.state.endDateFormattedDate = nextProps.data.endDateFormattedDate;
  78. this.state.techField = nextProps.data.techField;
  79. this.state.technicalSource = nextProps.data.technicalSource;
  80. this.state.targetKeys = nextProps.data.intellectualPropertyNumber || [];
  81. this.state.budget = nextProps.data.budget;
  82. this.state.firstYearExpenditure = nextProps.data.firstYearExpenditure;
  83. this.state.secondYearExpenditure = nextProps.data.secondYearExpenditure;
  84. this.state.thirdYearExpenditure = nextProps.data.thirdYearExpenditure;
  85. this.state.implement = nextProps.data.implement;
  86. this.state.technologyInnovation = nextProps.data.technologyInnovation;
  87. this.state.achievement = nextProps.data.achievement;
  88. this.state.mockData = nextProps.data.mockData;
  89. this.state.projectMode = nextProps.data.projectMode ? String(nextProps.data.projectMode) : undefined;
  90. this.state.proofUrl = nextProps.data.proofUrl;
  91. this.state.proofDownloadFileName = nextProps.data.proofDownloadFileName;
  92. };
  93. },
  94. intellectualChange(nextTargetKeys, direction, moveKeys) {
  95. this.setState({ targetKeys: nextTargetKeys });
  96. },
  97. intellectualSelectChange(sourceSelectedKeys, targetSelectedKeys) {
  98. this.setState({ selectedKeys: [...sourceSelectedKeys, ...targetSelectedKeys] });
  99. },
  100. render() {
  101. if (this.props.data) {
  102. return (
  103. <div className="admin-desc">
  104. <Modal title="企业研究开发活动情况详情" visible={this.state.visible} onCancel={this.handleCancel}
  105. width='800px' footer={[
  106. <Button key="submit" type="primary" size="large" loading={this.state.loading} onClick={this.handleOk}>保存</Button>,
  107. <Button key="back" type="ghost" size="large" onClick={this.handleCancel}>取消</Button>
  108. ]}
  109. className="admin-desc-content">
  110. <div className="clearfix">
  111. <div className="half-div">
  112. <p>研发活动编号:</p>
  113. <Input value={this.state.activityNumber}
  114. onChange={(e) => { this.setState({ activityNumber: e.target.value }); }} />
  115. </div>
  116. <div className="half-div">
  117. <p>研发活动名称:</p>
  118. <Input value={this.state.activityName}
  119. onChange={(e) => { this.setState({ activityName: e.target.value }); }} />
  120. </div>
  121. <div className="half-div">
  122. <p>开始日期:</p>
  123. <DatePicker
  124. value={this.state.startDateFormattedDate ? moment(this.state.startDateFormattedDate) : null}
  125. onChange={(data, dataString) => { this.setState({ startDateFormattedDate: dataString }); }} />
  126. </div>
  127. <div className="half-div">
  128. <p>结束日期:</p>
  129. <DatePicker
  130. value={this.state.endDateFormattedDate ? moment(this.state.endDateFormattedDate) : null}
  131. onChange={(data, dataString) => { this.setState({ endDateFormattedDate: dataString }); }} />
  132. </div>
  133. </div>
  134. <div>
  135. <p>技术领域:</p>
  136. <Cascader
  137. style={{ width: 500 }}
  138. options={techFieldList}
  139. value={this.state.techField}
  140. onChange={(value, selectedOptions) => { this.setState({ techField: value }); console.log(value) }}
  141. placeholder="选择技术领域"
  142. showSearch
  143. />,
  144. </div>
  145. <div className="half-div">
  146. <p>技术来源:</p>
  147. <Select placeholder="选择技术来源" style={{ width: 230 }}
  148. value={this.state.technicalSource}
  149. onChange={(e) => { this.setState({ technicalSource: e }) }}>
  150. {
  151. technicalSourceList.map(function (item, i) {
  152. return <Select.Option key={1000 + i} value={item.value} >{item.key}</Select.Option>
  153. })
  154. }
  155. </Select>
  156. </div>
  157. <div className="half-div">
  158. <p>参与人员:</p>
  159. <InputNumber value={this.state.participant}
  160. onChange={(e) => { this.setState({ participant: e }); }} />
  161. </div>
  162. <div style={{ marginTop: '10px' }}>
  163. <p>知识产权编号:</p>
  164. <Transfer
  165. dataSource={this.props.mockData}
  166. listStyle={{
  167. width: 300,
  168. height: 300,
  169. }}
  170. titles={['未选择', '已选择']}
  171. targetKeys={this.state.targetKeys}
  172. selectedKeys={this.state.selectedKeys}
  173. onChange={this.intellectualChange}
  174. onSelectChange={this.intellectualSelectChange}
  175. render={item => `${item.name}-${item.key}`}
  176. />
  177. </div>
  178. <div>
  179. <p>研发经费总预算(万元):</p>
  180. <InputNumber value={this.state.budget || 0}
  181. onChange={(e) => { this.setState({ budget: e }); }} />
  182. </div>
  183. <div className="clearfix" >
  184. <p>研发经费近三年总支出(万元):</p>
  185. <div className="half-div">
  186. <span>总计(万元):</span>
  187. <InputNumber value={
  188. this.state.firstYearExpenditure + this.state.secondYearExpenditure + this.state.thirdYearExpenditure || 0
  189. } />
  190. <span>(自动计算)</span>
  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 + "/techservice/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><Icon type="exclamation-circle" style={{ color: '#ffbf00', marginRight: '6px' }} />未上传!</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 + "/techservice/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 + "/techservice/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.data || !data.data.list) {
  318. if (data.error && data.error.length) {
  319. message.warning(data.error[0].message);
  320. this.state.ButtonDisabled = true;
  321. };
  322. return;
  323. };
  324. if (!intellectualList.data || !intellectualList.data.list) {
  325. if (intellectualList.error && intellectualList.error.length) {
  326. message.warning(intellectualList.error[0].message);
  327. this.state.ButtonDisabled = true;
  328. };
  329. return;
  330. };
  331. let theArr = [];
  332. for (let i = 0; i < intellectualList.data.list.length; i++) {
  333. theArr.push({
  334. key: intellectualList.data.list[i].intellectualPropertyNumber,
  335. name: intellectualList.data.list[i].intellectualPropertyName
  336. });
  337. };
  338. this.state.mockData = theArr;
  339. for (let i = 0; i < data.data.list.length; i++) {
  340. let thisdata = data.data.list[i];
  341. this.state.data.push({
  342. key: i,
  343. id: thisdata.id,
  344. uid: thisdata.uid,
  345. activityNumber: thisdata.activityNumber,
  346. activityName: thisdata.activityName,
  347. startDate: thisdata.startDate,
  348. endDate: thisdata.endDate,
  349. mockData: this.state.mockData,
  350. techField: [Number(thisdata.technicalField1), Number(thisdata.technicalField2), Number(thisdata.technicalField3)],
  351. technicalField: getTechField(thisdata.technicalField1, thisdata.technicalField2, thisdata.technicalField3),
  352. technicalField1: thisdata.technicalField1,
  353. technicalField2: thisdata.technicalField2,
  354. technicalField3: thisdata.technicalField3,
  355. technicalSource: String(thisdata.technicalSource),
  356. intellectualPropertyNumber: thisdata.intellectualPropertyNumber ? thisdata.intellectualPropertyNumber.split(",") : [],
  357. budget: thisdata.budget,
  358. firstYearExpenditure: thisdata.firstYearExpenditure,
  359. secondYearExpenditure: thisdata.secondYearExpenditure,
  360. thirdYearExpenditure: thisdata.thirdYearExpenditure,
  361. implement: thisdata.implement,
  362. technologyInnovation: thisdata.technologyInnovation,
  363. achievement: thisdata.achievement,
  364. internalLaborCost: thisdata.internalLaborCost,
  365. internalDirectCost: thisdata.internalDirectCost,
  366. internalDepreciationCost: thisdata.internalDepreciationCost,
  367. internalAmortizationCost: thisdata.internalAmortizationCost,
  368. internalDesignCost: thisdata.internalDesignCost,
  369. internalEquipmentCost: thisdata.internalEquipmentCost,
  370. internalOtherCost: thisdata.internalOtherCost,
  371. externalTotalCost: thisdata.externalTotalCost,
  372. externalAbroadCost: thisdata.externalAbroadCost,
  373. enterpriseFiller: thisdata.enterpriseFiller,
  374. signDate: thisdata.signDate,
  375. sortNumber: thisdata.sortNumber,
  376. startDateFormattedDate: thisdata.startDateFormattedDate,
  377. endDateFormattedDate: thisdata.endDateFormattedDate,
  378. projectMode: thisdata.projectMode,
  379. proofUrl: thisdata.proofUrl,
  380. proofDownloadFileName: thisdata.proofDownloadFileName
  381. });
  382. };
  383. this.state.pagination.current = data.data.pageNo;
  384. this.state.pagination.total = data.data.totalCount;
  385. this.setState({
  386. dataSource: this.state.data,
  387. pagination: this.state.pagination
  388. });
  389. }).always(function () {
  390. this.setState({
  391. loading: false
  392. });
  393. }.bind(this));
  394. },
  395. getInitialState() {
  396. return {
  397. mockData: [],
  398. selectedRowKeys: [],
  399. selectedRows: [],
  400. loading: false,
  401. pagination: {
  402. defaultCurrent: 1,
  403. defaultPageSize: 10,
  404. showQuickJumper: true,
  405. pageSize: 10,
  406. onChange: function (page) {
  407. this.loadData(page);
  408. }.bind(this),
  409. showTotal: function (total) {
  410. return '共' + total + '条数据';
  411. }
  412. },
  413. columns: [
  414. {
  415. title: '研发活动编号',
  416. dataIndex: 'activityNumber',
  417. key: 'activityNumber'
  418. }, {
  419. title: '研发活动名称',
  420. dataIndex: 'activityName',
  421. key: 'activityName'
  422. }, {
  423. title: '技术领域',
  424. dataIndex: 'technicalField',
  425. key: 'technicalField'
  426. }, {
  427. title: '技术来源',
  428. dataIndex: 'technicalSource',
  429. key: 'technicalSource',
  430. render: (text) => { return getTechnicalSource(text) }
  431. }, {
  432. title: '知识产权编号',
  433. dataIndex: 'intellectualPropertyNumber',
  434. key: 'intellectualPropertyNumber'
  435. }, {
  436. title: '开始时间',
  437. dataIndex: 'startDateFormattedDate',
  438. key: 'startDateFormattedDate'
  439. }, {
  440. title: '结束时间',
  441. dataIndex: 'endDateFormattedDate',
  442. key: 'endDateFormattedDate'
  443. }
  444. ],
  445. dataSource: []
  446. };
  447. },
  448. componentWillMount() {
  449. this.loadData();
  450. },
  451. tableRowClick(record, index) {
  452. this.state.RowData = record;
  453. this.setState({
  454. showDesc: true
  455. });
  456. },
  457. delectRow() {
  458. let deletedIds = [];
  459. for (let idx = 0; idx < this.state.selectedRows.length; idx++) {
  460. let rowItem = this.state.selectedRows[idx];
  461. if (rowItem.id) {
  462. deletedIds.push(rowItem.id)
  463. }
  464. }
  465. this.setState({
  466. selectedRowKeys: [],
  467. loading: deletedIds.length > 0
  468. });
  469. $.ajax({
  470. method: "POST",
  471. dataType: "json",
  472. crossDomain: false,
  473. url: globalConfig.context + "/techservice/cognizance/deleteActivity",
  474. data: {
  475. ids: deletedIds
  476. }
  477. }).done(function (data) {
  478. if (!data.error.length) {
  479. message.success('保存成功!');
  480. this.setState({
  481. loading: false,
  482. });
  483. } else {
  484. message.warning(data.error[0].message);
  485. };
  486. this.loadData();
  487. }.bind(this));
  488. },
  489. closeDesc(e, s) {
  490. this.state.showDesc = e;
  491. if (s) {
  492. this.loadData();
  493. };
  494. },
  495. search() {
  496. this.loadData();
  497. },
  498. reset() {
  499. this.state.activityName = undefined;
  500. this.state.activityNumber = undefined;
  501. this.loadData();
  502. },
  503. render() {
  504. const rowSelection = {
  505. selectedRowKeys: this.state.selectedRowKeys,
  506. onChange: (selectedRowKeys, selectedRows) => {
  507. this.setState({
  508. selectedRows: selectedRows,
  509. selectedRowKeys: selectedRowKeys
  510. });
  511. }
  512. };
  513. const hasSelected = this.state.selectedRowKeys.length > 0;
  514. return (
  515. <div className="user-content" >
  516. <div className="content-title">
  517. <span>企业研究开发活动情况表</span>
  518. </div>
  519. <div className="user-search">
  520. <Input placeholder="研发活动名称" value={this.state.activityName}
  521. onChange={(e) => { this.setState({ activityName: e.target.value }); }} />
  522. <Input placeholder="研发活动编号" value={this.state.activityNumber}
  523. onChange={(e) => { this.setState({ activityNumber: e.target.value }); }} />
  524. <Button type="primary" onClick={this.search}>搜索</Button>
  525. <Button onClick={this.reset}>重置</Button>
  526. <p>
  527. <Button style={{ background: "#ea0862", border: "none", color: "#fff" }}
  528. disabled={this.state.ButtonDisabled}
  529. onClick={this.tableRowClick}>添加<Icon type="plus" /></Button>
  530. <Button style={{ background: "#3fcf9e", border: "none", color: "#fff" }}
  531. disabled={!hasSelected}
  532. onClick={this.delectRow}>删除<Icon type="minus" /></Button>
  533. </p>
  534. </div>
  535. <div className="patent-table">
  536. <Spin spinning={this.state.loading}>
  537. <Table columns={this.state.columns}
  538. dataSource={this.state.dataSource}
  539. pagination={this.state.pagination}
  540. rowSelection={rowSelection}
  541. onRowClick={this.tableRowClick} />
  542. </Spin>
  543. </div>
  544. <ActivityDesc data={this.state.RowData}
  545. mockData={this.state.mockData}
  546. showDesc={this.state.showDesc} closeDesc={this.closeDesc} />
  547. </div >
  548. );
  549. }
  550. });
  551. export default Activity;