msgList.js
9.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
import React,{Component} from 'react';
import './style.less';
import {List, Checkbox, Icon, message, Button , Modal, notification } from 'antd';
import axios from '@src/axios/index';
import Utils from '@src/utils/utils';
import { API_SYS_MSG } from '@src/Api';
import Storage from '@src/utils/localStorage'
import UserManageBar from '@components/Common/WhiteBar/index'
import { connect } from 'react-redux';
import { saveMsgStatus } from '@src/redux/common/action';
/* 消息推送 */
class MsgList extends Component {
state = {
checkedList: [],
indeterminate: false,
checkAll: false,
detailStatus: [],
listData: [],
btnAuth: []
}
// 查询页数和数量配置
params = {
pageNum: 1,
pageSize: 10
}
plainOptions = [];
componentWillMount () {
this.getMsgList()
let btnAuth = Storage.get('btnAuth')
this.setState({btnAuth})
}
// 获取消息list 列表
getMsgList() {
notification.destroy()
this.setState({ loading: true, checkedList: [] })
const userInfo = Storage.get('userInfo')
const _this = this
axios.ajax({
url: API_SYS_MSG.getSysPcMsgDetailListByCondition,
data: {
userId: userInfo ? userInfo.id : '',
pageNum: this.params.pageNum,
pageSize: this.params.pageSize
}
}).then(res => {
// 头部消息状态
this.getMsgStatus()
if(res.records.length > 0) {
const listData = res.records
this.plainOptions= []
for( let i in listData) {
this.plainOptions.push(listData[i].id)
}
this.setState({
listData,
indeterminate: false,
checkedList: [],
checkAll: false,
pagination: Utils.pagination(res, (current) => {
_this.params.pageNum = current;
_this.setState({
checkedList: []
})
_this.getMsgList();
})
})
} else {
const current = this.params.pageNum
if (current > 1) {
this.params.pageNum = current - 1;
this.getMsgList();
return
}
this.setState({
listData: [],
indeterminate: false,
checkedList: [],
checkAll: false,
pagination: Utils.pagination(res, (current) => {
_this.params.pageNum = current;
_this.getMsgList();
})
})
this.plainOptions = []
}
})
}
// 获取头部消息是否点亮红色的标记
getMsgStatus() {
const userInfo = Storage.get('userInfo')
if (userInfo) {
axios.ajax({
url: API_SYS_MSG.getUnReadSysPcMsgDetailCount,
data: {
userId: userInfo.id
}
}).then(res => {
if(res>0){
this.props.saveMsgStatus(true, 'MSGSTATUS')
} else {
this.props.saveMsgStatus(false, 'MSGSTATUS')
}
})
}
}
onChange = (checkedList) =>{
this.setState({
checkedList,
indeterminate: !!checkedList.length && (checkedList.length < this.plainOptions.length),
checkAll: checkedList.length === this.plainOptions.length,
});
}
onCheckAllChange = (e) => {
this.setState({
checkedList: e.target.checked ? this.plainOptions : [],
indeterminate: false,
checkAll: e.target.checked,
});
}
setDetailStatus = (e, item)=> {
const { detailStatus , listData} = this.state;
if (item.readStatus === 1) {
axios.ajax({
url: API_SYS_MSG.updateReadStatus,
data: { ids: item.id }
}).then( res => {
this.getMsgStatus();
})
}
if(detailStatus.indexOf(item.id) === -1) {
detailStatus.push(item.id)
}else {
this.collectList(e, item)
}
const data = listData.map( (items, index) => {
if (items.id === item.id) {
return Object.assign({}, items, {readStatus:2})
} else {
return items
}
})
this.setState({
detailStatus: detailStatus,
listData: data
})
}
collectList = (e, item) => {
const { detailStatus } = this.state;
const index = detailStatus.indexOf(item.id)
if (index > -1) {
detailStatus.splice(index, 1);
}
this.setState({
detailStatus: detailStatus
})
}
setMsgRead = ()=>{
const data = this.state.checkedList
if (data.length === 0) {
message.warn('请选择要设置的消息')
return
}
Modal.confirm({
title: '设置已读',
content: `您要把选中的设为已读?`,
okText: '确定',
cancelText: '取消',
onOk: () => {
let readerStr = ''
for(let item in data) {
readerStr += data[item] + ','
}
axios.ajax({
url: API_SYS_MSG.updateReadStatus,
data: { ids: readerStr.substring(0, readerStr.lastIndexOf(',')) }
}).then(res => {
message.success('操作成功')
this.getMsgList();
})
}
})
}
// 消息列表删除
msgDelete = (e, item)=>{
Modal.confirm({
title: '删除',
content: `您要删除选中的消息?`,
okText: '确定',
cancelText: '取消',
onOk: () => {
if (item) {
axios.ajax({
url: API_SYS_MSG.deleteSysPcMsgDetail,
data: { ids: item.id }
}).then(res => {
message.success('删除成功')
this.getMsgList();
})
} else {
message.warn('请选择要删除的消息')
}
}
})
}
// 选中删除
msgBatchDelete = ()=>{
const data = this.state.checkedList
if (data.length === 0) {
message.warn('请选择要删除的消息')
return
}
Modal.confirm({
title: '删除',
content: `您要删除选中的消息?`,
okText: '确定',
cancelText: '取消',
onOk: () => {
let deleteStr = ''
for(let item in data) {
deleteStr += data[item] + ','
}
axios.ajax({
url: API_SYS_MSG.deleteSysPcMsgDetail,
data: { ids: deleteStr.substring(0, deleteStr.lastIndexOf(',')) }
}).then(res => {
message.success('删除成功')
this.getMsgList();
})
}
})
}
render () {
const IconText = ({ type, text }) => (
<span>
<Icon type={type} style={{ marginRight: 8 }} />
{text}
</span>
);
return (
<div className="msgList">
<UserManageBar title="系统通知" />
<div className = "msgListWrap">
<Checkbox.Group style={{ width: '100%' }} onChange={this.onChange} value={this.state.checkedList}>
<List
itemLayout="vertical"
size="large"
pagination={this.state.pagination}
dataSource={this.state.listData}
renderItem={item => (
<List.Item className = "msgListItem">
<Checkbox value= {item.id} >
</Checkbox>
{/* <List.Item.Meta
title={<a onClick = {(e) => this.setDetailStatus(e, item)}>
{ item.readStatus === 1 ? < i className="circle msgCircle"></i> : ''}
{item.messageTitle}</a>
}
className = "msgTitle"
>
</List.Item.Meta> */}
<div className = "msgTitle">
<a onClick = {(e) => this.setDetailStatus(e, item)}>
{ item.readStatus === 1 ? < i className="circle msgCircle"></i> : ''}
{item.messageTitle}
</a>
</div>
{
this.state.btnAuth.indexOf('msgList-delete') !== -1 ?
<div className = "msgDeleteIcon" onClick = {(e) => this.msgDelete(e, item)} >
<Icon type="delete" theme="outlined" />
</div> : ''
}
{
this.state.detailStatus.indexOf(item.id) !== -1 ?
<div className= "msgContent">
<span> <i className="iconfont icon-xiaoxi"></i> { Utils.formateDateToYMD(item.updateTime) } </span>
<div dangerouslySetInnerHTML = {{ __html: item.messageContent}}></div>
<div className = "msgUpOpt" >
<i className="iconfont icon-jiantou_yemian_xiangxia_o" onClick = {(e) => this.collectList(e, item)}></i>
</div>
</div> : ''
}
</List.Item>
)}
/>
</Checkbox.Group>
</div>
<div className="msgOptWrap">
<Checkbox
indeterminate={this.state.indeterminate}
onChange={this.onCheckAllChange}
checked={this.state.checkAll}
>
全选
</Checkbox>
{
this.state.btnAuth.indexOf('msgList-all-reader') !== -1 ?
<Button className="marginR10" onClick= {()=> this.setMsgRead()}>
标记已读
</Button> : ''
}
{
this.state.btnAuth.indexOf('msgList-all-delete') !== -1 ?
<Button className="marginR10" onClick= {()=> this.msgBatchDelete()}>
删除
</Button> : ''
}
</div>
</div>
);
}
}
export default connect(state => ({
msgStatus: state.msgStatus
}), {
saveMsgStatus,
})(MsgList)