|
|
@@ -70,25 +70,54 @@ Page({ |
|
|
|
// 接收服务器的消息事件 |
|
|
|
wx.onSocketMessage(function (res) { |
|
|
|
// 接收到的消息{date,message,type} type类型为 1 是对方的消息 为 0 是自己的消息 |
|
|
|
console.log(res, '消息页----收到新消息') |
|
|
|
|
|
|
|
// _this.initData(); |
|
|
|
let _data = JSON.parse(res.data); |
|
|
|
_data.chatRecord = JSON.parse(_data.chatRecord); |
|
|
|
console.log(_data, '消息页----收到新消息') |
|
|
|
let msgData = _this.data.msgData; |
|
|
|
// 初始化新消息 |
|
|
|
let isNewMsg = true; |
|
|
|
// 循环数据,检测发送人ID是否存在,如果不存在就是新消息。 |
|
|
|
msgData.forEach(el => { |
|
|
|
// 如果当前消息的 customerId = 发送人的ID |
|
|
|
if (el.businessCommunicationCustomerVO.customerId == _data.chatRecord.sender) { |
|
|
|
el.lastContent = _data.chatRecord.content; |
|
|
|
el.lastContentDate = $util.formatTime(new Date(_data.chatRecord.sendTime)); |
|
|
|
el.lastContentDate = el.lastContentDate.replaceAll('/', '-'); |
|
|
|
el.size += 1; |
|
|
|
if (el.businessCommunicationCustomerVO.customerId == _data.sendno) { |
|
|
|
isNewMsg = false; |
|
|
|
} |
|
|
|
if (el.customer) { |
|
|
|
if (el.customer.paidByMonth) { |
|
|
|
el.businessCommunicationCustomerVO.nickName = el.customer.nickName |
|
|
|
}) |
|
|
|
console.log(`是已存在列表框的还是不存在列表框`, isNewMsg) |
|
|
|
// 如果是新消息 |
|
|
|
if (isNewMsg) { |
|
|
|
let obj = {}; |
|
|
|
obj.lastContent = _data.chatRecord.chatRecord.content; |
|
|
|
obj.lastContentDate = $util.formatTime(new Date(_data.chatRecord.chatRecord.sendTime)); |
|
|
|
obj.lastContentDate = obj.lastContentDate.replaceAll('/', '-'); |
|
|
|
obj.size = 1; |
|
|
|
obj.customer = _data.chatRecord.senderCustomer; |
|
|
|
obj.businessCommunicationCustomerVO = _data.chatRecord.senderBusinessCommunicationCustomer; |
|
|
|
obj.messageType = _data.chatRecord.messageType; |
|
|
|
if (obj.customer) { |
|
|
|
if (obj.customer.paidByMonth) { |
|
|
|
obj.businessCommunicationCustomerVO.nickName = obj.customer.nickName; |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
msgData.unshift(obj); |
|
|
|
} else { |
|
|
|
msgData.forEach(el => { |
|
|
|
// 如果当前消息的 customerId = 发送人的ID |
|
|
|
if (el.businessCommunicationCustomerVO.customerId == _data.chatRecord.chatRecord.sender) { |
|
|
|
el.lastContent = _data.chatRecord.chatRecord.content; |
|
|
|
el.lastContentDate = $util.formatTime(new Date(_data.chatRecord.chatRecord.sendTime)); |
|
|
|
el.lastContentDate = el.lastContentDate.replaceAll('/', '-'); |
|
|
|
el.size += 1; |
|
|
|
} |
|
|
|
if (el.customer) { |
|
|
|
if (el.customer.paidByMonth) { |
|
|
|
el.businessCommunicationCustomerVO.nickName = el.customer.nickName |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
_this.setData({ |
|
|
|
msgData |
|
|
|
}) |
|
|
@@ -181,24 +210,38 @@ Page({ |
|
|
|
}, |
|
|
|
// 左滑删除 |
|
|
|
slideButtonTap(e) { |
|
|
|
console.log(`执行了删除`) |
|
|
|
// wx.showLoading({ |
|
|
|
// title: '操作中', |
|
|
|
// mask: true |
|
|
|
// }) |
|
|
|
let item = e.currentTarget.dataset.item; |
|
|
|
let customerId = item.businessCommunicationCustomerVO.customerId; |
|
|
|
let lastChatRecordCode = item.lastChatRecordCode; |
|
|
|
let msgData = this.data.msgData; |
|
|
|
msgData.forEach((el, inx) => { |
|
|
|
if (el.businessCommunicationCustomerVO.customerId == customerId) { |
|
|
|
msgData.splice(inx, 1); |
|
|
|
} |
|
|
|
}) |
|
|
|
this.setData({ |
|
|
|
msgData: msgData |
|
|
|
}) |
|
|
|
$request.post('/businessCommunicationDemand/delChatRecordTable/' + customerId + '/' + lastChatRecordCode + '.action').then(res => { |
|
|
|
// console.log() |
|
|
|
if (res.status == 0) { |
|
|
|
let msgData = this.data.msgData; |
|
|
|
msgData.forEach((el, inx) => { |
|
|
|
if (el.businessCommunicationCustomerVO.customerId == customerId) { |
|
|
|
msgData.splice(inx, 1); |
|
|
|
} |
|
|
|
}) |
|
|
|
this.setData({ |
|
|
|
msgData: msgData |
|
|
|
}) |
|
|
|
} |
|
|
|
// if (res.status == 0) { |
|
|
|
// let msgData = this.data.msgData; |
|
|
|
// msgData.forEach((el, inx) => { |
|
|
|
// if (el.businessCommunicationCustomerVO.customerId == customerId) { |
|
|
|
// msgData.splice(inx, 1); |
|
|
|
// } |
|
|
|
// }) |
|
|
|
// this.setData({ |
|
|
|
// msgData: msgData |
|
|
|
// }) |
|
|
|
// } |
|
|
|
// wx.hideLoading() |
|
|
|
}).catch(err => { |
|
|
|
// wx.hideLoading() |
|
|
|
console.log(err); |
|
|
|
}) |
|
|
|
}, |