activity.jsx 26 KB

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