newsList.jsx 13 KB

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