techDemand.jsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. import React from 'react';
  2. import {Button, Input, Select, Spin, Table, Switch, message, DatePicker } from 'antd';
  3. import $ from 'jquery/src/ajax';
  4. import moment from 'moment';
  5. import './techDemand.less';
  6. import TechDemandDesc from './demandDesc.jsx';
  7. import { demandTypeList } from '@/dataDic.js';
  8. import { getDemandType,getReleaseStateList } from '@/tools.js';
  9. const DemandList = React.createClass({
  10. loadData(pageNo) {
  11. this.state.data = [];
  12. this.setState({
  13. page:pageNo,
  14. loading: true
  15. });
  16. $.ajax({
  17. method: "get",
  18. dataType: "json",
  19. crossDomain: false,
  20. url: globalConfig.context + "/api/admin/demand/list",
  21. data: {
  22. pageNo: pageNo || 1,
  23. pageSize: this.state.pagination.pageSize,
  24. employerName: this.state.employerNameSearch,//客户名称
  25. name: this.state.nameSearch,
  26. auditStatus:this.state.auditStatusSearch,
  27. demandType: this.state.demandTypeSearch ? Number(this.state.demandTypeSearch) : undefined,
  28. status: this.state.statusSearch ? Number(this.state.statusSearch) : undefined,
  29. startDate: this.state.releaseDate[0],
  30. endDate: this.state.releaseDate[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. status: thisdata.status,
  46. name: thisdata.name,
  47. demandType: thisdata.demandType,
  48. auditStatus: thisdata.auditStatus,
  49. isHot: thisdata.isHot,
  50. isUrgent: thisdata.isUrgent,
  51. employerName:thisdata.employerName,
  52. createTime:thisdata.createTime?(new Date(thisdata.createTime)).toLocaleString():'',
  53. releaseDate:thisdata.releaseDate?(new Date(thisdata.releaseDate)).toLocaleString():''
  54. });
  55. };
  56. }
  57. this.state.pagination.current = data.data.pageNo;
  58. this.state.pagination.total = data.data.totalCount;
  59. if(data.data&&data.data.list&&!data.data.list.length){
  60. this.state.pagination.current=0
  61. this.state.pagination.total=0
  62. }
  63. this.setState({
  64. dataSource: theArr,
  65. pagination: this.state.pagination
  66. });
  67. }.bind(this),
  68. }).always(function () {
  69. this.setState({
  70. loading: false
  71. });
  72. }.bind(this));
  73. },
  74. getInitialState() {
  75. return {
  76. searchMore: true,
  77. validityPeriodDate: [],
  78. releaseDate: [],
  79. selectedRowKeys: [],
  80. selectedRows: [],
  81. loading: false,
  82. pagination: {
  83. defaultCurrent: 1,
  84. defaultPageSize: 10,
  85. showQuickJumper: true,
  86. pageSize: 10,
  87. onChange: function (page) {
  88. this.loadData(page);
  89. }.bind(this),
  90. showTotal: function (total) {
  91. return '共' + total + '条数据';
  92. }
  93. },
  94. columns: [
  95. {
  96. title: '编号',
  97. dataIndex: 'serialNumber',
  98. key: 'serialNumber',
  99. }, {
  100. title: '需求名称',
  101. dataIndex: 'name',
  102. key: 'name',
  103. }, {
  104. title: '需求类型',
  105. dataIndex: 'demandType',
  106. key: 'demandType',
  107. render: (text) => { return getDemandType(text); }
  108. },
  109. {
  110. title: '是否热门',
  111. dataIndex: 'isHot',
  112. key: 'isHot',
  113. render: text => { return text?'热门':'非热门'; }
  114. },
  115. {
  116. title: '是否加急',
  117. dataIndex: 'isUrgent',
  118. key: 'isUrgent',
  119. render: text => { return text?'加急':'未加急' }
  120. },
  121. {
  122. title: '客户名称',
  123. dataIndex: 'employerName',
  124. key: 'employerName'
  125. },
  126. {
  127. title: '发布状态',
  128. dataIndex: 'auditStatus',
  129. key: 'auditStatus',
  130. render: text => { return getReleaseStateList(text) }
  131. },
  132. {
  133. title: '需求状态',
  134. dataIndex: 'status',
  135. key: 'status',
  136. render: text => {
  137. return <div>
  138. {text=='0'&&<span>进行中</span>}
  139. {text=='1'&&<span>未解决</span>}
  140. {text=='2'&&<span>已解决</span>}
  141. </div>
  142. }
  143. },
  144. {
  145. title: '创建时间',
  146. dataIndex: 'createTime',
  147. key: 'createTime',
  148. },
  149. {
  150. title: '发布时间',
  151. dataIndex: 'releaseDate',
  152. key: 'releaseDate'
  153. }
  154. ],
  155. dataSource: [],
  156. searchTime: [,]
  157. };
  158. },
  159. componentWillMount() {
  160. let theArr = [];
  161. demandTypeList.map(function (item) {
  162. theArr.push(
  163. <Select.Option value={item.value} key={item.key}>{item.key}</Select.Option>
  164. )
  165. });
  166. this.state.demandTypeOption = theArr;
  167. this.loadData();
  168. },
  169. tableRowClick(record, index) {
  170. this.state.RowData = record;
  171. this.setState({
  172. showDesc: true,
  173. examineState:false
  174. });
  175. },
  176. delectRow(recard) {
  177. this.setState({
  178. loading:true
  179. })
  180. let deletedIds =[];
  181. let rowItem = this.state.selectedRowKeys[0];
  182. let data = this.state.dataSource ||[];
  183. if (data.length) {
  184. deletedIds.push(data[rowItem].id);
  185. }
  186. $.ajax({
  187. method: "POST",
  188. dataType: "json",
  189. crossDomain: false,
  190. url: globalConfig.context + "/api/admin/demand/annul",
  191. data: {
  192. id: deletedIds[0]
  193. }
  194. }).done(function (data) {
  195. if (!data.error.length) {
  196. message.success('下架成功!');
  197. this.setState({
  198. loading: false,
  199. selectedRowKeys:[],
  200. });
  201. } else {
  202. message.warning(data.error[0].message);
  203. };
  204. this.loadData();
  205. }.bind(this));
  206. },
  207. closeDesc(e, s) {
  208. this.state.showDesc = e;
  209. if (s) {
  210. this.loadData(this.state.page);
  211. };
  212. },
  213. search() {
  214. this.loadData();
  215. },
  216. reset() {
  217. this.state.nameSearch = '';
  218. this.state.demandTypeSearch = undefined;
  219. this.state.auditStatusSearch = undefined;
  220. this.state.statusSearch = undefined;
  221. this.state.employerNameSearch='';
  222. this.state.releaseDate = [];
  223. this.loadData();
  224. },
  225. searchSwitch() {
  226. this.setState({
  227. searchMore: !this.state.searchMore
  228. });
  229. },
  230. render() {
  231. const rowSelection = {
  232. selectedRowKeys: this.state.selectedRowKeys,
  233. onChange: (selectedRowKeys, selectedRows) => {
  234. this.setState({
  235. selectedRows: selectedRows.slice(-1),
  236. selectedRowKeys: selectedRowKeys.slice(-1)
  237. });
  238. }
  239. };
  240. const hasSelected = this.state.selectedRowKeys.length > 0;
  241. const { RangePicker } = DatePicker;
  242. const hasSelect = this.state.selectedRowKeys.length;
  243. return (
  244. <div className="user-content" >
  245. <div className="content-title">
  246. <span>科技需求库</span>
  247. </div>
  248. <div className="user-search">
  249. <Input placeholder="需求名称"
  250. value={this.state.nameSearch}
  251. onChange={(e) => { this.setState({ nameSearch: e.target.value }); }} />
  252. <Select placeholder="选择需求类型"
  253. style={{ width: 120 }}
  254. value={this.state.demandTypeSearch}
  255. onChange={(e) => { this.setState({ demandTypeSearch: e }) }}>
  256. {this.state.demandTypeOption}
  257. </Select>
  258. <Select placeholder="发布状态" style={{ width: 120 }}
  259. value={this.state.auditStatusSearch}
  260. onChange={(e) => { this.setState({ auditStatusSearch: e }) }}>
  261. <Select.Option value="0" >草稿</Select.Option>
  262. <Select.Option value="1" >发布审核</Select.Option>
  263. <Select.Option value="2" >已发布</Select.Option>
  264. <Select.Option value="3" >发布失败</Select.Option>
  265. <Select.Option value="4" >已撤销</Select.Option>
  266. </Select>
  267. <Select placeholder="需求状态" style={{ width: 160 }}
  268. value={this.state.statusSearch}
  269. onChange={(e) => { this.setState({ statusSearch: e }) }}>
  270. <Select.Option value="0" >进行中</Select.Option>
  271. <Select.Option value="1" >未解决</Select.Option>
  272. <Select.Option value="2" >已解决</Select.Option>
  273. </Select>
  274. <Button type="primary" onClick={this.search}>搜索</Button>
  275. <Button onClick={this.reset}>重置</Button>
  276. <Button type="danger" disabled={!hasSelect} onClick={(e)=>{this.delectRow()}}>下架</Button>
  277. <span>更多搜索<Switch defaultChecked={false} onChange={this.searchSwitch} /></span>
  278. <div className="search-more" style={this.state.searchMore ? { display: 'none' } : {}}>
  279. <Input style={{width:140,marginRight:10}} value={this.state.employerNameSearch} onChange={(e)=>{this.setState({employerNameSearch:e.target.value})}} placeholder="客户名称"/>
  280. <span>发布时间 :</span>
  281. <RangePicker
  282. value={[this.state.releaseDate[0] ? moment(this.state.releaseDate[0]) : null,
  283. this.state.releaseDate[1] ? moment(this.state.releaseDate[1]) : null]}
  284. onChange={(data, dataString) => { this.setState({ releaseDate: dataString }); }} />
  285. </div>
  286. </div>
  287. <div className="patent-table">
  288. <Spin spinning={this.state.loading}>
  289. <Table columns={this.state.columns}
  290. dataSource={this.state.dataSource}
  291. rowSelection={rowSelection}
  292. pagination={this.state.pagination}
  293. onRowClick={this.tableRowClick} />
  294. </Spin>
  295. </div>
  296. <TechDemandDesc
  297. data={this.state.RowData}
  298. examineState={this.state.examineState}
  299. demandTypeOption={this.state.demandTypeOption}
  300. showDesc={this.state.showDesc}
  301. closeDesc={this.closeDesc} />
  302. </div>
  303. );
  304. }
  305. });
  306. export default DemandList;