techDemand.jsx 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. import React from 'react';
  2. import { Icon, Button, Input, Select, Spin, 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. <Button type="danger" onClick={(e)=>{e.stopPropagation();this.delectRow(recard)}}>删除</Button>
  139. {recard.auditStatus!='1'&&recard.auditStatus=='2'&&<Button type="success" onClick={(e)=>{ e.stopPropagation(),this.updateFun(recard)}}>刷新发布</Button>}
  140. {recard.auditStatus!='1'&&recard.auditStatus=='2'&&<Button type="danger" onClick={(e)=>{e.stopPropagation(),this.revokeFun(recard)}}>撤销发布</Button>}
  141. </div>
  142. }
  143. }
  144. ],
  145. dataSource: [],
  146. searchTime: [,]
  147. };
  148. },
  149. //提交审核
  150. submission(record){
  151. this.setState({
  152. showDesc:false,
  153. loading:true
  154. });
  155. $.ajax({
  156. method: "POST",
  157. dataType: "json",
  158. crossDomain: false,
  159. url: globalConfig.context + "/api/user/demand/publishDemand",
  160. data: {
  161. id:record.id,
  162. auditStatus:record.auditStatus
  163. }
  164. }).done(function (data) {
  165. if (!data.error.length) {
  166. message.success('提交成功.');
  167. this.setState({
  168. loading: false,
  169. });
  170. this.loadData(this.state.page)
  171. } else {
  172. message.warning(data.error[0].message);
  173. };
  174. }.bind(this));
  175. },
  176. //刷新发布
  177. updateFun(recard){
  178. this.setState({
  179. loading:true
  180. })
  181. $.ajax({
  182. method: "POST",
  183. dataType: "json",
  184. crossDomain: false,
  185. url: globalConfig.context +'/api/user/demand/refreshPublish',
  186. data: {
  187. id: recard.id,
  188. auditStatus:recard.auditStatus
  189. }
  190. }).done(function (data) {
  191. if (!data.error.length) {
  192. message.success('刷新成功!');
  193. this.setState({
  194. loading: false,
  195. });
  196. } else {
  197. message.warning(data.error[0].message);
  198. };
  199. this.loadData(this.state.page);
  200. }.bind(this));
  201. },
  202. //撤销发布
  203. revokeFun(recard){
  204. this.setState({
  205. loading:true
  206. })
  207. $.ajax({
  208. method: "POST",
  209. dataType: "json",
  210. crossDomain: false,
  211. url: globalConfig.context + '/api/user/demand/offShelf',
  212. data: {
  213. id: recard.id,
  214. auditStatus:recard.auditStatus
  215. }
  216. }).done(function (data) {
  217. if (!data.error.length) {
  218. message.success('撤销成功!');
  219. this.setState({
  220. loading: false,
  221. });
  222. this.loadData(this.state.page);
  223. } else {
  224. message.warning(data.error[0].message);
  225. };
  226. }.bind(this));
  227. },
  228. componentWillMount() {
  229. let theArr = [];
  230. demandTypeList.map(function (item) {
  231. theArr.push(
  232. <Select.Option value={item.value} key={item.key}>{item.key}</Select.Option>
  233. )
  234. });
  235. this.state.demandTypeOption = theArr;
  236. this.loadData();
  237. },
  238. tableRowClick(record, index) {
  239. this.state.RowData = record;
  240. this.setState({
  241. showDesc: true
  242. });
  243. },
  244. delectRow(recard) {
  245. this.setState({
  246. loading:true
  247. })
  248. let idArr=[];
  249. idArr.push(recard.id);
  250. $.ajax({
  251. method: "POST",
  252. dataType: "json",
  253. crossDomain: false,
  254. url: globalConfig.context + "/api/user/demand/delete",
  255. data: {
  256. ids: idArr
  257. }
  258. }).done(function (data) {
  259. if (!data.error.length) {
  260. message.success('删除成功!');
  261. this.setState({
  262. loading: false
  263. });
  264. if((this.state.total)%10==1){
  265. this.loadData((this.state.page)-1);
  266. }else{
  267. this.loadData(this.state.page);
  268. }
  269. } else {
  270. message.warning(data.error[0].message);
  271. };
  272. }.bind(this));
  273. },
  274. addClick() {
  275. this.state.RowData = {};
  276. this.setState({
  277. showDesc: true
  278. });
  279. },
  280. closeDesc(e, s) {
  281. this.state.showDesc = e;
  282. if (s) {
  283. this.loadData(this.state.page);
  284. };
  285. },
  286. search() {
  287. this.loadData();
  288. },
  289. reset() {
  290. this.state.name = '';
  291. this.state.releaseDate = [];
  292. this.loadData();
  293. },
  294. searchSwitch() {
  295. this.setState({
  296. searchMore: !this.state.searchMore
  297. });
  298. },
  299. render() {
  300. const rowSelection = {
  301. selectedRowKeys: this.state.selectedRowKeys,
  302. onChange: (selectedRowKeys, selectedRows) => {
  303. this.setState({
  304. selectedRows: selectedRows.slice(-1),
  305. selectedRowKeys: selectedRowKeys.slice(-1)
  306. });
  307. }
  308. };
  309. const hasSelected = this.state.selectedRowKeys.length > 0;
  310. const { RangePicker } = DatePicker;
  311. return (
  312. <div className="user-content" >
  313. <div className="content-title">
  314. <span>科技需求列表</span>
  315. <div className="patent-addNew">
  316. <Button type="primary" onClick={this.addClick}>发布需求<Icon type="plus" /></Button>
  317. </div>
  318. </div>
  319. <div className="user-search">
  320. <Input placeholder="需求名称"
  321. value={this.state.name}
  322. onChange={(e) => { this.setState({ name: e.target.value }); }} />
  323. <Button type="primary" onClick={this.search}>搜索</Button>
  324. <Button onClick={this.reset}>重置</Button>
  325. <span>更多搜索<Switch defaultChecked={false} onChange={this.searchSwitch} /></span>
  326. <div className="search-more" style={this.state.searchMore ? { display: 'none' } : {}}>
  327. <span>发布时间 :</span>
  328. <RangePicker
  329. value={[this.state.releaseDate[0] ? moment(this.state.releaseDate[0]) : null,
  330. this.state.releaseDate[1] ? moment(this.state.releaseDate[1]) : null]}
  331. onChange={(data, dataString) => { this.setState({ releaseDate: dataString }); }} />
  332. </div>
  333. </div>
  334. <div className="patent-table">
  335. <Spin spinning={this.state.loading}>
  336. <Table columns={this.state.columns}
  337. dataSource={this.state.dataSource}
  338. rowSelection={rowSelection}
  339. pagination={this.state.pagination}
  340. onRowClick={this.tableRowClick} />
  341. </Spin>
  342. </div>
  343. <TechDemandDesc
  344. data={this.state.RowData}
  345. demandTypeOption={this.state.demandTypeOption}
  346. showDesc={this.state.showDesc}
  347. closeDesc={this.closeDesc} />
  348. </div >
  349. );
  350. }
  351. });
  352. export default DemandList;