techDemand.jsx 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  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. dataSource: theArr,
  59. pagination: this.state.pagination
  60. });
  61. }.bind(this),
  62. }).always(function () {
  63. this.setState({
  64. loading: false
  65. });
  66. }.bind(this));
  67. },
  68. getInitialState() {
  69. return {
  70. searchMore: true,
  71. validityPeriodDate: [],
  72. releaseDate: [],
  73. selectedRowKeys: [],
  74. selectedRows: [],
  75. loading: false,
  76. pagination: {
  77. defaultCurrent: 1,
  78. defaultPageSize: 10,
  79. showQuickJumper: true,
  80. pageSize: 10,
  81. onChange: function (page) {
  82. this.loadData(page);
  83. }.bind(this),
  84. showTotal: function (total) {
  85. return '共' + total + '条数据';
  86. }
  87. },
  88. columns: [
  89. {
  90. title: '编号',
  91. dataIndex: 'serialNumber',
  92. key: 'serialNumber',
  93. }, {
  94. title: '需求名称',
  95. dataIndex: 'name',
  96. key: 'name',
  97. }, {
  98. title: '需求类型',
  99. dataIndex: 'demandType',
  100. key: 'demandType',
  101. render: text => { return getDemandType(text); }
  102. },
  103. {
  104. title: '发布状态',
  105. dataIndex: 'auditStatus',
  106. key: 'auditStatus',
  107. render: text => { return getReleaseStateList(text) }
  108. }, {
  109. title: '创建时间',
  110. dataIndex: 'createTime',
  111. key: 'createTime'
  112. },
  113. {
  114. title: '发布时间',
  115. dataIndex: 'releaseDate',
  116. key: 'releaseDate'
  117. },
  118. {
  119. title: '需求状态',
  120. dataIndex: 'status',
  121. key: 'status',
  122. render: text => {
  123. return <div>
  124. {text=='0'&&<span>进行中</span>}
  125. {text=='1'&&<span>未解决</span>}
  126. {text=='2'&&<span>已解决</span>}
  127. </div>
  128. }
  129. },
  130. {
  131. title: '操作',
  132. dataIndex: 'caozuo',
  133. key: 'caozuo',
  134. render:(text,recard) => {
  135. return <div className="btnRight">
  136. {recard.auditStatus!='1'&&recard.auditStatus!='2'&&<Button type="primary" style={{ background: "#3fcf9e", border: "none", color: "#fff" }} onClick={(e)=>{e.stopPropagation(),this.submission(recard)}}>提交审核</Button>}
  137. <Button type="danger" onClick={(e)=>{e.stopPropagation();this.delectRow(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. this.setState({
  245. loading:true
  246. })
  247. let idArr=[];
  248. idArr.push(recard.id);
  249. console.log(idArr)
  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. this.loadData(this.state.page);
  265. } else {
  266. message.warning(data.error[0].message);
  267. };
  268. }.bind(this));
  269. },
  270. addClick() {
  271. this.state.RowData = {};
  272. this.setState({
  273. showDesc: true
  274. });
  275. },
  276. closeDesc(e, s) {
  277. this.state.showDesc = e;
  278. if (s) {
  279. this.loadData(this.state.page);
  280. };
  281. },
  282. search() {
  283. this.loadData();
  284. },
  285. reset() {
  286. this.state.name = '';
  287. this.state.releaseDate = [];
  288. this.loadData();
  289. },
  290. searchSwitch() {
  291. this.setState({
  292. searchMore: !this.state.searchMore
  293. });
  294. },
  295. render() {
  296. const rowSelection = {
  297. selectedRowKeys: this.state.selectedRowKeys,
  298. onChange: (selectedRowKeys, selectedRows) => {
  299. this.setState({
  300. selectedRows: selectedRows.slice(-1),
  301. selectedRowKeys: selectedRowKeys.slice(-1)
  302. });
  303. }
  304. };
  305. const hasSelected = this.state.selectedRowKeys.length > 0;
  306. const { RangePicker } = DatePicker;
  307. return (
  308. <div className="user-content" >
  309. <div className="content-title">
  310. <span>我的科技需求</span>
  311. <div className="patent-addNew">
  312. <Button type="primary" onClick={this.addClick}>发布需求<Icon type="plus" /></Button>
  313. </div>
  314. </div>
  315. <div className="user-search">
  316. <Input placeholder="需求名称"
  317. value={this.state.name}
  318. onChange={(e) => { this.setState({ name: e.target.value }); }} />
  319. <Button type="primary" onClick={this.search}>搜索</Button>
  320. <Button onClick={this.reset}>重置</Button>
  321. <span>更多搜索<Switch defaultChecked={false} onChange={this.searchSwitch} /></span>
  322. <div className="search-more" style={this.state.searchMore ? { display: 'none' } : {}}>
  323. <span>发布时间 :</span>
  324. <RangePicker
  325. value={[this.state.releaseDate[0] ? moment(this.state.releaseDate[0]) : null,
  326. this.state.releaseDate[1] ? moment(this.state.releaseDate[1]) : null]}
  327. onChange={(data, dataString) => { this.setState({ releaseDate: dataString }); }} />
  328. </div>
  329. </div>
  330. <div className="patent-table">
  331. <Spin spinning={this.state.loading}>
  332. <Table columns={this.state.columns}
  333. dataSource={this.state.dataSource}
  334. rowSelection={rowSelection}
  335. pagination={this.state.pagination}
  336. onRowClick={this.tableRowClick} />
  337. </Spin>
  338. </div>
  339. <TechDemandDesc
  340. data={this.state.RowData}
  341. demandTypeOption={this.state.demandTypeOption}
  342. showDesc={this.state.showDesc}
  343. closeDesc={this.closeDesc} />
  344. </div >
  345. );
  346. }
  347. });
  348. export default DemandList;