activity.jsx 24 KB

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