techDemand.jsx 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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 { demandTypeList } from '../../dataDic.js';
  9. import { getDemandType } from '../../tools.js';
  10. const DemandList = React.createClass({
  11. loadData(pageNo) {
  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 + "/api/user/demand/list",
  21. data: {
  22. pageNo: pageNo || 1,
  23. pageSize: this.state.pagination.pageSize,
  24. serialNumber: this.state.serialNumber,
  25. name: this.state.name,
  26. keyword: this.state.keyword,
  27. demandType: this.state.demandType ? Number(this.state.demandType) : undefined,
  28. status: this.state.status ? Number(this.state.status) : undefined,
  29. releaseStatus: this.state.releaseStatus ? Number(this.state.releaseStatus) : undefined,
  30. validityPeriodStartDate: this.state.validityPeriodDate[0],
  31. validityPeriodEndDate: this.state.validityPeriodDate[1],
  32. releaseDateStartDate: this.state.releaseDate[0],
  33. releaseDateEndDate: this.state.releaseDate[1],
  34. auditStatus: this.state.auditStatus
  35. },
  36. success: function (data) {
  37. let theArr = [];
  38. if (!data.data || !data.data.list) {
  39. if (data.error && data.error.length) {
  40. message.warning(data.error[0].message);
  41. };
  42. } else {
  43. for (let i = 0; i < data.data.list.length; i++) {
  44. let thisdata = data.data.list[i];
  45. theArr.push({
  46. key: i,
  47. id: thisdata.id,
  48. serialNumber: thisdata.serialNumber,
  49. dataCategory: thisdata.dataCategory,
  50. name: thisdata.name,
  51. keyword: thisdata.keyword,
  52. releaseDate: thisdata.releaseDate,
  53. demandType: thisdata.demandType,
  54. validityPeriod: thisdata.validityPeriod,
  55. status: thisdata.status,
  56. releaseStatus: thisdata.releaseStatus,
  57. employerId: thisdata.employerId,
  58. releaseDateFormattedDate: thisdata.releaseDateFormattedDate,
  59. validityPeriodFormattedDate: thisdata.validityPeriodFormattedDate,
  60. auditStatus: thisdata.auditStatus
  61. });
  62. };
  63. }
  64. this.state.pagination.current = data.data.pageNo;
  65. this.state.pagination.total = data.data.totalCount;
  66. this.setState({
  67. dataSource: theArr,
  68. pagination: this.state.pagination
  69. });
  70. }.bind(this),
  71. }).always(function () {
  72. this.setState({
  73. loading: false
  74. });
  75. }.bind(this));
  76. },
  77. getInitialState() {
  78. return {
  79. searchMore: true,
  80. validityPeriodDate: [],
  81. releaseDate: [],
  82. selectedRowKeys: [],
  83. selectedRows: [],
  84. loading: false,
  85. pagination: {
  86. defaultCurrent: 1,
  87. defaultPageSize: 10,
  88. showQuickJumper: true,
  89. pageSize: 10,
  90. onChange: function (page) {
  91. this.loadData(page);
  92. }.bind(this),
  93. showTotal: function (total) {
  94. return '共' + total + '条数据';
  95. }
  96. },
  97. columns: [
  98. {
  99. title: '编号',
  100. dataIndex: 'serialNumber',
  101. key: 'serialNumber',
  102. }, {
  103. title: '需求名称',
  104. dataIndex: 'name',
  105. key: 'name',
  106. }, {
  107. title: '关键字',
  108. dataIndex: 'keyword',
  109. key: 'keyword',
  110. }, {
  111. title: '需求类型',
  112. dataIndex: 'demandType',
  113. key: 'demandType',
  114. render: text => { return getDemandType(text); }
  115. }, {
  116. title: '审核状态',
  117. dataIndex: 'auditStatus',
  118. key: 'auditStatus',
  119. render: text => {
  120. switch (text) {
  121. case "0":
  122. return <span>未提交审核(草稿)</span>;
  123. case "1":
  124. return <span>提交审核</span>;
  125. case "2":
  126. return <span>审核中</span>;
  127. case "3":
  128. return <span>审核通过</span>;
  129. case "4":
  130. return <span>审核未通过</span>;
  131. }
  132. }
  133. }, {
  134. title: '需求状态',
  135. dataIndex: 'status',
  136. key: 'status',
  137. render: text => {
  138. switch (text) {
  139. case "0":
  140. return <span>未解决</span>;
  141. case "1":
  142. return <span>已解决</span>;
  143. }
  144. }
  145. }, {
  146. title: '有效期限',
  147. dataIndex: 'validityPeriodFormattedDate',
  148. key: 'validityPeriodFormattedDate',
  149. }, {
  150. title: '发布时间',
  151. dataIndex: 'releaseDateFormattedDate',
  152. key: 'releaseDateFormattedDate',
  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. });
  174. },
  175. delectRow() {
  176. let deletedIds = [];
  177. for (let idx = 0; idx < this.state.selectedRows.length; idx++) {
  178. let rowItem = this.state.selectedRows[idx];
  179. if (rowItem.id) {
  180. deletedIds.push(rowItem.id)
  181. };
  182. };
  183. this.setState({
  184. selectedRowKeys: [],
  185. loading: deletedIds.length > 0
  186. });
  187. $.ajax({
  188. method: "POST",
  189. dataType: "json",
  190. crossDomain: false,
  191. url: globalConfig.context + "/api/user/demand/delete",
  192. data: {
  193. ids: deletedIds
  194. }
  195. }).done(function (data) {
  196. if (!data.error.length) {
  197. message.success('删除成功!');
  198. this.setState({
  199. loading: false,
  200. });
  201. } else {
  202. message.warning(data.error[0].message);
  203. };
  204. this.loadData();
  205. }.bind(this));
  206. },
  207. addClick() {
  208. this.state.RowData = {};
  209. this.setState({
  210. showDesc: true
  211. });
  212. },
  213. closeDesc(e, s) {
  214. this.state.showDesc = e;
  215. if (s) {
  216. this.loadData();
  217. };
  218. },
  219. search() {
  220. this.loadData();
  221. },
  222. reset() {
  223. this.state.serialNumber = undefined;
  224. this.state.auditStatus = undefined;
  225. this.state.name = undefined;
  226. this.state.keyword = undefined;
  227. this.state.demandType = undefined;
  228. this.state.username = undefined;
  229. this.state.status = undefined;
  230. this.state.releaseStatus = undefined;
  231. this.state.validityPeriodDate = [];
  232. this.state.releaseDate = [];
  233. this.loadData();
  234. },
  235. searchSwitch() {
  236. this.setState({
  237. searchMore: !this.state.searchMore
  238. });
  239. },
  240. render() {
  241. const rowSelection = {
  242. selectedRowKeys: this.state.selectedRowKeys,
  243. onChange: (selectedRowKeys, selectedRows) => {
  244. this.setState({
  245. selectedRows: selectedRows.slice(-1),
  246. selectedRowKeys: selectedRowKeys.slice(-1)
  247. });
  248. }
  249. };
  250. const hasSelected = this.state.selectedRowKeys.length > 0;
  251. const { RangePicker } = DatePicker;
  252. return (
  253. <div className="user-content" >
  254. <div className="content-title">
  255. <span>科技需求管理</span>
  256. <div className="patent-addNew">
  257. <Button type="primary" onClick={this.addClick}>新增需求<Icon type="plus" /></Button>
  258. </div>
  259. </div>
  260. <div className="user-search">
  261. <Input placeholder="需求编号"
  262. value={this.state.serialNumber}
  263. onChange={(e) => { this.setState({ serialNumber: e.target.value }); }} />
  264. <Input placeholder="需求名称"
  265. value={this.state.name}
  266. onChange={(e) => { this.setState({ name: e.target.value }); }} />
  267. <Input placeholder="关键字"
  268. value={this.state.keyword}
  269. onChange={(e) => { this.setState({ keyword: e.target.value }); }} />
  270. <Select placeholder="选择需求类型"
  271. style={{ width: 120 }}
  272. value={this.state.demandType}
  273. onChange={(e) => { this.setState({ demandType: e }) }}>
  274. {this.state.demandTypeOption}
  275. </Select>
  276. <Select placeholder="选择需求状态" style={{ width: 120 }}
  277. value={this.state.status}
  278. onChange={(e) => { this.setState({ status: e }) }}>
  279. <Select.Option value="0" >未解决</Select.Option>
  280. <Select.Option value="1" >已解决</Select.Option>
  281. </Select>
  282. <Select placeholder="选择审核状态" style={{ width: 160 }}
  283. value={this.state.auditStatus}
  284. onChange={(e) => { this.setState({ auditStatus: e }) }}>
  285. <Select.Option value="0" >未提交审核(草稿)</Select.Option>
  286. <Select.Option value="1" >提交审核</Select.Option>
  287. <Select.Option value="2" >审核中</Select.Option>
  288. <Select.Option value="3" >审核通过</Select.Option>
  289. <Select.Option value="4" >审核未通过</Select.Option>
  290. </Select>
  291. <Button type="primary" onClick={this.search}>搜索</Button>
  292. <Button onClick={this.reset}>重置</Button>
  293. <Button style={{ background: "#3fcf9e", border: "none", color: "#fff" }}
  294. disabled={!hasSelected}
  295. onClick={this.delectRow}>删除<Icon type="minus" /></Button>
  296. <span>更多搜索<Switch defaultChecked={false} onChange={this.searchSwitch} /></span>
  297. <div className="search-more" style={this.state.searchMore ? { display: 'none' } : {}}>
  298. <Select placeholder="选择是否发布" style={{ width: 120 }}
  299. value={this.state.releaseStatus}
  300. onChange={(e) => { this.setState({ releaseStatus: e }) }}>
  301. <Select.Option value="0" >未发布</Select.Option>
  302. <Select.Option value="1" >已发布</Select.Option>
  303. </Select>
  304. <span>有效期限 :</span>
  305. <RangePicker
  306. value={[this.state.validityPeriodDate[0] ? moment(this.state.validityPeriodDate[0]) : null,
  307. this.state.validityPeriodDate[1] ? moment(this.state.validityPeriodDate[1]) : null]}
  308. onChange={(data, dataString) => { this.setState({ validityPeriodDate: dataString }); }} />
  309. <span>发布时间 :</span>
  310. <RangePicker
  311. value={[this.state.releaseDate[0] ? moment(this.state.releaseDate[0]) : null,
  312. this.state.releaseDate[1] ? moment(this.state.releaseDate[1]) : null]}
  313. onChange={(data, dataString) => { this.setState({ releaseDate: dataString }); }} />
  314. </div>
  315. </div>
  316. <div className="patent-table">
  317. <Spin spinning={this.state.loading}>
  318. <Table size="middle" columns={this.state.columns}
  319. dataSource={this.state.dataSource}
  320. rowSelection={rowSelection}
  321. pagination={this.state.pagination}
  322. style={{
  323. cursor: 'pointer',
  324. }}
  325. onRowClick={this.tableRowClick} />
  326. </Spin>
  327. </div>
  328. <TechDemandDesc
  329. data={this.state.RowData}
  330. demandTypeOption={this.state.demandTypeOption}
  331. showDesc={this.state.showDesc}
  332. closeDesc={this.closeDesc} />
  333. </div >
  334. );
  335. }
  336. });
  337. export default DemandList;