techDemand.jsx 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  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. title: '管理员',
  186. dataIndex: 'principalId',
  187. key: 'principalId',
  188. }, {
  189. title: '技术经纪人',
  190. dataIndex: 'techBrokerId',
  191. key: 'techBrokerId',
  192. }
  193. ],
  194. dataSource: [],
  195. searchTime: [,]
  196. };
  197. },
  198. getCompanyList() {
  199. this.setState({
  200. loading: true
  201. });
  202. $.ajax({
  203. method: "get",
  204. dataType: "json",
  205. crossDomain: false,
  206. url: globalConfig.context + "/api/admin/demand/unitNames",
  207. success: function (data) {
  208. let theArr = [];
  209. if (!data.data) {
  210. if (data.error && data.error.length) {
  211. message.warning(data.error[0].message);
  212. };
  213. } else {
  214. data.data.map(function (item) {
  215. theArr.push(
  216. <Select.Option value={item.uid} key={item.uid}>{item.unitName}</Select.Option>
  217. )
  218. });
  219. };
  220. this.setState({
  221. companyOption: theArr
  222. });
  223. }.bind(this),
  224. }).always(function () {
  225. this.setState({
  226. loading: false
  227. });
  228. }.bind(this));
  229. },
  230. getUserList() {
  231. this.setState({
  232. loading: true
  233. });
  234. $.ajax({
  235. method: "get",
  236. dataType: "json",
  237. crossDomain: false,
  238. url: globalConfig.context + "/api/admin/demand/userNames",
  239. success: function (data) {
  240. let theArr = [];
  241. if (!data.data) {
  242. if (data.error && data.error.length) {
  243. message.warning(data.error[0].message);
  244. };
  245. } else {
  246. data.data.map(function (item) {
  247. theArr.push(
  248. <Select.Option value={item.uid} key={item.uid}>{item.username}</Select.Option>
  249. )
  250. });
  251. };
  252. this.setState({
  253. userOption: theArr
  254. });
  255. }.bind(this),
  256. }).always(function () {
  257. this.setState({
  258. loading: false
  259. });
  260. }.bind(this));
  261. },
  262. componentWillMount() {
  263. let theArr = [];
  264. demandTypeList.map(function (item) {
  265. theArr.push(
  266. <Select.Option value={item.value} key={item.key}>{item.key}</Select.Option>
  267. )
  268. });
  269. this.state.demandTypeOption = theArr;
  270. if (window.location.search) {
  271. let theObj = getSearchUrl(window.location.search);
  272. if (theObj.rid) {
  273. theObj.id = theObj.rid;
  274. theObj.employerId = theObj.uid;
  275. if (theObj.rid != 'null') {
  276. this.tableRowClick(theObj);
  277. };
  278. };
  279. };
  280. this.loadData();
  281. this.getCompanyList();
  282. this.getUserList();
  283. },
  284. componentWillReceiveProps(nextProps) {
  285. if (this.props['data-listApiUrl'] != nextProps['data-listApiUrl']) {
  286. this.loadData(null, nextProps['data-listApiUrl']);
  287. this.state.selectedRowKeys = [];
  288. this.state.selectedRows = [];
  289. };
  290. },
  291. tableRowClick(record, index) {
  292. this.state.RowData = record;
  293. this.setState({
  294. showDesc: true
  295. });
  296. },
  297. delectRow() {
  298. let deletedIds = [];
  299. for (let idx = 0; idx < this.state.selectedRows.length; idx++) {
  300. let rowItem = this.state.selectedRows[idx];
  301. if (rowItem.id) {
  302. deletedIds.push(rowItem.id)
  303. };
  304. };
  305. this.setState({
  306. selectedRowKeys: [],
  307. loading: deletedIds.length > 0
  308. });
  309. $.ajax({
  310. method: "POST",
  311. dataType: "json",
  312. crossDomain: false,
  313. url: globalConfig.context + "/api/admin/demand/delete",
  314. data: {
  315. ids: deletedIds
  316. }
  317. }).done(function (data) {
  318. if (!data.error.length) {
  319. message.success('删除成功!');
  320. this.setState({
  321. loading: false,
  322. });
  323. } else {
  324. message.warning(data.error[0].message);
  325. };
  326. this.loadData();
  327. }.bind(this));
  328. },
  329. addClick() {
  330. this.state.RowData = {};
  331. this.setState({
  332. showDesc: true
  333. });
  334. },
  335. closeDesc(e, s) {
  336. this.state.showDesc = e;
  337. if (s) {
  338. this.loadData();
  339. };
  340. },
  341. search() {
  342. this.loadData();
  343. },
  344. reset() {
  345. this.state.serialNumber = undefined;
  346. this.state.name = undefined;
  347. this.state.keyword = undefined;
  348. this.state.infoSources = undefined;
  349. this.state.demandType = undefined;
  350. this.state.username = undefined;
  351. this.state.status = undefined;
  352. this.state.releaseStatus = undefined;
  353. this.state.auditStatus = undefined;
  354. this.state.validityPeriodDate = [];
  355. this.state.releaseDate = [];
  356. this.loadData();
  357. },
  358. searchSwitch() {
  359. this.setState({
  360. searchMore: !this.state.searchMore
  361. });
  362. },
  363. render() {
  364. const rowSelection = {
  365. selectedRowKeys: this.state.selectedRowKeys,
  366. onChange: (selectedRowKeys, selectedRows) => {
  367. this.setState({
  368. selectedRows: selectedRows.slice(-1),
  369. selectedRowKeys: selectedRowKeys.slice(-1)
  370. });
  371. }
  372. };
  373. const hasSelected = this.state.selectedRowKeys.length > 0;
  374. const { RangePicker } = DatePicker;
  375. return (
  376. <div className="user-content" >
  377. <div className="content-title">
  378. <span>科技需求管理</span>
  379. <div className="patent-addNew clearfix">
  380. <Upload
  381. action={globalConfig.context + "/api/admin/demand/uploadTemplate"}
  382. data={{ 'sign': 'demand_template' }}
  383. beforeUpload={beforeUploadFile}
  384. showUploadList={false}
  385. onChange={(info) => {
  386. if (info.file.status !== 'uploading') {
  387. console.log(info.file, info.fileList);
  388. }
  389. if (info.file.status === 'done') {
  390. if (!info.file.response.error.length) {
  391. message.success(`${info.file.name} 文件上传成功!`);
  392. } else {
  393. message.warning(info.file.response.error[0].message);
  394. return;
  395. };
  396. } else if (info.file.status === 'error') {
  397. message.error(`${info.file.name} 文件上传失败。`);
  398. };
  399. }} >
  400. <Button>上传批量导入模板</Button>
  401. </Upload>
  402. <Button onClick={() => { window.open(globalConfig.context + '/api/admin/demand/downloadTemplate?sign=demand_template') }}>下载批量导入模板</Button>
  403. <Button type="primary" className="addButton" onClick={this.addClick}>新增需求<Icon type="plus" /></Button>
  404. <BatchImport closeDesc={this.closeDesc} />
  405. </div>
  406. </div>
  407. <div className="user-search">
  408. <Input placeholder="需求编号"
  409. value={this.state.serialNumber}
  410. onChange={(e) => { this.setState({ serialNumber: e.target.value }); }} />
  411. <Input placeholder="需求名称"
  412. value={this.state.name}
  413. onChange={(e) => { this.setState({ name: e.target.value }); }} />
  414. <Input placeholder="关键字"
  415. value={this.state.keyword}
  416. onChange={(e) => { this.setState({ keyword: e.target.value }); }} />
  417. <Select placeholder="选择信息来源" style={{ width: 120 }}
  418. value={this.state.infoSources}
  419. onChange={(e) => { this.setState({ infoSources: e }) }}>
  420. <Select.Option value="0" >平台采集</Select.Option>
  421. <Select.Option value="1" >客户发布</Select.Option>
  422. <Select.Option value="2" >批量导入</Select.Option>
  423. <Select.Option value="3" >三方对接</Select.Option>
  424. </Select>
  425. <Select placeholder="选择需求类型"
  426. style={{ width: 120 }}
  427. value={this.state.demandType}
  428. onChange={(e) => { this.setState({ demandType: e }) }}>
  429. {this.state.demandTypeOption}
  430. </Select>
  431. <Select placeholder="选择需求状态" style={{ width: 120 }}
  432. value={this.state.status}
  433. onChange={(e) => { this.setState({ status: e }) }}>
  434. <Select.Option value="0" >进行中</Select.Option>
  435. <Select.Option value="1" >未解决</Select.Option>
  436. <Select.Option value="2" >已解决</Select.Option>
  437. </Select>
  438. <Select placeholder="选择审核状态" style={{ width: 160 }}
  439. value={this.state.auditStatus}
  440. onChange={(e) => { this.setState({ auditStatus: e }) }}>
  441. <Select.Option value="0" >未提交审核(草稿)</Select.Option>
  442. <Select.Option value="1" >提交审核</Select.Option>
  443. <Select.Option value="2" >审核中</Select.Option>
  444. <Select.Option value="3" >审核通过</Select.Option>
  445. <Select.Option value="4" >审核未通过</Select.Option>
  446. </Select>
  447. <Button type="primary" onClick={this.search}>搜索</Button>
  448. <Button onClick={this.reset}>重置</Button>
  449. <Button style={{ background: "#3fcf9e", border: "none", color: "#fff" }}
  450. disabled={!hasSelected}
  451. onClick={this.delectRow}>删除<Icon type="minus" /></Button>
  452. <span>更多搜索<Switch defaultChecked={false} onChange={this.searchSwitch} /></span>
  453. <div className="search-more" style={this.state.searchMore ? { display: 'none' } : {}}>
  454. <Select placeholder="选择是否发布" style={{ width: 120 }}
  455. value={this.state.releaseStatus}
  456. onChange={(e) => { this.setState({ releaseStatus: e }) }}>
  457. <Select.Option value="0" >未发布</Select.Option>
  458. <Select.Option value="1" >已发布</Select.Option>
  459. </Select>
  460. <span style={{ marginLeft: '10px' }}>有效期限 : </span>
  461. <RangePicker
  462. value={[this.state.validityPeriodDate[0] ? moment(this.state.validityPeriodDate[0]) : null,
  463. this.state.validityPeriodDate[1] ? moment(this.state.validityPeriodDate[1]) : null]}
  464. onChange={(data, dataString) => { this.setState({ validityPeriodDate: dataString }); }} />
  465. <span style={{ marginLeft: '10px' }}>发布时间 : </span>
  466. <RangePicker
  467. value={[this.state.releaseDate[0] ? moment(this.state.releaseDate[0]) : null,
  468. this.state.releaseDate[1] ? moment(this.state.releaseDate[1]) : null]}
  469. onChange={(data, dataString) => { this.setState({ releaseDate: dataString }); }} />
  470. </div>
  471. </div>
  472. <div className="patent-table">
  473. <Spin spinning={this.state.loading}>
  474. <Table columns={this.state.columns}
  475. dataSource={this.state.dataSource}
  476. rowSelection={rowSelection}
  477. pagination={this.state.pagination}
  478. onRowClick={this.tableRowClick} />
  479. </Spin>
  480. </div>
  481. <TechDemandDesc
  482. data={this.state.RowData}
  483. detailApiUrl={this.props['data-detailApiUrl']}
  484. companyOption={this.state.companyOption}
  485. userOption={this.state.userOption}
  486. demandTypeOption={this.state.demandTypeOption}
  487. showDesc={this.state.showDesc}
  488. closeDesc={this.closeDesc} />
  489. </div >
  490. );
  491. }
  492. });
  493. export default DemandList;