policyList.jsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. import React from 'react';
  2. import { Icon, Button, Input, Select, Spin, Table, Switch, message, DatePicker } from 'antd';
  3. import $ from 'jquery/src/ajax';
  4. import moment from 'moment';
  5. import '@/account/demand/techDemand.less';
  6. import NewDesc from '@/administration/policy/policyDesc';
  7. import '@/administration/news/news.less';
  8. import { } from '@/dataDic.js';
  9. import { getReleaseStateList, } from '@/tools.js';
  10. const PolicyList = React.createClass({
  11. loadData(pageNo) {
  12. this.state.data = [];
  13. this.setState({
  14. page: pageNo,
  15. loading: true
  16. });
  17. $.ajax({
  18. method: "get",
  19. dataType: "json",
  20. crossDomain: false,
  21. url: globalConfig.context + "/api/admin/policy/list",
  22. data: {
  23. pageNo: pageNo || 1,
  24. pageSize: this.state.pagination.pageSize,
  25. title: this.state.nameSearch, //政策标题
  26. type: this.state.type,
  27. startReleaseDate: this.state.releaseDate[0],
  28. endReleaseDate: this.state.releaseDate[1],
  29. auditStatus: this.state.auditStatusSearch,
  30. },
  31. success: function (data) {
  32. let theArr = [];
  33. if (!data.data || !data.data.list) {
  34. if (data.error && data.error.length) {
  35. message.warning(data.error[0].message);
  36. };
  37. } else {
  38. for (let i = 0; i < data.data.list.length; i++) {
  39. let thisdata = data.data.list[i];
  40. theArr.push({
  41. key: i,
  42. id: thisdata.id,
  43. title: thisdata.title,
  44. type: thisdata.type,
  45. author: thisdata.author,
  46. source: thisdata.source,
  47. auditStatus: thisdata.auditStatus, //审核状态
  48. releaseDate: thisdata.releaseDate ? (new Date(thisdata.releaseDate)).toLocaleString() : ''
  49. });
  50. };
  51. };
  52. this.state.selectedRowKeys = [];
  53. this.state.pagination.current = data.data.pageNo;
  54. this.state.pagination.total = data.data.totalCount;
  55. if (data.data && data.data.list && !data.data.list.length) {
  56. this.state.pagination.current = 0
  57. this.state.pagination.total = 0
  58. };
  59. this.setState({
  60. dataSource: theArr,
  61. pagination: this.state.pagination
  62. });
  63. }.bind(this),
  64. }).always(function () {
  65. this.setState({
  66. loading: false
  67. });
  68. }.bind(this));
  69. },
  70. getInitialState() {
  71. return {
  72. searchMore: true,
  73. validityPeriodDate: [],
  74. releaseDate: [],
  75. selectedRowKeys: [],
  76. selectedRows: [],
  77. loading: false,
  78. pagination: {
  79. defaultCurrent: 1,
  80. defaultPageSize: 10,
  81. showQuickJumper: true,
  82. pageSize: 10,
  83. onChange: function (page) {
  84. this.loadData(page);
  85. }.bind(this),
  86. showTotal: function (total) {
  87. return '共' + total + '条数据';
  88. }
  89. },
  90. columns: [
  91. {
  92. title: '政策名称',
  93. dataIndex: 'title',
  94. key: 'title',
  95. }, {
  96. title: '政策类型',
  97. dataIndex: 'type',
  98. key: 'type',
  99. render: text => { return <span>{["政策", "咨询", "观点", "百科"][text]}</span> }
  100. }, {
  101. title: '创建人',
  102. dataIndex: 'author',
  103. key: 'author',
  104. render: text => { return <span>管理员</span> }
  105. },
  106. {
  107. title: '发布状态',
  108. dataIndex: 'auditStatus',
  109. key: 'auditStatus',
  110. render: text => { return getReleaseStateList(text) }
  111. },
  112. {
  113. title: '来源',
  114. dataIndex: 'source',
  115. key: 'source'
  116. },
  117. {
  118. title: '发布时间',
  119. dataIndex: 'releaseDate',
  120. key: 'releaseDate'
  121. },
  122. {
  123. title: '操作',
  124. dataIndex: 'caozuo',
  125. key: 'caozuo',
  126. render: (text, recard) => {
  127. return <div className="btnRight">
  128. {recard.auditStatus != '1' && recard.auditStatus != '2' && <Button type="primary" style={{ background: "#3fcf9e", border: "none", color: "#fff" }} onClick={(e) => { e.stopPropagation(), this.submission(recard) }}>发布</Button>}
  129. {recard.auditStatus != '1' && recard.auditStatus == '2' && <Button type="success" onClick={(e) => { e.stopPropagation(), this.updateFun(recard) }}>刷新发布</Button>}
  130. {recard.auditStatus != '1' && recard.auditStatus == '2' && <Button type="danger" onClick={(e) => { e.stopPropagation(), this.revokeFun(recard) }}>撤销发布</Button>}
  131. </div>
  132. }
  133. }
  134. ],
  135. dataSource: [],
  136. searchTime: [,]
  137. };
  138. },
  139. //发布
  140. submission(record) {
  141. this.setState({
  142. showDesc: false,
  143. loading: true
  144. });
  145. $.ajax({
  146. method: "POST",
  147. dataType: "json",
  148. crossDomain: false,
  149. url: globalConfig.context + "/api/admin/policy/updateStatus",
  150. data: {
  151. id: record.id,
  152. auditStatus: 2
  153. }
  154. }).done(function (data) {
  155. if (!data.error.length) {
  156. message.success('发布成功.');
  157. this.setState({
  158. loading: false,
  159. });
  160. this.loadData(this.state.page)
  161. } else {
  162. message.warning(data.error[0].message);
  163. };
  164. }.bind(this));
  165. },
  166. //刷新发布
  167. updateFun(recard) {
  168. this.setState({
  169. loading: true
  170. })
  171. $.ajax({
  172. method: "POST",
  173. dataType: "json",
  174. crossDomain: false,
  175. url: globalConfig.context + '/api/admin/policy/updateStatus',
  176. data: {
  177. id: recard.id,
  178. auditStatus: recard.auditStatus,
  179. refresh: 1
  180. }
  181. }).done(function (data) {
  182. if (!data.error.length) {
  183. message.success('刷新成功!');
  184. this.setState({
  185. loading: false,
  186. });
  187. } else {
  188. message.warning(data.error[0].message);
  189. };
  190. this.loadData(this.state.page);
  191. }.bind(this));
  192. },
  193. //撤销发布
  194. revokeFun(recard) {
  195. this.setState({
  196. loading: true
  197. })
  198. $.ajax({
  199. method: "POST",
  200. dataType: "json",
  201. crossDomain: false,
  202. url: globalConfig.context + '/api/admin/policy/updateStatus',
  203. data: {
  204. id: recard.id,
  205. auditStatus: 4,
  206. }
  207. }).done(function (data) {
  208. if (!data.error.length) {
  209. message.success('撤销成功!');
  210. this.setState({
  211. loading: false,
  212. });
  213. this.loadData(this.state.page);
  214. } else {
  215. message.warning(data.error[0].message);
  216. };
  217. }.bind(this));
  218. },
  219. componentWillMount() {
  220. this.loadData();
  221. },
  222. tableRowClick(record, index) {
  223. this.state.RowData = record;
  224. this.setState({
  225. showDesc: true
  226. });
  227. },
  228. delectRow() {
  229. this.setState({
  230. loading: true
  231. })
  232. let deletedIds = [];
  233. let rowItem = this.state.selectedRowKeys[0];
  234. let data = this.state.dataSource || [];
  235. if (data.length) {
  236. deletedIds.push(data[rowItem].id);
  237. }
  238. $.ajax({
  239. method: "POST",
  240. dataType: "json",
  241. crossDomain: false,
  242. url: globalConfig.context + "/api/admin/policy/delete",
  243. data: {
  244. id: deletedIds[0]
  245. }
  246. }).done(function (data) {
  247. if (!data.error.length) {
  248. message.success('删除成功!');
  249. this.setState({
  250. loading: false
  251. });
  252. this.loadData(this.state.page);
  253. } else {
  254. message.warning(data.error[0].message);
  255. };
  256. }.bind(this));
  257. },
  258. addClick() {
  259. this.state.RowData = {};
  260. this.setState({
  261. showDesc: true
  262. });
  263. },
  264. closeDesc(e, s) {
  265. this.state.showDesc = e;
  266. if (s) {
  267. this.loadData(this.state.page);
  268. };
  269. },
  270. search() {
  271. this.loadData();
  272. },
  273. reset() {
  274. this.state.type = undefined;
  275. this.state.nameSearch = undefined;
  276. this.state.releaseDate = [];
  277. this.state.dataCategorySearch = undefined;
  278. this.state.auditStatusSearch = undefined;
  279. this.loadData();
  280. },
  281. searchSwitch() {
  282. this.setState({
  283. searchMore: !this.state.searchMore
  284. });
  285. },
  286. render() {
  287. const rowSelection = {
  288. selectedRowKeys: this.state.selectedRowKeys,
  289. onChange: (selectedRowKeys, selectedRows) => {
  290. this.setState({
  291. selectedRows: selectedRows.slice(-1),
  292. selectedRowKeys: selectedRowKeys.slice(-1)
  293. });
  294. }
  295. };
  296. const { RangePicker } = DatePicker;
  297. const hasSelect = this.state.selectedRowKeys.length;
  298. return (
  299. <div className="user-content" >
  300. <div className="content-title">
  301. <span>政策管理</span>
  302. <div className="patent-addNew">
  303. <Button type="primary" onClick={this.addClick}>发布政策<Icon type="plus" /></Button>
  304. </div>
  305. </div>
  306. <div className="user-search">
  307. <Input placeholder="政策名称"
  308. value={this.state.nameSearch}
  309. onChange={(e) => { this.setState({ nameSearch: e.target.value }); }} />
  310. <Select placeholder="政策类型" style={{ width: 120 }}
  311. value={this.state.type}
  312. onChange={(e) => { this.setState({ type: e }) }}>
  313. <Select.Option value={0} >政策</Select.Option>
  314. <Select.Option value={1} >咨询</Select.Option>
  315. <Select.Option value={2} >观点</Select.Option>
  316. <Select.Option value={3} >百科</Select.Option>
  317. </Select>
  318. <Select placeholder="发布状态" style={{ width: 120 }}
  319. value={this.state.auditStatusSearch}
  320. onChange={(e) => { this.setState({ auditStatusSearch: e }) }}>
  321. <Select.Option value="0" >草稿</Select.Option>
  322. <Select.Option value="2" >已发布</Select.Option>
  323. </Select>
  324. <Button type="primary" onClick={this.search}>搜索</Button>
  325. <Button onClick={this.reset}>重置</Button>
  326. <Button type="danger" disabled={!hasSelect} onClick={(e) => { this.delectRow() }}>删除</Button>
  327. <span>更多搜索<Switch defaultChecked={false} onChange={this.searchSwitch} /></span>
  328. <div className="search-more" style={this.state.searchMore ? { display: 'none' } : {}}>
  329. <span>发布时间 :</span>
  330. <RangePicker
  331. value={[this.state.releaseDate[0] ? moment(this.state.releaseDate[0]) : null,
  332. this.state.releaseDate[1] ? moment(this.state.releaseDate[1]) : null]}
  333. onChange={(data, dataString) => { this.setState({ releaseDate: dataString }); }} />
  334. </div>
  335. </div>
  336. <div className="patent-table">
  337. <Spin spinning={this.state.loading}>
  338. <Table columns={this.state.columns}
  339. dataSource={this.state.dataSource}
  340. rowSelection={rowSelection}
  341. pagination={this.state.pagination}
  342. onRowClick={this.tableRowClick} />
  343. </Spin>
  344. </div>
  345. <NewDesc
  346. data={this.state.RowData}
  347. showDesc={this.state.showDesc}
  348. closeDesc={this.closeDesc} />
  349. </div >
  350. );
  351. }
  352. });
  353. export default PolicyList;