techDemand.jsx 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  1. import React from 'react';
  2. import {Icon, Button, Input, Select, Spin, Popconfirm, Table, Switch, message, DatePicker, Modal, Upload} from 'antd';
  3. import ajax from 'jquery/src/ajax/xhr.js';
  4. import $ from 'jquery/src/ajax';
  5. import moment from 'moment';
  6. import './techDemand.less';
  7. import TechDemandDesc from './demandDesc.jsx';
  8. import { demandTypeList } from '@/dataDic.js';
  9. import { getDemandType,getReleaseStateList } from '@/tools.js';
  10. const DemandList = React.createClass({
  11. loadData(pageNo) {
  12. this.state.data = [];
  13. this.setState({
  14. page:pageNo,
  15. loading: true
  16. });
  17. $.ajax({
  18. method: "get",
  19. dataType: "json",
  20. crossDomain: false,
  21. url: globalConfig.context + "/api/user/demand/list",
  22. data: {
  23. pageNo: pageNo || 1,
  24. pageSize: this.state.pagination.pageSize,
  25. name: this.state.name, //需求名称
  26. startDate: this.state.releaseDate[0],
  27. endDate: this.state.releaseDate[1],
  28. auditStatus: this.state.searchAuditStatus,
  29. createStartDate: this.state.releaseCreateTime[0],
  30. createEndDate: this.state.releaseCreateTime[1],
  31. },
  32. success: function (data) {
  33. let theArr = [];
  34. if (!data.data || !data.data.list) {
  35. if (data.error && data.error.length) {
  36. message.warning(data.error[0].message);
  37. };
  38. } else {
  39. for (let i = 0; i < data.data.list.length; i++) {
  40. let thisdata = data.data.list[i];
  41. theArr.push({
  42. key: i,
  43. id: thisdata.id,
  44. serialNumber: thisdata.serialNumber, //编号
  45. name: thisdata.name,
  46. demandType: thisdata.demandType,
  47. auditStatus: thisdata.auditStatus, //审核状态
  48. createTime:thisdata.createTime?(new Date(thisdata.createTime)).toLocaleString():'',
  49. status:thisdata.status, //需求状态
  50. releaseDate:thisdata.releaseDate?(new Date(thisdata.releaseDate)).toLocaleString():''
  51. });
  52. };
  53. };
  54. this.state.pagination.current = data.data.pageNo;
  55. this.state.pagination.total = data.data.totalCount;
  56. if(data.data&&data.data.list&&!data.data.list.length){
  57. this.state.pagination.current=0
  58. this.state.pagination.total=0
  59. };
  60. this.setState({
  61. total:data.data.totalCount,
  62. dataSource: theArr,
  63. pagination: this.state.pagination
  64. });
  65. }.bind(this),
  66. }).always(function () {
  67. this.setState({
  68. loading: false
  69. });
  70. }.bind(this));
  71. },
  72. getInitialState() {
  73. return {
  74. uploadFileLoading:false,
  75. searchMore: true,
  76. validityPeriodDate: [],
  77. releaseDate: [],
  78. releaseCreateTime: '',
  79. searchAuditStatus: '',
  80. selectedRowKeys: [],
  81. selectedRows: [],
  82. loading: false,
  83. pagination: {
  84. defaultCurrent: 1,
  85. defaultPageSize: 10,
  86. showQuickJumper: true,
  87. pageSize: 10,
  88. onChange: function (page) {
  89. this.loadData(page);
  90. }.bind(this),
  91. showTotal: function (total) {
  92. return '共' + total + '条数据';
  93. }
  94. },
  95. columns: [
  96. {
  97. title: '编号',
  98. dataIndex: 'serialNumber',
  99. key: 'serialNumber',
  100. }, {
  101. title: '需求名称',
  102. dataIndex: 'name',
  103. key: 'name',
  104. }, {
  105. title: '需求类型',
  106. dataIndex: 'demandType',
  107. key: 'demandType',
  108. render: text => { return getDemandType(text); }
  109. },
  110. {
  111. title: '发布状态',
  112. dataIndex: 'auditStatus',
  113. key: 'auditStatus',
  114. render: text => { return getReleaseStateList(text) }
  115. }, {
  116. title: '创建时间',
  117. dataIndex: 'createTime',
  118. key: 'createTime'
  119. },
  120. {
  121. title: '发布时间',
  122. dataIndex: 'releaseDate',
  123. key: 'releaseDate'
  124. },
  125. {
  126. title: '需求状态',
  127. dataIndex: 'status',
  128. key: 'status',
  129. render: text => {
  130. return <div>
  131. {text=='0'&&<span>进行中</span>}
  132. {text=='1'&&<span>未解决</span>}
  133. {text=='2'&&<span>已解决</span>}
  134. </div>
  135. }
  136. },
  137. {
  138. title: '操作',
  139. dataIndex: 'caozuo',
  140. key: 'caozuo',
  141. render:(text,recard) => {
  142. return <div className="btnRight">
  143. {recard.auditStatus!='1'&&recard.auditStatus!='2'&&<Button type="primary" style={{ background: "#3fcf9e", border: "none", color: "#fff" }} onClick={(e)=>{e.stopPropagation(),this.submission(recard)}}>提交审核</Button>}
  144. {/*{recard.auditStatus!='1'&&recard.auditStatus=='2'&&<Button type="success" onClick={(e)=>{ e.stopPropagation(),this.updateFun(recard)}}>刷新发布</Button>}*/}
  145. {recard.auditStatus!='1'&&recard.auditStatus=='2'&&<Button type="danger" onClick={(e)=>{e.stopPropagation(),this.revokeFun(recard)}}>撤销发布</Button>}
  146. </div>
  147. }
  148. }
  149. ],
  150. dataSource: [],
  151. searchTime: [,]
  152. };
  153. },
  154. //提交审核
  155. submission(record){
  156. this.setState({
  157. showDesc:false,
  158. loading:true
  159. });
  160. $.ajax({
  161. method: "POST",
  162. dataType: "json",
  163. crossDomain: false,
  164. url: globalConfig.context + "/api/user/demand/publishDemand",
  165. data: {
  166. id:record.id,
  167. auditStatus:record.auditStatus
  168. }
  169. }).done(function (data) {
  170. if (!data.error.length) {
  171. message.success('提交成功.');
  172. this.setState({
  173. loading: false,
  174. });
  175. this.loadData(this.state.page)
  176. } else {
  177. message.warning(data.error[0].message);
  178. };
  179. }.bind(this));
  180. },
  181. //刷新发布
  182. updateFun(recard){
  183. this.setState({
  184. loading:true
  185. })
  186. $.ajax({
  187. method: "POST",
  188. dataType: "json",
  189. crossDomain: false,
  190. url: globalConfig.context +'/api/user/demand/refreshPublish',
  191. data: {
  192. id: recard.id,
  193. auditStatus:recard.auditStatus
  194. }
  195. }).done(function (data) {
  196. if (!data.error.length) {
  197. message.success('刷新成功!');
  198. this.setState({
  199. loading: false,
  200. });
  201. } else {
  202. message.warning(data.error[0].message);
  203. };
  204. this.loadData(this.state.page);
  205. }.bind(this));
  206. },
  207. //撤销发布
  208. revokeFun(recard){
  209. this.setState({
  210. loading:true
  211. })
  212. $.ajax({
  213. method: "POST",
  214. dataType: "json",
  215. crossDomain: false,
  216. url: globalConfig.context + '/api/user/demand/offShelf',
  217. data: {
  218. id: recard.id,
  219. auditStatus:recard.auditStatus
  220. }
  221. }).done(function (data) {
  222. if (!data.error.length) {
  223. message.success('撤销成功!');
  224. this.setState({
  225. loading: false,
  226. });
  227. this.loadData(this.state.page);
  228. } else {
  229. message.warning(data.error[0].message);
  230. };
  231. }.bind(this));
  232. },
  233. componentWillMount() {
  234. let theArr = [];
  235. demandTypeList.map(function (item) {
  236. theArr.push(
  237. <Select.Option value={item.value} key={item.key}>{item.key}</Select.Option>
  238. )
  239. });
  240. this.state.demandTypeOption = theArr;
  241. this.loadData();
  242. },
  243. tableRowClick(record, index) {
  244. this.state.RowData = record;
  245. this.setState({
  246. showDesc: true
  247. });
  248. },
  249. delectRow(recard) {
  250. let deletedIds =[];
  251. let rowItem = this.state.selectedRowKeys[0];
  252. let data = this.state.dataSource ||[];
  253. if (data.length) {
  254. deletedIds.push(data[rowItem].id);
  255. }
  256. this.setState({
  257. selectedRowKeys: [],
  258. loading: deletedIds.length > 0
  259. });
  260. $.ajax({
  261. method: "POST",
  262. dataType: "json",
  263. crossDomain: false,
  264. url: globalConfig.context + "/api/user/demand/delete",
  265. data: {
  266. ids: deletedIds
  267. }
  268. }).done(function (data) {
  269. if (!data.error.length) {
  270. message.success('删除成功!');
  271. this.setState({
  272. loading: false
  273. });
  274. if((this.state.total)%10==1){
  275. this.loadData((this.state.page)-1);
  276. }else{
  277. this.loadData(this.state.page);
  278. }
  279. } else {
  280. message.warning(data.error[0].message);
  281. };
  282. }.bind(this));
  283. },
  284. addClick() {
  285. this.state.RowData = {};
  286. this.setState({
  287. showDesc: true
  288. });
  289. },
  290. closeDesc(e, s) {
  291. this.state.showDesc = e;
  292. if (s) {
  293. this.loadData(this.state.page);
  294. };
  295. },
  296. search() {
  297. this.loadData();
  298. },
  299. reset() {
  300. this.setState({
  301. name: '',
  302. releaseDate: [],
  303. releaseCreateTime: [],
  304. searchAuditStatus: '',
  305. },()=>{
  306. this.loadData();
  307. })
  308. },
  309. searchSwitch() {
  310. this.setState({
  311. searchMore: !this.state.searchMore
  312. });
  313. },
  314. downLoadFile() {
  315. window.open(globalConfig.context + '/api/user/demand/downloadTemplate?sign=demand_template')
  316. },
  317. render() {
  318. const rowSelection = {
  319. selectedRowKeys: this.state.selectedRowKeys,
  320. onChange: (selectedRowKeys, selectedRows) => {
  321. this.setState({
  322. selectedRows: selectedRows.slice(-1),
  323. selectedRowKeys: selectedRowKeys.slice(-1)
  324. });
  325. }
  326. };
  327. const hasSelected = this.state.selectedRowKeys.length > 0;
  328. const { RangePicker } = DatePicker;
  329. return (
  330. <div className="user-content" >
  331. <div className="content-title">
  332. <span>科技需求列表</span>
  333. <div className="patent-addNew">
  334. <Button type="primary" onClick={this.addClick}>发布需求<Icon type="plus" /></Button>
  335. <Button type="primary" onClick={this.downLoadFile}>下载批量导入模板</Button>
  336. <Upload
  337. action={globalConfig.context + "/api/user/demand/importDemand"}
  338. data={{ 'sign': '' }}
  339. showUploadList={false}
  340. multiple={true}
  341. onChange={(info) => {
  342. message.config({
  343. top: 80,
  344. });
  345. if (info.file.status === 'uploading') {
  346. this.setState({
  347. uploadFileLoading: true,
  348. })
  349. if(!this.uploadFileHide){
  350. this.uploadFileHide = message.loading('文件上传中..', 0);
  351. }
  352. }
  353. if (info.file.status === 'done') {
  354. this.setState({
  355. uploadFileLoading: false,
  356. })
  357. this.uploadFileHide();
  358. this.uploadFileHide = null;
  359. if (!info.file.response.error.length) {
  360. message.success(`${info.file.name} 文件上传成功!`);
  361. this.loadData()
  362. } else {
  363. message.warning(info.file.response.error[0].message);
  364. return;
  365. };
  366. } else if (info.file.status === 'error') {
  367. this.setState({
  368. uploadFileLoading: false,
  369. });
  370. this.uploadFileHide();
  371. this.uploadFileHide = null;
  372. message.error(`${info.file.name} 文件上传失败。`);
  373. };
  374. }} >
  375. <Button type="primary" loading={this.state.uploadFileLoading}>上传批量导入文件</Button>
  376. </Upload>
  377. </div>
  378. </div>
  379. <div className="user-search">
  380. <Input placeholder="需求名称"
  381. value={this.state.name}
  382. onChange={(e) => { this.setState({ name: e.target.value }); }} />
  383. <Button type="primary" onClick={this.search}>搜索</Button>
  384. <Button onClick={this.reset}>重置</Button>
  385. <Button
  386. type="danger"
  387. disabled={!hasSelected}
  388. onClick={this.delectRow}
  389. >
  390. 删除<Icon type="minus" />
  391. </Button>
  392. <span>更多搜索<Switch defaultChecked={false} onChange={this.searchSwitch} /></span>
  393. <div style={{display:'flex'}}>
  394. <div className="search-more" style={this.state.searchMore ? { display: 'none' } : {}}>
  395. <span>发布时间 :</span>
  396. <RangePicker
  397. value={[this.state.releaseDate[0] ? moment(this.state.releaseDate[0]) : null,
  398. this.state.releaseDate[1] ? moment(this.state.releaseDate[1]) : null]}
  399. onChange={(data, dataString) => { this.setState({ releaseDate: dataString }); }} />
  400. </div>
  401. <div className="search-more" style={this.state.searchMore ? { display: 'none' } : {marginLeft:'10px',marginRight:'10px'}}>
  402. <span>创建时间 :</span>
  403. <RangePicker
  404. value={[this.state.releaseCreateTime[0] ? moment(this.state.releaseCreateTime[0]) : null,
  405. this.state.releaseCreateTime[1] ? moment(this.state.releaseCreateTime[1]) : null]}
  406. onChange={(data, dataString) => { this.setState({ releaseCreateTime: dataString }); }} />
  407. </div>
  408. {/*0--草稿,1--审核中,2--审核通过,3--审核未通过,4-已撤销*/}
  409. <div className="search-more" style={this.state.searchMore ? { display: 'none' } : {}}>
  410. <span>审核状态 :</span>
  411. <Select style={{ width: 120,marginTop:'0px' }} value={this.state.searchAuditStatus}
  412. onChange={(e) => {
  413. if(e === -1){
  414. this.setState({ searchAuditStatus: '' })
  415. }else{
  416. this.setState({ searchAuditStatus: e })
  417. }
  418. }}>
  419. <Select.Option value={-1}>无</Select.Option>
  420. <Select.Option value={0}>草稿</Select.Option>
  421. <Select.Option value={1}>审核中</Select.Option>
  422. <Select.Option value={2}>审核通过</Select.Option>
  423. <Select.Option value={3}>审核未通过</Select.Option>
  424. <Select.Option value={4}>已撤销</Select.Option>
  425. </Select>
  426. </div>
  427. </div>
  428. </div>
  429. <div className="patent-table">
  430. <Spin spinning={this.state.loading}>
  431. <Table columns={this.state.columns}
  432. dataSource={this.state.dataSource}
  433. rowSelection={rowSelection}
  434. pagination={this.state.pagination}
  435. onRowClick={this.tableRowClick} />
  436. </Spin>
  437. </div>
  438. <TechDemandDesc
  439. data={this.state.RowData}
  440. demandTypeOption={this.state.demandTypeOption}
  441. showDesc={this.state.showDesc}
  442. closeDesc={this.closeDesc} />
  443. </div >
  444. );
  445. }
  446. });
  447. export default DemandList;