policyList.jsx 12 KB

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