techDemand.jsx 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  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 './techDemandDesc.jsx';
  8. import { provinceArr, demandTypeList } from '../../dataDic.js';
  9. import { companySearch, getDemandType } from '../../tools.js';
  10. const DemandList = React.createClass({
  11. loadData(pageNo, apiUrl) {
  12. this.state.data = [];
  13. this.setState({
  14. loading: true
  15. });
  16. $.ajax({
  17. method: "get",
  18. dataType: "json",
  19. crossDomain: false,
  20. url: globalConfig.context + (apiUrl || this.props['data-listApiUrl']),
  21. data: {
  22. pageNo: pageNo || 1,
  23. pageSize: this.state.pagination.pageSize,
  24. province: this.state.province,
  25. serialNumber: this.state.serialNumber,
  26. name: this.state.name,
  27. keyword: this.state.keyword,
  28. infoSources: this.state.infoSources ? Number(this.state.infoSources) : undefined,
  29. demandType: this.state.demandType ? Number(this.state.demandType) : undefined,
  30. //username: this.state.username,
  31. status: this.state.status ? Number(this.state.status) : undefined,
  32. release: this.state.release ? Number(this.state.release) : undefined,
  33. validityPeriodStartDate: this.state.validityPeriodDate[0],
  34. validityPeriodEndDate: this.state.validityPeriodDate[1],
  35. releaseDateStartDate: this.state.releaseDate[0],
  36. releaseDateEndDate: this.state.releaseDate[1],
  37. },
  38. success: function (data) {
  39. let theArr = [];
  40. if (!data.data && !data.data.list) {
  41. if (data.error && data.error.length) {
  42. message.warning(data.error[0].message);
  43. };
  44. } else {
  45. for (let i = 0; i < data.data.list.length; i++) {
  46. let thisdata = data.data.list[i];
  47. theArr.push({
  48. key: i,
  49. id: thisdata.id,
  50. serialNumber: thisdata.serialNumber,
  51. dataCategory: thisdata.dataCategory,
  52. name: thisdata.name,
  53. keyword: thisdata.keyword,
  54. infoSources: thisdata.infoSources,
  55. username: thisdata.username,
  56. demandType: thisdata.demandType,
  57. validityPeriod: thisdata.validityPeriod,
  58. employerName: thisdata.employerName,
  59. employerId:thisdata.employerId,
  60. province: thisdata.province,
  61. status: thisdata.status,
  62. releaseStatus: thisdata.releaseStatus,
  63. releaseDate: thisdata.releaseDate,
  64. principalId: thisdata.principalId,
  65. validityPeriodFormattedDate: thisdata.validityPeriodFormattedDate,
  66. releaseDateFormattedDate: thisdata.releaseDateFormattedDate
  67. });
  68. };
  69. }
  70. this.state.pagination.current = data.data.pageNo;
  71. this.state.pagination.total = data.data.totalCount;
  72. this.setState({
  73. dataSource: theArr,
  74. pagination: this.state.pagination
  75. });
  76. }.bind(this),
  77. }).always(function () {
  78. this.setState({
  79. loading: false
  80. });
  81. }.bind(this));
  82. },
  83. getInitialState() {
  84. return {
  85. searchMore: true,
  86. validityPeriodDate: [],
  87. releaseDate: [],
  88. selectedRowKeys: [],
  89. selectedRows: [],
  90. loading: false,
  91. pagination: {
  92. defaultCurrent: 1,
  93. defaultPageSize: 10,
  94. showQuickJumper: true,
  95. pageSize: 10,
  96. onChange: function (page) {
  97. this.loadData(page);
  98. }.bind(this),
  99. showTotal: function (total) {
  100. return '共' + total + '条数据';
  101. }
  102. },
  103. columns: [
  104. {
  105. title: '编号',
  106. dataIndex: 'serialNumber',
  107. key: 'serialNumber',
  108. }, {
  109. title: '需求名称',
  110. dataIndex: 'name',
  111. key: 'name',
  112. }, {
  113. title: '关键字',
  114. dataIndex: 'keyword',
  115. key: 'keyword',
  116. }, {
  117. title: '需求类型',
  118. dataIndex: 'demandType',
  119. key: 'demandType',
  120. render: text => { return getDemandType(text); }
  121. }, {
  122. title: '信息来源',
  123. dataIndex: 'infoSources',
  124. key: 'infoSources',
  125. render: text => {
  126. switch (text) {
  127. case "0":
  128. return <span>平台采集</span>;
  129. case "1":
  130. return <span>客户发布</span>
  131. }
  132. }
  133. }, {
  134. title: '雇主名称',
  135. dataIndex: 'username',
  136. key: 'username',
  137. }, {
  138. title: '需求状态',
  139. dataIndex: 'status',
  140. key: 'status',
  141. render: text => {
  142. switch (text) {
  143. case "0":
  144. return <span>进行中</span>;
  145. case "1":
  146. return <span>未解决</span>;
  147. case "1":
  148. return <span>已解决</span>;
  149. }
  150. }
  151. }, {
  152. title: '是否发布',
  153. dataIndex: 'release',
  154. key: 'release',
  155. render: text => {
  156. switch (text) {
  157. case "0":
  158. return <span>未发布</span>;
  159. case "1":
  160. return <span>发布</span>
  161. }
  162. }
  163. }, {
  164. title: '有效期限',
  165. dataIndex: 'validityPeriodFormattedDate',
  166. key: 'validityPeriodFormattedDate',
  167. }, {
  168. title: '发布时间',
  169. dataIndex: 'releaseDateFormattedDate',
  170. key: 'releaseDateFormattedDate',
  171. }, {
  172. title: '管理员',
  173. dataIndex: 'principalId',
  174. key: 'principalId',
  175. }
  176. ],
  177. dataSource: [],
  178. searchTime: [,]
  179. };
  180. },
  181. getCompanyList() {
  182. this.setState({
  183. loading: true
  184. });
  185. $.ajax({
  186. method: "get",
  187. dataType: "json",
  188. crossDomain: false,
  189. url: globalConfig.context + "/api/admin/demand/unitNames",
  190. success: function (data) {
  191. let theArr = [];
  192. if (!data.data) {
  193. if (data.error && data.error.length) {
  194. message.warning(data.error[0].message);
  195. };
  196. } else {
  197. data.data.map(function (item) {
  198. theArr.push(
  199. <Select.Option value={item.uid} key={item.uid}>{item.unitName}</Select.Option>
  200. )
  201. });
  202. };
  203. this.setState({
  204. companyOption: theArr
  205. });
  206. }.bind(this),
  207. }).always(function () {
  208. this.setState({
  209. loading: false
  210. });
  211. }.bind(this));
  212. },
  213. getUserList() {
  214. this.setState({
  215. loading: true
  216. });
  217. $.ajax({
  218. method: "get",
  219. dataType: "json",
  220. crossDomain: false,
  221. url: globalConfig.context + "/api/admin/demand/userNames",
  222. success: function (data) {
  223. let theArr = [];
  224. if (!data.data) {
  225. if (data.error && data.error.length) {
  226. message.warning(data.error[0].message);
  227. };
  228. } else {
  229. data.data.map(function (item) {
  230. theArr.push(
  231. <Select.Option value={item.uid} key={item.uid}>{item.username}</Select.Option>
  232. )
  233. });
  234. };
  235. this.setState({
  236. userOption: theArr
  237. });
  238. }.bind(this),
  239. }).always(function () {
  240. this.setState({
  241. loading: false
  242. });
  243. }.bind(this));
  244. },
  245. componentWillMount() {
  246. let pArr = [], dArr = [];
  247. provinceArr.map(function (item) {
  248. pArr.push(
  249. <Select.Option value={item} key={item}>{item}</Select.Option>
  250. )
  251. });
  252. demandTypeList.map(function (item) {
  253. dArr.push(
  254. <Select.Option value={item.value} key={item.key}>{item.key}</Select.Option>
  255. )
  256. });
  257. this.state.provinceOption = pArr;
  258. this.state.demandTypeOption = dArr;
  259. this.loadData();
  260. this.getCompanyList();
  261. this.getUserList();
  262. // if (window.location.search) {
  263. // let theArr(window.location.search);
  264. // if (theObj.id != 'null' && theObj.type != 'null') {
  265. // this.tableRowClick(theObj);
  266. // };
  267. // };
  268. },
  269. componentWillReceiveProps(nextProps) {
  270. if (this.props['data-listApiUrl'] != nextProps['data-listApiUrl']) {
  271. this.loadData(null, nextProps['data-listApiUrl']);
  272. this.state.selectedRowKeys = [];
  273. this.state.selectedRows = [];
  274. };
  275. },
  276. tableRowClick(record, index) {
  277. this.state.RowData = record;
  278. this.setState({
  279. showDesc: true
  280. });
  281. },
  282. delectRow() {
  283. let deletedIds = [];
  284. for (let idx = 0; idx < this.state.selectedRows.length; idx++) {
  285. let rowItem = this.state.selectedRows[idx];
  286. if (rowItem.id) {
  287. deletedIds.push(rowItem.id)
  288. };
  289. };
  290. this.setState({
  291. selectedRowKeys: [],
  292. loading: deletedIds.length > 0
  293. });
  294. $.ajax({
  295. method: "POST",
  296. dataType: "json",
  297. crossDomain: false,
  298. url: globalConfig.context + "/api/admin/demand/delete",
  299. data: {
  300. ids: deletedIds
  301. }
  302. }).done(function (data) {
  303. if (!data.error.length) {
  304. message.success('删除成功!');
  305. this.setState({
  306. loading: false,
  307. });
  308. } else {
  309. message.warning(data.error[0].message);
  310. };
  311. this.loadData();
  312. }.bind(this));
  313. },
  314. addClick() {
  315. this.state.RowData = {};
  316. this.setState({
  317. showDesc: true
  318. });
  319. },
  320. closeDesc(e, s) {
  321. this.state.showDesc = e;
  322. if (s) {
  323. this.loadData();
  324. };
  325. },
  326. search() {
  327. this.loadData();
  328. },
  329. reset() {
  330. this.state.province = undefined;
  331. this.state.serialNumber = undefined;
  332. this.state.name = undefined;
  333. this.state.keyword = undefined;
  334. this.state.infoSources = undefined;
  335. this.state.demandType = undefined;
  336. this.state.username = undefined;
  337. this.state.status = undefined;
  338. this.state.release = undefined;
  339. this.state.validityPeriodDate = [];
  340. this.state.releaseDate = [];
  341. this.loadData();
  342. },
  343. searchSwitch() {
  344. this.setState({
  345. searchMore: !this.state.searchMore
  346. });
  347. },
  348. render() {
  349. const rowSelection = {
  350. selectedRowKeys: this.state.selectedRowKeys,
  351. onChange: (selectedRowKeys, selectedRows) => {
  352. this.setState({
  353. selectedRows: selectedRows,
  354. selectedRowKeys: selectedRowKeys
  355. });
  356. }
  357. };
  358. const hasSelected = this.state.selectedRowKeys.length > 0;
  359. const { RangePicker } = DatePicker;
  360. return (
  361. <div className="user-content" >
  362. <div className="content-title">
  363. <span>科技需求管理</span>
  364. <div className="patent-addNew">
  365. <Button type="primary" onClick={this.addClick}>新增需求<Icon type="plus" /></Button>
  366. </div>
  367. </div>
  368. <div className="user-search">
  369. <Select placeholder="选择省份"
  370. style={{ width: 100 }}
  371. value={this.state.province}
  372. showSearch
  373. filterOption={companySearch}
  374. onChange={(e) => { this.setState({ province: e }) }}>
  375. {this.state.provinceOption}
  376. </Select>
  377. <Input placeholder="需求编号"
  378. value={this.state.serialNumber}
  379. onChange={(e) => { this.setState({ serialNumber: e.target.value }); }} />
  380. <Input placeholder="需求名称"
  381. value={this.state.name}
  382. onChange={(e) => { this.setState({ name: e.target.value }); }} />
  383. <Input placeholder="关键字"
  384. value={this.state.keyword}
  385. onChange={(e) => { this.setState({ keyword: e.target.value }); }} />
  386. <Select placeholder="选择信息来源" style={{ width: 120 }}
  387. value={this.state.infoSources}
  388. onChange={(e) => { this.setState({ infoSources: e }) }}>
  389. <Select.Option value="0" >平台采集</Select.Option>
  390. <Select.Option value="1" >客户发布</Select.Option>
  391. </Select>
  392. <Select placeholder="选择需求类型"
  393. style={{ width: 120 }}
  394. value={this.state.demandType}
  395. onChange={(e) => { this.setState({ demandType: e }) }}>
  396. {this.state.demandTypeOption}
  397. </Select>
  398. <Select placeholder="选择需求状态" style={{ width: 120 }}
  399. value={this.state.status}
  400. onChange={(e) => { this.setState({ status: e }) }}>
  401. <Select.Option value="0" >进行中</Select.Option>
  402. <Select.Option value="1" >未解决</Select.Option>
  403. <Select.Option value="2" >已解决</Select.Option>
  404. </Select>
  405. <Select placeholder="选择是否发布" style={{ width: 120 }}
  406. value={this.state.release}
  407. onChange={(e) => { this.setState({ release: e }) }}>
  408. <Select.Option value="0" >未发布</Select.Option>
  409. <Select.Option value="1" >已发布</Select.Option>
  410. </Select>
  411. <Button type="primary" onClick={this.search}>搜索</Button>
  412. <Button onClick={this.reset}>重置</Button>
  413. <Button style={{ background: "#3fcf9e", border: "none", color: "#fff" }}
  414. disabled={!hasSelected}
  415. onClick={this.delectRow}>删除<Icon type="minus" /></Button>
  416. <span>更多搜索<Switch defaultChecked={false} onChange={this.searchSwitch} /></span>
  417. <div className="search-more" style={this.state.searchMore ? { display: 'none' } : {}}>
  418. <p>
  419. <span>有效期限 :</span>
  420. <RangePicker
  421. value={[this.state.validityPeriodDate[0] ? moment(this.state.validityPeriodDate[0]) : null,
  422. this.state.validityPeriodDate[1] ? moment(this.state.validityPeriodDate[1]) : null]}
  423. onChange={(data, dataString) => { this.setState({ validityPeriodDate: dataString }); }} />
  424. <span>发布时间 :</span>
  425. <RangePicker
  426. value={[this.state.releaseDate[0] ? moment(this.state.releaseDate[0]) : null,
  427. this.state.releaseDate[1] ? moment(this.state.releaseDate[1]) : null]}
  428. onChange={(data, dataString) => { this.setState({ releaseDate: dataString }); }} />
  429. </p>
  430. </div>
  431. </div>
  432. <div className="patent-table">
  433. <Spin spinning={this.state.loading}>
  434. <Table columns={this.state.columns}
  435. dataSource={this.state.dataSource}
  436. rowSelection={rowSelection}
  437. pagination={this.state.pagination}
  438. onRowClick={this.tableRowClick} />
  439. </Spin>
  440. </div>
  441. <TechDemandDesc
  442. data={this.state.RowData}
  443. detailApiUrl={this.props['data-detailApiUrl']}
  444. companyOption={this.state.companyOption}
  445. userOption={this.state.userOption}
  446. demandTypeOption={this.state.demandTypeOption}
  447. showDesc={this.state.showDesc}
  448. closeDesc={this.closeDesc} />
  449. </div >
  450. );
  451. }
  452. });
  453. export default DemandList;