techDemand.jsx 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. import React from 'react';
  2. import { Icon, Button, Input, Select, Spin, Popconfirm,Table, Switch, message, DatePicker, Modal } 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. },
  29. success: function (data) {
  30. let theArr = [];
  31. if (!data.data || !data.data.list) {
  32. if (data.error && data.error.length) {
  33. message.warning(data.error[0].message);
  34. };
  35. } else {
  36. for (let i = 0; i < data.data.list.length; i++) {
  37. let thisdata = data.data.list[i];
  38. theArr.push({
  39. key: i,
  40. id: thisdata.id,
  41. serialNumber: thisdata.serialNumber, //编号
  42. name: thisdata.name,
  43. demandType: thisdata.demandType,
  44. auditStatus: thisdata.auditStatus, //审核状态
  45. createTime:thisdata.createTime?(new Date(thisdata.createTime)).toLocaleString():'',
  46. status:thisdata.status, //需求状态
  47. releaseDate:thisdata.releaseDate?(new Date(thisdata.releaseDate)).toLocaleString():''
  48. });
  49. };
  50. };
  51. this.state.pagination.current = data.data.pageNo;
  52. this.state.pagination.total = data.data.totalCount;
  53. if(data.data&&data.data.list&&!data.data.list.length){
  54. this.state.pagination.current=0
  55. this.state.pagination.total=0
  56. };
  57. this.setState({
  58. total:data.data.totalCount,
  59. dataSource: theArr,
  60. pagination: this.state.pagination
  61. });
  62. }.bind(this),
  63. }).always(function () {
  64. this.setState({
  65. loading: false
  66. });
  67. }.bind(this));
  68. },
  69. getInitialState() {
  70. return {
  71. searchMore: true,
  72. validityPeriodDate: [],
  73. releaseDate: [],
  74. selectedRowKeys: [],
  75. selectedRows: [],
  76. loading: false,
  77. pagination: {
  78. defaultCurrent: 1,
  79. defaultPageSize: 10,
  80. showQuickJumper: true,
  81. pageSize: 10,
  82. onChange: function (page) {
  83. this.loadData(page);
  84. }.bind(this),
  85. showTotal: function (total) {
  86. return '共' + total + '条数据';
  87. }
  88. },
  89. columns: [
  90. {
  91. title: '编号',
  92. dataIndex: 'serialNumber',
  93. key: 'serialNumber',
  94. }, {
  95. title: '需求名称',
  96. dataIndex: 'name',
  97. key: 'name',
  98. }, {
  99. title: '需求类型',
  100. dataIndex: 'demandType',
  101. key: 'demandType',
  102. render: text => { return getDemandType(text); }
  103. },
  104. {
  105. title: '发布状态',
  106. dataIndex: 'auditStatus',
  107. key: 'auditStatus',
  108. render: text => { return getReleaseStateList(text) }
  109. }, {
  110. title: '创建时间',
  111. dataIndex: 'createTime',
  112. key: 'createTime'
  113. },
  114. {
  115. title: '发布时间',
  116. dataIndex: 'releaseDate',
  117. key: 'releaseDate'
  118. },
  119. {
  120. title: '需求状态',
  121. dataIndex: 'status',
  122. key: 'status',
  123. render: text => {
  124. return <div>
  125. {text=='0'&&<span>进行中</span>}
  126. {text=='1'&&<span>未解决</span>}
  127. {text=='2'&&<span>已解决</span>}
  128. </div>
  129. }
  130. },
  131. {
  132. title: '操作',
  133. dataIndex: 'caozuo',
  134. key: 'caozuo',
  135. render:(text,recard) => {
  136. return <div className="btnRight">
  137. {recard.auditStatus!='1'&&recard.auditStatus!='2'&&<Button type="primary" style={{ background: "#3fcf9e", border: "none", color: "#fff" }} onClick={(e)=>{e.stopPropagation(),this.submission(recard)}}>提交审核</Button>}
  138. {recard.auditStatus!='1'&&recard.auditStatus=='2'&&<Button type="success" onClick={(e)=>{ e.stopPropagation(),this.updateFun(recard)}}>刷新发布</Button>}
  139. {recard.auditStatus!='1'&&recard.auditStatus=='2'&&<Button type="danger" onClick={(e)=>{e.stopPropagation(),this.revokeFun(recard)}}>撤销发布</Button>}
  140. </div>
  141. }
  142. }
  143. ],
  144. dataSource: [],
  145. searchTime: [,]
  146. };
  147. },
  148. //提交审核
  149. submission(record){
  150. this.setState({
  151. showDesc:false,
  152. loading:true
  153. });
  154. $.ajax({
  155. method: "POST",
  156. dataType: "json",
  157. crossDomain: false,
  158. url: globalConfig.context + "/api/user/demand/publishDemand",
  159. data: {
  160. id:record.id,
  161. auditStatus:record.auditStatus
  162. }
  163. }).done(function (data) {
  164. if (!data.error.length) {
  165. message.success('提交成功.');
  166. this.setState({
  167. loading: false,
  168. });
  169. this.loadData(this.state.page)
  170. } else {
  171. message.warning(data.error[0].message);
  172. };
  173. }.bind(this));
  174. },
  175. //刷新发布
  176. updateFun(recard){
  177. this.setState({
  178. loading:true
  179. })
  180. $.ajax({
  181. method: "POST",
  182. dataType: "json",
  183. crossDomain: false,
  184. url: globalConfig.context +'/api/user/demand/refreshPublish',
  185. data: {
  186. id: recard.id,
  187. auditStatus:recard.auditStatus
  188. }
  189. }).done(function (data) {
  190. if (!data.error.length) {
  191. message.success('刷新成功!');
  192. this.setState({
  193. loading: false,
  194. });
  195. } else {
  196. message.warning(data.error[0].message);
  197. };
  198. this.loadData(this.state.page);
  199. }.bind(this));
  200. },
  201. //撤销发布
  202. revokeFun(recard){
  203. this.setState({
  204. loading:true
  205. })
  206. $.ajax({
  207. method: "POST",
  208. dataType: "json",
  209. crossDomain: false,
  210. url: globalConfig.context + '/api/user/demand/offShelf',
  211. data: {
  212. id: recard.id,
  213. auditStatus:recard.auditStatus
  214. }
  215. }).done(function (data) {
  216. if (!data.error.length) {
  217. message.success('撤销成功!');
  218. this.setState({
  219. loading: false,
  220. });
  221. this.loadData(this.state.page);
  222. } else {
  223. message.warning(data.error[0].message);
  224. };
  225. }.bind(this));
  226. },
  227. componentWillMount() {
  228. let theArr = [];
  229. demandTypeList.map(function (item) {
  230. theArr.push(
  231. <Select.Option value={item.value} key={item.key}>{item.key}</Select.Option>
  232. )
  233. });
  234. this.state.demandTypeOption = theArr;
  235. this.loadData();
  236. },
  237. tableRowClick(record, index) {
  238. this.state.RowData = record;
  239. this.setState({
  240. showDesc: true
  241. });
  242. },
  243. delectRow(recard) {
  244. let deletedIds =[];
  245. let rowItem = this.state.selectedRowKeys[0];
  246. let data = this.state.dataSource ||[];
  247. if (data.length) {
  248. deletedIds.push(data[rowItem].id);
  249. }
  250. this.setState({
  251. selectedRowKeys: [],
  252. loading: deletedIds.length > 0
  253. });
  254. $.ajax({
  255. method: "POST",
  256. dataType: "json",
  257. crossDomain: false,
  258. url: globalConfig.context + "/api/user/demand/delete",
  259. data: {
  260. ids: deletedIds
  261. }
  262. }).done(function (data) {
  263. if (!data.error.length) {
  264. message.success('删除成功!');
  265. this.setState({
  266. loading: false
  267. });
  268. if((this.state.total)%10==1){
  269. this.loadData((this.state.page)-1);
  270. }else{
  271. this.loadData(this.state.page);
  272. }
  273. } else {
  274. message.warning(data.error[0].message);
  275. };
  276. }.bind(this));
  277. },
  278. addClick() {
  279. this.state.RowData = {};
  280. this.setState({
  281. showDesc: true
  282. });
  283. },
  284. closeDesc(e, s) {
  285. this.state.showDesc = e;
  286. if (s) {
  287. this.loadData(this.state.page);
  288. };
  289. },
  290. search() {
  291. this.loadData();
  292. },
  293. reset() {
  294. this.state.name = '';
  295. this.state.releaseDate = [];
  296. this.loadData();
  297. },
  298. searchSwitch() {
  299. this.setState({
  300. searchMore: !this.state.searchMore
  301. });
  302. },
  303. render() {
  304. const rowSelection = {
  305. selectedRowKeys: this.state.selectedRowKeys,
  306. onChange: (selectedRowKeys, selectedRows) => {
  307. this.setState({
  308. selectedRows: selectedRows.slice(-1),
  309. selectedRowKeys: selectedRowKeys.slice(-1)
  310. });
  311. }
  312. };
  313. const hasSelected = this.state.selectedRowKeys.length > 0;
  314. const { RangePicker } = DatePicker;
  315. return (
  316. <div className="user-content" >
  317. <div className="content-title">
  318. <span>科技需求列表</span>
  319. <div className="patent-addNew">
  320. <Button type="primary" onClick={this.addClick}>发布需求<Icon type="plus" /></Button>
  321. </div>
  322. </div>
  323. <div className="user-search">
  324. <Input placeholder="需求名称"
  325. value={this.state.name}
  326. onChange={(e) => { this.setState({ name: e.target.value }); }} />
  327. <Button type="primary" onClick={this.search}>搜索</Button>
  328. <Button onClick={this.reset}>重置</Button>
  329. <Button
  330. type="danger"
  331. disabled={!hasSelected}
  332. onClick={this.delectRow}
  333. >
  334. 删除<Icon type="minus" />
  335. </Button>
  336. <span>更多搜索<Switch defaultChecked={false} onChange={this.searchSwitch} /></span>
  337. <div className="search-more" style={this.state.searchMore ? { display: 'none' } : {}}>
  338. <span>发布时间 :</span>
  339. <RangePicker
  340. value={[this.state.releaseDate[0] ? moment(this.state.releaseDate[0]) : null,
  341. this.state.releaseDate[1] ? moment(this.state.releaseDate[1]) : null]}
  342. onChange={(data, dataString) => { this.setState({ releaseDate: dataString }); }} />
  343. </div>
  344. </div>
  345. <div className="patent-table">
  346. <Spin spinning={this.state.loading}>
  347. <Table columns={this.state.columns}
  348. dataSource={this.state.dataSource}
  349. rowSelection={rowSelection}
  350. pagination={this.state.pagination}
  351. onRowClick={this.tableRowClick} />
  352. </Spin>
  353. </div>
  354. <TechDemandDesc
  355. data={this.state.RowData}
  356. demandTypeOption={this.state.demandTypeOption}
  357. showDesc={this.state.showDesc}
  358. closeDesc={this.closeDesc} />
  359. </div >
  360. );
  361. }
  362. });
  363. export default DemandList;