|
|
|
|
|
|
|
|
}) |
|
|
}) |
|
|
// 接收服务器的消息事件 |
|
|
// 接收服务器的消息事件 |
|
|
wx.onSocketMessage(function (res) { |
|
|
wx.onSocketMessage(function (res) { |
|
|
console.log(res, '消息发送页接受---------------------------------'); |
|
|
|
|
|
|
|
|
// console.log(res, '消息发送页接受---------------------------------'); |
|
|
// 接收到的消息{date,message,type} type类型为 1 是对方的消息 为 0 是自己的消息 |
|
|
// 接收到的消息{date,message,type} type类型为 1 是对方的消息 为 0 是自己的消息 |
|
|
let list = []; |
|
|
let list = []; |
|
|
list = _this.data.newsList; |
|
|
list = _this.data.newsList; |
|
|
|
|
|
let historyList = _this.data.historyList; |
|
|
let _data = JSON.parse(res.data); |
|
|
let _data = JSON.parse(res.data); |
|
|
|
|
|
|
|
|
if (_data.readMessageCode) { |
|
|
if (_data.readMessageCode) { |
|
|
|
|
|
|
|
|
|
|
|
list.forEach(el=>{ |
|
|
|
|
|
el.isRead = true; |
|
|
|
|
|
}) |
|
|
|
|
|
historyList.forEach(el=>{ |
|
|
|
|
|
el.isRead = true; |
|
|
|
|
|
}) |
|
|
|
|
|
_this.setData({ |
|
|
|
|
|
newsList: list, |
|
|
|
|
|
historyList |
|
|
|
|
|
}) |
|
|
} else { |
|
|
} else { |
|
|
|
|
|
|
|
|
_data.chatRecord = JSON.parse(_data.chatRecord); |
|
|
_data.chatRecord = JSON.parse(_data.chatRecord); |
|
|
|
|
|
|
|
|
console.log(_data, '_data'); |
|
|
|
|
|
let msgData = {}; |
|
|
let msgData = {}; |
|
|
// type 0 自己 1 对方 |
|
|
// type 0 自己 1 对方 |
|
|
if (_data.chatRecord.chatRecord.sender != _this.data.receiveMemberId) { |
|
|
if (_data.chatRecord.chatRecord.sender != _this.data.receiveMemberId) { |
|
|
|
|
|
|
|
|
if (msgData.messageType == 1) { |
|
|
if (msgData.messageType == 1) { |
|
|
msgData.object = _data.chatRecord.chatRecord.object; |
|
|
msgData.object = _data.chatRecord.chatRecord.object; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
let d = { |
|
|
|
|
|
sendno: _this.data.receiveMemberId, |
|
|
|
|
|
userno: _this.data.sendMemberId, |
|
|
|
|
|
messageModule : "010", |
|
|
|
|
|
readMessageCode: _data.chatRecord.chatRecord.chatRecordCode, |
|
|
|
|
|
}; |
|
|
|
|
|
wx.sendSocketMessage({ |
|
|
|
|
|
data: JSON.stringify(d), |
|
|
|
|
|
success: (res) => { |
|
|
|
|
|
console.log(`发送成功`) |
|
|
|
|
|
console.log(res) |
|
|
|
|
|
}, |
|
|
|
|
|
fail: (err) => { |
|
|
|
|
|
console.log('sendSocketMessage', '失败') |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
msgData.date = utils.formatTime(new Date(_data.chatRecord.chatRecord.sendTime)); |
|
|
msgData.date = utils.formatTime(new Date(_data.chatRecord.chatRecord.sendTime)); |
|
|
msgData.date = msgData.date.replaceAll('/', '-'); |
|
|
msgData.date = msgData.date.replaceAll('/', '-'); |
|
|
list.push(msgData); |
|
|
list.push(msgData); |
|
|
|
|
|
|
|
|
temp.messageType = msgType; |
|
|
temp.messageType = msgType; |
|
|
temp.transactionId = transactionId; |
|
|
temp.transactionId = transactionId; |
|
|
temp.isRead = false; |
|
|
temp.isRead = false; |
|
|
|
|
|
let tempGuid = this.guid(); |
|
|
|
|
|
temp.code = tempGuid; |
|
|
if (msgType == 1) { |
|
|
if (msgType == 1) { |
|
|
temp.object = {}; |
|
|
temp.object = {}; |
|
|
temp.object.info = this.data.productInfo; |
|
|
temp.object.info = this.data.productInfo; |
|
|
|
|
|
|
|
|
newsList: list, |
|
|
newsList: list, |
|
|
input: null, |
|
|
input: null, |
|
|
inputShowed: true, |
|
|
inputShowed: true, |
|
|
|
|
|
currentGuid:tempGuid |
|
|
}) |
|
|
}) |
|
|
this.scrollBottom() |
|
|
this.scrollBottom() |
|
|
// 表情选择隐藏 |
|
|
// 表情选择隐藏 |
|
|
|
|
|
|
|
|
urls: [url] // 需要预览的图片http链接列表 |
|
|
urls: [url] // 需要预览的图片http链接列表 |
|
|
}) |
|
|
}) |
|
|
}, |
|
|
}, |
|
|
|
|
|
guid() { |
|
|
|
|
|
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { |
|
|
|
|
|
var r = Math.random() * 16 | 0, |
|
|
|
|
|
v = c == 'x' ? r : (r & 0x3 | 0x8); |
|
|
|
|
|
return v.toString(16); |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|