proList.jsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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 {proStatus,productType } from '@/dataDic.js';
  9. import {getProStatus,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/community/list",
  23. data: {
  24. pageNo: pageNo || 1,
  25. pageSize: this.state.pagination.pageSize,
  26. title: this.state.nameSearch, //需求名称
  27. startTime: this.state.releaseDate[0],
  28. endTime: this.state.releaseDate[1],
  29. status:this.state.auditStatusSearch,
  30. category: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. category:thisdata.category,
  46. status: thisdata.status,
  47. releaseTime:thisdata.releaseTime?(new Date(thisdata.releaseTime)).toLocaleString():''
  48. });
  49. };
  50. };
  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. render:text=>{
  94. return text&&text.length>30?text.substr(0,30)+'...':text
  95. }
  96. },
  97. {
  98. title: '产品类型',
  99. dataIndex: 'category',
  100. key: 'category',
  101. render:text=>{return getProductType(text)}
  102. },
  103. {
  104. title: '发布状态',
  105. dataIndex: 'status',
  106. key: 'status',
  107. render: text => { return getProStatus(text) }
  108. },
  109. {
  110. title: '发布时间',
  111. dataIndex: 'releaseTime',
  112. key: 'releaseTime'
  113. },
  114. {
  115. title: '操作',
  116. dataIndex: 'caozuo',
  117. key: 'caozuo',
  118. render:(text,recard) => {
  119. return <div className="btnRight">
  120. {recard.status!='1'&&<Button type="primary" style={{ background: "#3fcf9e", border: "none", color: "#fff" }} onClick={(e)=>{e.stopPropagation(),this.submission(recard,1)}}>发布</Button>}
  121. {recard.status=='1'&&<Button type="danger" onClick={(e)=>{e.stopPropagation(),this.submission(recard,3)}}>撤销发布</Button>}
  122. </div>
  123. }
  124. }
  125. ],
  126. dataSource: [],
  127. searchTime: [,]
  128. };
  129. },
  130. //发布
  131. submission(record,status){
  132. this.setState({
  133. showDesc:false,
  134. loading:true
  135. });
  136. $.ajax({
  137. method: "POST",
  138. dataType: "json",
  139. crossDomain: false,
  140. url: globalConfig.context + "/api/admin/community/updateCommunity",
  141. data: {
  142. id:record.id,
  143. status:status
  144. }
  145. }).done(function (data) {
  146. if (!data.error.length) {
  147. message.success('操作成功.');
  148. this.setState({
  149. loading: false,
  150. });
  151. this.loadData(this.state.page)
  152. } else {
  153. message.warning(data.error[0].message);
  154. };
  155. }.bind(this));
  156. },
  157. componentWillMount() {
  158. this.loadData();
  159. },
  160. tableRowClick(record, index) {
  161. this.state.RowData = record;
  162. this.setState({
  163. showDesc: true
  164. });
  165. },
  166. delectRow(recard) {
  167. this.setState({
  168. loading:true
  169. })
  170. let deletedIds =[];
  171. let rowItem = this.state.selectedRowKeys[0];
  172. let data = this.state.dataSource ||[];
  173. if (data.length) {
  174. deletedIds.push(data[rowItem].id);
  175. }
  176. $.ajax({
  177. method: "POST",
  178. dataType: "json",
  179. crossDomain: false,
  180. url: globalConfig.context + "/api/admin/community/updateCommunity",
  181. data: {
  182. id: deletedIds[0],
  183. status:2
  184. }
  185. }).done(function (data) {
  186. if (!data.error.length) {
  187. message.success('删除成功!');
  188. this.setState({
  189. loading: false
  190. });
  191. this.loadData(this.state.page);
  192. } else {
  193. message.warning(data.error[0].message);
  194. };
  195. }.bind(this));
  196. },
  197. addClick() {
  198. this.state.RowData = {};
  199. this.setState({
  200. showDesc: true
  201. });
  202. },
  203. closeDesc(e, s) {
  204. this.state.showDesc = e;
  205. if (s) {
  206. this.loadData(this.state.page);
  207. };
  208. },
  209. search() {
  210. this.loadData();
  211. },
  212. reset() {
  213. this.state.nameSearch = '';
  214. this.state.typeSearch=undefined;
  215. this.state.releaseDate = [];
  216. this.state.dataCategorySearch = undefined;
  217. this.state.auditStatusSearch = undefined;
  218. this.loadData();
  219. },
  220. searchSwitch() {
  221. this.setState({
  222. searchMore: !this.state.searchMore
  223. });
  224. },
  225. render() {
  226. const rowSelection = {
  227. selectedRowKeys: this.state.selectedRowKeys,
  228. onChange: (selectedRowKeys, selectedRows) => {
  229. this.setState({
  230. selectedRows: selectedRows.slice(-1),
  231. selectedRowKeys: selectedRowKeys.slice(-1)
  232. });
  233. }
  234. };
  235. const { RangePicker } = DatePicker;
  236. const hasSelect = this.state.selectedRowKeys.length;
  237. return (
  238. <div className="user-content" >
  239. <div className="content-title">
  240. <span>产品专栏管理</span>
  241. <div className="patent-addNew">
  242. <Button type="primary" onClick={this.addClick}>发布<Icon type="plus" /></Button>
  243. </div>
  244. </div>
  245. <div className="user-search">
  246. <Input placeholder="专栏名称"
  247. value={this.state.nameSearch}
  248. onChange={(e) => { this.setState({ nameSearch: e.target.value }); }} />
  249. <Select placeholder="发布状态" style={{ width: 120 }}
  250. value={this.state.auditStatusSearch}
  251. onChange={(e) => { this.setState({ auditStatusSearch: e }) }}>
  252. {
  253. proStatus.map(item=>{
  254. return <Select.Option value={item.value} >{item.key}</Select.Option>
  255. })
  256. }
  257. </Select>
  258. <Select placeholder="产品类型" style={{ width: 120 }}
  259. value={this.state.typeSearch}
  260. onChange={(e) => { this.setState({ typeSearch: e }) }}>
  261. {
  262. productType.map(item=>{
  263. return <Select.Option value={item.value} >{item.key}</Select.Option>
  264. })
  265. }
  266. </Select>
  267. <Button type="primary" onClick={this.search}>搜索</Button>
  268. <Button onClick={this.reset}>重置</Button>
  269. <Button type="danger" disabled={!hasSelect} onClick={(e)=>{this.delectRow()}}>删除</Button>
  270. <span>更多搜索<Switch defaultChecked={false} onChange={this.searchSwitch} /></span>
  271. <div className="search-more" style={this.state.searchMore ? { display: 'none' } : {}}>
  272. <span>发布时间 :</span>
  273. <RangePicker
  274. value={[this.state.releaseDate[0] ? moment(this.state.releaseDate[0]) : null,
  275. this.state.releaseDate[1] ? moment(this.state.releaseDate[1]) : null]}
  276. onChange={(data, dataString) => { this.setState({ releaseDate: dataString }); }} />
  277. </div>
  278. </div>
  279. <div className="patent-table">
  280. <Spin spinning={this.state.loading}>
  281. <Table columns={this.state.columns}
  282. dataSource={this.state.dataSource}
  283. rowSelection={rowSelection}
  284. pagination={this.state.pagination}
  285. onRowClick={this.tableRowClick} />
  286. </Spin>
  287. </div>
  288. <NewDesc
  289. data={this.state.RowData}
  290. showDesc={this.state.showDesc}
  291. closeDesc={this.closeDesc} />
  292. </div >
  293. );
  294. }
  295. });
  296. export default DemandList;