newsList.jsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  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/news/newDesc';
  7. import '@/administration/news/news.less';
  8. import { } from '@/dataDic.js';
  9. import {getReleaseStateList, } from '@/tools.js';
  10. const DemandList = 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/news/list",
  22. data: {
  23. pageNo: pageNo || 1,
  24. pageSize: this.state.pagination.pageSize,
  25. title: this.state.nameSearch, //需求名称
  26. startCreateTime: this.state.releaseDate[0],
  27. endCreateTime: 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.pagination.current = data.data.pageNo;
  51. this.state.pagination.total = data.data.totalCount;
  52. if(data.data&&data.data.list&&!data.data.list.length){
  53. this.state.pagination.current=0
  54. this.state.pagination.total=0
  55. };
  56. this.setState({
  57. dataSource: theArr,
  58. pagination: this.state.pagination
  59. });
  60. }.bind(this),
  61. }).always(function () {
  62. this.setState({
  63. loading: false
  64. });
  65. }.bind(this));
  66. },
  67. getInitialState() {
  68. return {
  69. searchMore: true,
  70. validityPeriodDate: [],
  71. releaseDate: [],
  72. selectedRowKeys: [],
  73. selectedRows: [],
  74. loading: false,
  75. pagination: {
  76. defaultCurrent: 1,
  77. defaultPageSize: 10,
  78. showQuickJumper: true,
  79. pageSize: 10,
  80. onChange: function (page) {
  81. this.loadData(page);
  82. }.bind(this),
  83. showTotal: function (total) {
  84. return '共' + total + '条数据';
  85. }
  86. },
  87. columns: [
  88. {
  89. title: '新闻名称',
  90. dataIndex: 'title',
  91. key: 'title',
  92. }, {
  93. title: '创建人',
  94. dataIndex: 'author',
  95. key: 'author',
  96. render:text=>{return <span>管理员</span>}
  97. },
  98. {
  99. title: '发布状态',
  100. dataIndex: 'auditStatus',
  101. key: 'auditStatus',
  102. render: text => { return getReleaseStateList(text) }
  103. },
  104. {
  105. title: '来源',
  106. dataIndex: 'source',
  107. key: 'source'
  108. },
  109. {
  110. title: '发布时间',
  111. dataIndex: 'releaseDate',
  112. key: 'releaseDate'
  113. },
  114. {
  115. title: '操作',
  116. dataIndex: 'caozuo',
  117. key: 'caozuo',
  118. render:(text,recard) => {
  119. return <div className="btnRight">
  120. {recard.auditStatus!='1'&&recard.auditStatus!='2'&&<Button type="primary" style={{ background: "#3fcf9e", border: "none", color: "#fff" }} onClick={(e)=>{e.stopPropagation(),this.submission(recard)}}>发布</Button>}
  121. <Button type="danger" onClick={(e)=>{e.stopPropagation();this.delectRow(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/news/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/news/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/news/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(recard) {
  222. this.setState({
  223. loading:true
  224. })
  225. $.ajax({
  226. method: "POST",
  227. dataType: "json",
  228. crossDomain: false,
  229. url: globalConfig.context + "/api/admin/news/deleteById",
  230. data: {
  231. id: recard.id
  232. }
  233. }).done(function (data) {
  234. if (!data.error.length) {
  235. message.success('删除成功!');
  236. this.setState({
  237. loading: false
  238. });
  239. this.loadData(this.state.page);
  240. } else {
  241. message.warning(data.error[0].message);
  242. };
  243. }.bind(this));
  244. },
  245. addClick() {
  246. this.state.RowData = {};
  247. this.setState({
  248. showDesc: true
  249. });
  250. },
  251. closeDesc(e, s) {
  252. this.state.showDesc = e;
  253. if (s) {
  254. this.loadData(this.state.page);
  255. };
  256. },
  257. search() {
  258. this.loadData();
  259. },
  260. reset() {
  261. this.state.nameSearch = '';
  262. this.state.releaseDate = [];
  263. this.state.dataCategorySearch = undefined;
  264. this.state.auditStatusSearch = undefined;
  265. this.loadData();
  266. },
  267. searchSwitch() {
  268. this.setState({
  269. searchMore: !this.state.searchMore
  270. });
  271. },
  272. render() {
  273. const rowSelection = {
  274. selectedRowKeys: this.state.selectedRowKeys,
  275. onChange: (selectedRowKeys, selectedRows) => {
  276. this.setState({
  277. selectedRows: selectedRows.slice(-1),
  278. selectedRowKeys: selectedRowKeys.slice(-1)
  279. });
  280. }
  281. };
  282. const { RangePicker } = DatePicker;
  283. return (
  284. <div className="user-content" >
  285. <div className="content-title">
  286. <span>新闻管理</span>
  287. <div className="patent-addNew">
  288. <Button type="primary" onClick={this.addClick}>发布新闻<Icon type="plus" /></Button>
  289. </div>
  290. </div>
  291. <div className="user-search">
  292. <Input placeholder="新闻名称"
  293. value={this.state.nameSearch}
  294. onChange={(e) => { this.setState({ nameSearch: e.target.value }); }} />
  295. <Select placeholder="发布状态" style={{ width: 120 }}
  296. value={this.state.auditStatusSearch}
  297. onChange={(e) => { this.setState({ auditStatusSearch: e }) }}>
  298. <Select.Option value="0" >草稿</Select.Option>
  299. <Select.Option value="1" >发布审核</Select.Option>
  300. <Select.Option value="2" >已发布</Select.Option>
  301. <Select.Option value="3" >发布失败</Select.Option>
  302. <Select.Option value="4" >已撤销</Select.Option>
  303. </Select>
  304. <Button type="primary" onClick={this.search}>搜索</Button>
  305. <Button onClick={this.reset}>重置</Button>
  306. <span>更多搜索<Switch defaultChecked={false} onChange={this.searchSwitch} /></span>
  307. <div className="search-more" style={this.state.searchMore ? { display: 'none' } : {}}>
  308. <span>发布时间 :</span>
  309. <RangePicker
  310. value={[this.state.releaseDate[0] ? moment(this.state.releaseDate[0]) : null,
  311. this.state.releaseDate[1] ? moment(this.state.releaseDate[1]) : null]}
  312. onChange={(data, dataString) => { this.setState({ releaseDate: dataString }); }} />
  313. </div>
  314. </div>
  315. <div className="patent-table">
  316. <Spin spinning={this.state.loading}>
  317. <Table columns={this.state.columns}
  318. dataSource={this.state.dataSource}
  319. rowSelection={rowSelection}
  320. pagination={this.state.pagination}
  321. onRowClick={this.tableRowClick} />
  322. </Spin>
  323. </div>
  324. <NewDesc
  325. data={this.state.RowData}
  326. demandTypeOption={this.state.demandTypeOption}
  327. showDesc={this.state.showDesc}
  328. closeDesc={this.closeDesc} />
  329. </div >
  330. );
  331. }
  332. });
  333. export default DemandList;