techDemand.jsx 21 KB

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