proList.jsx 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  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/product/proDesc';
  7. import '@/administration/news/news.less';
  8. import {releaseStateList,specialType,productType } from '@/dataDic.js';
  9. import {getReleaseStateList,getSpecialType,getProductType } 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 getSpecialType(text)}
  99. },
  100. {
  101. title: '产品类型',
  102. dataIndex: 'author1',
  103. key: 'author1',
  104. render:text=>{return getProductType(text)}
  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/news/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/news/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/news/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(recard) {
  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/news/deleteById",
  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.nameSearch = '';
  275. this.state.typeSearch=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.auditStatusSearch}
  312. onChange={(e) => { this.setState({ auditStatusSearch: e }) }}>
  313. {
  314. releaseStateList.map(item=>{
  315. return <Select.Option value={item.value} >{item.key}</Select.Option>
  316. })
  317. }
  318. </Select>
  319. <Select placeholder="产品专栏" style={{ width: 120 }}
  320. value={this.state.typeSearch}
  321. onChange={(e) => { this.setState({ typeSearch: e }) }}>
  322. {
  323. specialType.map(item=>{
  324. return <Select.Option value={item.value} >{item.key}</Select.Option>
  325. })
  326. }
  327. </Select>
  328. <Select placeholder="产品类型" style={{ width: 120 }}
  329. value={this.state.typeSearch}
  330. onChange={(e) => { this.setState({ typeSearch: e }) }}>
  331. {
  332. productType.map(item=>{
  333. return <Select.Option value={item.value} >{item.key}</Select.Option>
  334. })
  335. }
  336. </Select>
  337. <Button type="primary" onClick={this.search}>搜索</Button>
  338. <Button onClick={this.reset}>重置</Button>
  339. <Button type="danger" disabled={!hasSelect} onClick={(e)=>{this.delectRow()}}>删除</Button>
  340. <span>更多搜索<Switch defaultChecked={false} onChange={this.searchSwitch} /></span>
  341. <div className="search-more" style={this.state.searchMore ? { display: 'none' } : {}}>
  342. <span>发布时间 :</span>
  343. <RangePicker
  344. value={[this.state.releaseDate[0] ? moment(this.state.releaseDate[0]) : null,
  345. this.state.releaseDate[1] ? moment(this.state.releaseDate[1]) : null]}
  346. onChange={(data, dataString) => { this.setState({ releaseDate: dataString }); }} />
  347. </div>
  348. </div>
  349. <div className="patent-table">
  350. <Spin spinning={this.state.loading}>
  351. <Table columns={this.state.columns}
  352. dataSource={this.state.dataSource}
  353. rowSelection={rowSelection}
  354. pagination={this.state.pagination}
  355. onRowClick={this.tableRowClick} />
  356. </Spin>
  357. </div>
  358. <NewDesc
  359. data={this.state.RowData}
  360. showDesc={this.state.showDesc}
  361. closeDesc={this.closeDesc} />
  362. </div >
  363. );
  364. }
  365. });
  366. export default DemandList;