systemMessage.jsx 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. import React from 'react';
  2. import { Icon, Button, Input, Select, Spin, Table, message, DatePicker } from 'antd';
  3. import $ from 'jquery/src/ajax';
  4. import moment from 'moment';
  5. import NewDesc from '@/administration/messagePush/messageIn/messageDesc';
  6. import '@/account/demand/techDemand.less';
  7. import '@/administration/news/news.less';
  8. const DemandList = React.createClass({
  9. loadData(pageNo) {
  10. this.state.data = [];
  11. this.setState({
  12. selectedRowKeys:[],
  13. page:pageNo,
  14. loading: true
  15. });
  16. $.ajax({
  17. method: "get",
  18. dataType: "json",
  19. crossDomain: false,
  20. url: globalConfig.context + "/api/admin/message/getMessageList",
  21. data: {
  22. pageNo: pageNo || 1,
  23. pageSize: this.state.pagination.pageSize,
  24. title: this.state.nameSearch, //需求名称
  25. subject:0,
  26. isSend:this.state.auditStatusSearch,
  27. sendStartTime: this.state.releaseDate[0],
  28. sendEndTime: this.state.releaseDate[1],
  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. isSend:thisdata.isSend,
  44. admin:thisdata.admin?thisdata.admin:'管理员',
  45. body: thisdata.body,
  46. createTime:thisdata.createTime?(new Date(thisdata.createTime)).toLocaleString():'',
  47. releaseDate:thisdata.sendTime?(new Date(thisdata.sendTime)).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. },
  94. {
  95. title: '消息内容',
  96. dataIndex: 'body',
  97. key: 'body',
  98. render: text => { return text&&text.length>16?text.substr(0,16)+'...':text}
  99. },
  100. {
  101. title: '创建人',
  102. dataIndex: 'admin',
  103. key: 'admin'
  104. },
  105. {
  106. title: '创建时间',
  107. dataIndex: 'createTime',
  108. key: 'createTime'
  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.isSend?<Button type="primary" style={{ background: "#3fcf9e", border: "none", color: "#fff" }} onClick={(e)=>{e.stopPropagation();this.submission(recard)}}>推送</Button>:''}
  122. {!recard.isSend?<Button type="danger" style={{ margin:10 }} onClick={(e)=>{e.stopPropagation(),this.del(recard)}}>删除</Button>:''}
  123. </div>
  124. }
  125. }
  126. ],
  127. dataSource: [],
  128. searchTime: [,]
  129. };
  130. },
  131. //发布
  132. submission(record){
  133. this.setState({
  134. loading:true
  135. });
  136. $.ajax({
  137. method: "get",
  138. dataType: "json",
  139. crossDomain: false,
  140. url: globalConfig.context + "/api/admin/message/sendMessage",
  141. data: {
  142. messageId:record.id,
  143. }
  144. }).done(function (data) {
  145. if (!data.error.length) {
  146. message.success('推送成功.');
  147. this.setState({
  148. loading: false,
  149. });
  150. this.loadData(this.state.page)
  151. } else {
  152. message.warning(data.error[0].message);
  153. };
  154. }.bind(this));
  155. },
  156. componentWillMount() {
  157. this.loadData();
  158. },
  159. tableRowClick(record, index) {
  160. this.state.RowData = record;
  161. this.setState({
  162. showDesc: true
  163. });
  164. },
  165. del(recard) {
  166. this.setState({
  167. loading:true
  168. })
  169. $.ajax({
  170. method: "POST",
  171. dataType: "json",
  172. crossDomain: false,
  173. url: globalConfig.context + "/api/admin/message/updMessageById",
  174. data: {
  175. id: recard.id,
  176. title: recard.title,
  177. subject:0, //消息类别 0-系统消息
  178. isDraft:1, //是否草稿 0-否 1-是
  179. deleteSign:1, //删除标识 0-否 ,1-是
  180. isSend:0, //是否发送0-否 1-是
  181. body:recard.body
  182. }
  183. }).done(function (data) {
  184. if (!data.error.length) {
  185. message.success('删除成功!');
  186. this.setState({
  187. loading: false
  188. });
  189. if(this.state.pagination.total%10==1){
  190. this.loadData((this.state.page)-1);
  191. }else{
  192. this.loadData(this.state.page);
  193. }
  194. } else {
  195. message.warning(data.error[0].message);
  196. };
  197. }.bind(this));
  198. },
  199. addClick() {
  200. this.state.RowData = {};
  201. this.setState({
  202. showDesc: true
  203. });
  204. },
  205. closeDesc(e, s) {
  206. this.state.showDesc = e;
  207. if (s) {
  208. this.loadData(this.state.page);
  209. };
  210. },
  211. search() {
  212. this.loadData();
  213. },
  214. reset() {
  215. this.state.nameSearch = '';
  216. this.state.releaseDate = [];
  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>APP站内消息推送</span>
  241. <div style={{float:'right'}}>
  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. <Select.Option value="0" >草稿</Select.Option>
  253. <Select.Option value="1" >已推送</Select.Option>
  254. </Select>
  255. <span>推送时间 : </span>
  256. <RangePicker
  257. style={{marginRight:10}}
  258. value={[this.state.releaseDate[0] ? moment(this.state.releaseDate[0]) : null,
  259. this.state.releaseDate[1] ? moment(this.state.releaseDate[1]) : null]}
  260. onChange={(data, dataString) => { this.setState({ releaseDate: dataString }); }} />
  261. <Button type="primary" onClick={this.search}>搜索</Button>
  262. <Button onClick={this.reset}>重置</Button>
  263. </div>
  264. <div className="patent-table">
  265. <Spin spinning={this.state.loading}>
  266. <Table columns={this.state.columns}
  267. dataSource={this.state.dataSource}
  268. rowSelection={rowSelection}
  269. pagination={this.state.pagination}
  270. onRowClick={this.tableRowClick} />
  271. </Spin>
  272. </div>
  273. <NewDesc
  274. data={this.state.RowData}
  275. showDesc={this.state.showDesc}
  276. closeDesc={this.closeDesc} />
  277. </div >
  278. );
  279. }
  280. });
  281. export default DemandList;