techDemand.jsx 23 KB

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