|
|
|
@ -8,15 +8,14 @@ interface IMessageItem {
@@ -8,15 +8,14 @@ interface IMessageItem {
|
|
|
|
|
content: any; |
|
|
|
|
fromDoctorId: string; |
|
|
|
|
doctorImg: string; |
|
|
|
|
msgVisitTime: string; |
|
|
|
|
createTime: ""; |
|
|
|
|
createTime: string; |
|
|
|
|
createTimeName?: string; |
|
|
|
|
isSelf: 1 | 2; |
|
|
|
|
isRead: 1 | 2; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
interface Item { |
|
|
|
|
questionId: string; |
|
|
|
|
question: string; |
|
|
|
|
doctorName: string; |
|
|
|
|
hospitalName: string; |
|
|
|
|
showTime?: boolean; |
|
|
|
|
isPlay?: boolean; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Page({ |
|
|
|
@ -30,104 +29,21 @@ Page({
@@ -30,104 +29,21 @@ Page({
|
|
|
|
|
scrollIntoView: "", |
|
|
|
|
doctorDetail: {} as any, |
|
|
|
|
|
|
|
|
|
questionActive: 0, |
|
|
|
|
questionList: [] as any, |
|
|
|
|
questionActiveList: [] as Item[], |
|
|
|
|
|
|
|
|
|
roomDoctors: [], |
|
|
|
|
newRoomDoctors: [], |
|
|
|
|
case: {} as any, |
|
|
|
|
chatGroupInfo: {}, |
|
|
|
|
chatDoctor: {}, |
|
|
|
|
chatGroupInfo: {} as any, |
|
|
|
|
chatDoctor: {} as any, |
|
|
|
|
|
|
|
|
|
isLoad: false, |
|
|
|
|
isFinish: false, |
|
|
|
|
messageList: [ |
|
|
|
|
{ |
|
|
|
|
msgId: "686", |
|
|
|
|
contentType: "2", |
|
|
|
|
msgContent: "重症肌无力患者复查的频率取决于多种因素", |
|
|
|
|
welcomeMsg: "", |
|
|
|
|
msgVisitTime: "", |
|
|
|
|
msgFromType: "2", |
|
|
|
|
msgCreateTime: "2024-10-10 09:37:40", |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
msgId: "686", |
|
|
|
|
contentType: "3", |
|
|
|
|
msgContent: "重症肌无力患者复查的频率取决于多种因素", |
|
|
|
|
welcomeMsg: "", |
|
|
|
|
msgVisitTime: "", |
|
|
|
|
msgFromType: "2", |
|
|
|
|
msgCreateTime: "2024-10-10 09:37:40", |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
msgId: "686", |
|
|
|
|
contentType: "2", |
|
|
|
|
msgContent: "重症肌无力患者复查的频率取决于多种因素", |
|
|
|
|
welcomeMsg: "", |
|
|
|
|
msgVisitTime: "", |
|
|
|
|
msgFromType: "1", |
|
|
|
|
msgCreateTime: "2024-10-10 09:37:40", |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
msgId: "686", |
|
|
|
|
contentType: "3", |
|
|
|
|
msgContent: "重症肌无力患者复查的频率取决于多种因素", |
|
|
|
|
welcomeMsg: "", |
|
|
|
|
msgVisitTime: "", |
|
|
|
|
msgFromType: "1", |
|
|
|
|
msgCreateTime: "2024-10-10 09:37:40", |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
msgId: "681", |
|
|
|
|
contentType: "1", |
|
|
|
|
msgContent: "重症肌无力是否有遗传性?", |
|
|
|
|
welcomeMsg: "", |
|
|
|
|
msgVisitTime: "", |
|
|
|
|
msgFromType: "1", |
|
|
|
|
msgCreateTime: "2024-10-10 09:37:17", |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
msgId: "681", |
|
|
|
|
contentType: "1", |
|
|
|
|
msgContent: "重症肌无力是否有遗传性?", |
|
|
|
|
welcomeMsg: "", |
|
|
|
|
msgVisitTime: "", |
|
|
|
|
msgFromType: "1", |
|
|
|
|
msgCreateTime: "2024-10-10 09:37:17", |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
msgId: "483", |
|
|
|
|
contentType: "4", |
|
|
|
|
msgContent: |
|
|
|
|
'[{"duration":8,"url":"https://circlehbsaas.oss-cn-beijing.aliyuncs.com/audio/20240907757_tmp_acf4f18c59553a8d2d9f74e173a16328.m4a.mp3"}]', |
|
|
|
|
welcomeMsg: "", |
|
|
|
|
msgVisitTime: "", |
|
|
|
|
msgFromType: "2", |
|
|
|
|
msgCreateTime: "2024-10-08 15:24:19", |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
msgId: "483", |
|
|
|
|
contentType: "4", |
|
|
|
|
msgContent: |
|
|
|
|
'[{"duration":8,"url":"https://circlehbsaas.oss-cn-beijing.aliyuncs.com/audio/20240907757_tmp_acf4f18c59553a8d2d9f74e173a16328.m4a.mp3"}]', |
|
|
|
|
welcomeMsg: "", |
|
|
|
|
msgVisitTime: "", |
|
|
|
|
msgFromType: "1", |
|
|
|
|
msgCreateTime: "2024-10-08 15:24:19", |
|
|
|
|
}, |
|
|
|
|
], |
|
|
|
|
messageList: [] as IMessageItem[], |
|
|
|
|
lastMsgId: "", |
|
|
|
|
unReadCount: 0, |
|
|
|
|
firstNotReadMsgId: 0, |
|
|
|
|
isVisitAdl: 2, |
|
|
|
|
adlMsgId: 0, |
|
|
|
|
|
|
|
|
|
week: ["周一", "周二", "周三", "周四", "周五", "周六", "周日"], |
|
|
|
|
timeDay: { 1: "上午", 2: "下午" }, |
|
|
|
|
userInfo: {} as any, |
|
|
|
|
|
|
|
|
|
userInfo: {}, |
|
|
|
|
sendMessage: [], |
|
|
|
|
}, |
|
|
|
|
innerAudioContext: null as WechatMiniprogram.InnerAudioContext | null, |
|
|
|
|
videoContext: null as WechatMiniprogram.VideoContext | null, |
|
|
|
@ -141,9 +57,12 @@ Page({
@@ -141,9 +57,12 @@ Page({
|
|
|
|
|
|
|
|
|
|
this.getMessageList(); |
|
|
|
|
this.getDetail(); |
|
|
|
|
this.listenMessage(); |
|
|
|
|
app.getUserInfo(this); |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
onUnload() { |
|
|
|
|
wx.WebIM.conn.close(); |
|
|
|
|
if (this.innerAudioContext) { |
|
|
|
|
this.innerAudioContext.stop(); |
|
|
|
|
} |
|
|
|
@ -190,6 +109,7 @@ Page({
@@ -190,6 +109,7 @@ Page({
|
|
|
|
|
chatGroupInfo: res.chatGroupInfo, |
|
|
|
|
chatDoctor: res.chatDoctor, |
|
|
|
|
}); |
|
|
|
|
this.WebIMLogin(); |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
handleRoomDetail() { |
|
|
|
@ -203,29 +123,14 @@ Page({
@@ -203,29 +123,14 @@ Page({
|
|
|
|
|
scrollIntoView: index > -1 ? `view${index}` : `place`, |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
getDoctorDetail() { |
|
|
|
|
wx.ajax({ |
|
|
|
|
method: "GET", |
|
|
|
|
url: "?r=zd/message-interact/get-bind-doctor-info", |
|
|
|
|
data: {}, |
|
|
|
|
}).then((res) => { |
|
|
|
|
this.setData({ |
|
|
|
|
doctorDetail: { |
|
|
|
|
...res, |
|
|
|
|
}, |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
getQuestionList() { |
|
|
|
|
wx.ajax({ |
|
|
|
|
method: "GET", |
|
|
|
|
url: "?r=zd/message-interact/get-question-list", |
|
|
|
|
data: {}, |
|
|
|
|
}).then((res) => { |
|
|
|
|
this.setData({ |
|
|
|
|
questionList: res, |
|
|
|
|
questionActiveList: res[0].questionList, |
|
|
|
|
}); |
|
|
|
|
listenMessage() { |
|
|
|
|
wx.WebIM.conn.addEventHandler("room", { |
|
|
|
|
onConnected: (message) => { |
|
|
|
|
console.log("message: ", message); |
|
|
|
|
}, |
|
|
|
|
onTextMessage: (meessage) => { |
|
|
|
|
console.log("meessage1: ", meessage); |
|
|
|
|
}, |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
getMessageList() { |
|
|
|
@ -242,23 +147,23 @@ Page({
@@ -242,23 +147,23 @@ Page({
|
|
|
|
|
roomId: this.data.id, |
|
|
|
|
}, |
|
|
|
|
}).then((res) => { |
|
|
|
|
if (res.length === 0) { |
|
|
|
|
this.setData({ |
|
|
|
|
isFinite: true, |
|
|
|
|
}); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
res.map((item) => { |
|
|
|
|
//消息内容类型,1-文本,2-语音,3-图片,4-视频,5-提示信息
|
|
|
|
|
if (["2", "3", "4"].includes(item.contentType)) { |
|
|
|
|
item.msgContent = JSON.parse(item.msgContent); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return item; |
|
|
|
|
}); |
|
|
|
|
this.setData({ |
|
|
|
|
messageList: [...res.messageList.reverse(), ...this.data.messageList], |
|
|
|
|
lastMsgId: res.lastMsgId, |
|
|
|
|
unReadCount: res.unReadCount, |
|
|
|
|
firstNotReadMsgId: res.firstNotReadMsgId, |
|
|
|
|
isVisitAdl: res.isVisitAdl, |
|
|
|
|
adlMsgId: res.adlMsgId, |
|
|
|
|
messageList: [...res.reverse(), ...this.data.messageList], |
|
|
|
|
lastMsgId: res[0].msgId, |
|
|
|
|
isLoad: false, |
|
|
|
|
isFinish: lastMsgId === res.lastMsgId, |
|
|
|
|
}); |
|
|
|
|
this.filterCreateTime(); |
|
|
|
|
if (!lastMsgId) { |
|
|
|
@ -267,9 +172,80 @@ Page({
@@ -267,9 +172,80 @@ Page({
|
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
scrolltoupper(e) { |
|
|
|
|
// if (e.detail.direction === 'top') {
|
|
|
|
|
// this.getMessageList()
|
|
|
|
|
// }
|
|
|
|
|
if (e.detail.direction === "top") { |
|
|
|
|
this.getMessageList(); |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
WebIMLogin() { |
|
|
|
|
const { chatDoctor } = this.data; |
|
|
|
|
wx.WebIM.conn.open({ |
|
|
|
|
user: chatDoctor.chatUserId, |
|
|
|
|
pwd: chatDoctor.chatUserPwd, |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
handleSendMessage() { |
|
|
|
|
const { sendMessage, userInfo } = this.data; |
|
|
|
|
if (!sendMessage) { |
|
|
|
|
wx.showToast({ |
|
|
|
|
icon: "none", |
|
|
|
|
title: "请输入内容", |
|
|
|
|
}); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
const message: IMessageItem = { |
|
|
|
|
msgId: "", |
|
|
|
|
contentType: "1", |
|
|
|
|
content: sendMessage, |
|
|
|
|
fromDoctorId: userInfo.DoctorId, |
|
|
|
|
createTime: dayjs().format("YYYY-MM-DD HH:mm:ss"), |
|
|
|
|
isSelf: 1, |
|
|
|
|
isRead: 1, |
|
|
|
|
doctorImg: userInfo.Img, |
|
|
|
|
doctorName: userInfo.Name, |
|
|
|
|
hospitalName: userInfo.HospitalName, |
|
|
|
|
}; |
|
|
|
|
this.WebIMSendMessage(message); |
|
|
|
|
}, |
|
|
|
|
WebIMSendMessage(message: IMessageItem) { |
|
|
|
|
const { chatGroupInfo } = this.data; |
|
|
|
|
const option = { |
|
|
|
|
type: "txt", |
|
|
|
|
msg: message.content, |
|
|
|
|
to: chatGroupInfo.ChatGroupId, |
|
|
|
|
chatType: "groupChat", |
|
|
|
|
ext: { |
|
|
|
|
...message, |
|
|
|
|
}, |
|
|
|
|
}; |
|
|
|
|
const msg = wx.WebIM.message.create(option); |
|
|
|
|
wx.WebIM.conn |
|
|
|
|
.send(msg) |
|
|
|
|
.then((res) => { |
|
|
|
|
this.sendMessage({ ...message, uniqueCode: res.serverMsgId }); |
|
|
|
|
this.setData({ |
|
|
|
|
messageList: [...this.data.messageList, message], |
|
|
|
|
}); |
|
|
|
|
}) |
|
|
|
|
.catch(() => { |
|
|
|
|
wx.showToast({ |
|
|
|
|
icon: "none", |
|
|
|
|
title: "发送失败", |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
sendMessage({ uniqueCode, ...message }) { |
|
|
|
|
wx.ajax({ |
|
|
|
|
method: "POST", |
|
|
|
|
url: "?r=takeda/chat/send-message", |
|
|
|
|
data: { |
|
|
|
|
roomId: this.data.id, |
|
|
|
|
message: { |
|
|
|
|
contentType: message.contentType, |
|
|
|
|
content: message.content, |
|
|
|
|
uniqueCode, |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
handleHot(e) { |
|
|
|
|
const { index, mindex } = e.currentTarget.dataset; |
|
|
|
@ -285,69 +261,25 @@ Page({
@@ -285,69 +261,25 @@ Page({
|
|
|
|
|
msgContent: hot?.question, |
|
|
|
|
msgVisitTime: "", |
|
|
|
|
msgFromType: "1", |
|
|
|
|
msgCreateTime: dayjs().format("YYYY-MM-DD HH:mm:ss"), |
|
|
|
|
createTime: dayjs().format("YYYY-MM-DD HH:mm:ss"), |
|
|
|
|
}, |
|
|
|
|
], |
|
|
|
|
}); |
|
|
|
|
this.handleView(); |
|
|
|
|
this.sendQuestion(hot?.questionId); |
|
|
|
|
}, |
|
|
|
|
handleQuestion(e) { |
|
|
|
|
const { index } = e.currentTarget.dataset; |
|
|
|
|
const { questionActiveList, messageList } = this.data; |
|
|
|
|
const question = questionActiveList[index]; |
|
|
|
|
this.setData({ |
|
|
|
|
messageList: [ |
|
|
|
|
...messageList, |
|
|
|
|
{ |
|
|
|
|
msgId: "", |
|
|
|
|
contentType: "1", |
|
|
|
|
msgContent: question.question, |
|
|
|
|
msgVisitTime: "", |
|
|
|
|
msgFromType: "1", |
|
|
|
|
msgCreateTime: dayjs().format("YYYY-MM-DD HH:mm:ss"), |
|
|
|
|
}, |
|
|
|
|
], |
|
|
|
|
}); |
|
|
|
|
this.sendQuestion(question.questionId); |
|
|
|
|
}, |
|
|
|
|
sendQuestion(questionId) { |
|
|
|
|
wx.ajax({ |
|
|
|
|
method: "POST", |
|
|
|
|
url: "?r=zd/message-interact/send-question-message", |
|
|
|
|
data: { |
|
|
|
|
questionId, |
|
|
|
|
}, |
|
|
|
|
}).then((res) => { |
|
|
|
|
this.setData({ |
|
|
|
|
messageList: [ |
|
|
|
|
...this.data.messageList, |
|
|
|
|
{ |
|
|
|
|
msgId: "", |
|
|
|
|
contentType: "1", |
|
|
|
|
msgContent: res, |
|
|
|
|
msgVisitTime: "", |
|
|
|
|
msgFromType: "2", |
|
|
|
|
msgCreateTime: dayjs().format("YYYY-MM-DD HH:mm:ss"), |
|
|
|
|
}, |
|
|
|
|
], |
|
|
|
|
}); |
|
|
|
|
this.filterCreateTime(); |
|
|
|
|
this.handleView(); |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
formatTime(date: string) { |
|
|
|
|
let msgCreateTimeName = ""; |
|
|
|
|
let createTimeName = ""; |
|
|
|
|
if (dayjs().format("YYYY-MM-DD") === dayjs(date).format("YYYY-MM-DD")) { |
|
|
|
|
msgCreateTimeName = dayjs(date).format("HH:mm"); |
|
|
|
|
createTimeName = dayjs(date).format("HH:mm"); |
|
|
|
|
} else if (dayjs().format("YYYY-MM-DD") === dayjs(date).add(1, "day").format("YYYY-MM-DD")) { |
|
|
|
|
msgCreateTimeName = `昨天 ${dayjs(date).format("HH:mm")}`; |
|
|
|
|
createTimeName = `昨天 ${dayjs(date).format("HH:mm")}`; |
|
|
|
|
} else if (dayjs().diff(date, "day") < 7) { |
|
|
|
|
msgCreateTimeName = dayjs(date).format(`dddd HH:mm`); |
|
|
|
|
createTimeName = dayjs(date).format(`dddd HH:mm`); |
|
|
|
|
} else { |
|
|
|
|
msgCreateTimeName = dayjs(date).format("YYYY-MM-DD HH:mm"); |
|
|
|
|
createTimeName = dayjs(date).format("YYYY-MM-DD HH:mm"); |
|
|
|
|
} |
|
|
|
|
return msgCreateTimeName; |
|
|
|
|
return createTimeName; |
|
|
|
|
}, |
|
|
|
|
filterCreateTime() { |
|
|
|
|
const gapTime = 5 * 60 * 1000; |
|
|
|
@ -357,14 +289,14 @@ Page({
@@ -357,14 +289,14 @@ Page({
|
|
|
|
|
messageList.forEach((item, index) => { |
|
|
|
|
if (index === 0) { |
|
|
|
|
item.showTime = true; |
|
|
|
|
preTime = dayjs(item.msgCreateTime).valueOf(); |
|
|
|
|
item.msgCreateTimeName = this.formatTime(item.msgCreateTime); |
|
|
|
|
preTime = dayjs(item.createTime).valueOf(); |
|
|
|
|
item.createTimeName = this.formatTime(item.createTime); |
|
|
|
|
} else { |
|
|
|
|
const curTime = dayjs(item.msgCreateTime).valueOf(); |
|
|
|
|
const curTime = dayjs(item.createTime).valueOf(); |
|
|
|
|
if (curTime - preTime > gapTime) { |
|
|
|
|
item.showTime = true; |
|
|
|
|
item.msgCreateTimeName = this.formatTime(item.msgCreateTime); |
|
|
|
|
preTime = dayjs(item.msgCreateTime).valueOf(); |
|
|
|
|
item.createTimeName = this.formatTime(item.createTime); |
|
|
|
|
preTime = dayjs(item.createTime).valueOf(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
@ -372,27 +304,6 @@ Page({
@@ -372,27 +304,6 @@ Page({
|
|
|
|
|
messageList, |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
handleQuestionTab(e) { |
|
|
|
|
const { index } = e.currentTarget.dataset; |
|
|
|
|
this.setData({ |
|
|
|
|
questionActive: index, |
|
|
|
|
questionActiveList: this.data.questionList[index].questionList, |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
handleDoctorDetail() { |
|
|
|
|
const { doctorId } = this.data.doctorDetail; |
|
|
|
|
wx.navigateTo({ |
|
|
|
|
url: `/pages/doctorDetail/index?id=${doctorId}`, |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
handleRead() { |
|
|
|
|
const { firstNotReadMsgId, messageList } = this.data; |
|
|
|
|
const index = messageList.findIndex((item) => `${item.msgId}` === `${firstNotReadMsgId}`); |
|
|
|
|
this.handleView(index); |
|
|
|
|
this.setData({ |
|
|
|
|
unReadCount: 0, |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
handleFooter() { |
|
|
|
|
this.setData({ |
|
|
|
|
fold: !this.data.fold, |
|
|
|
@ -403,16 +314,11 @@ Page({
@@ -403,16 +314,11 @@ Page({
|
|
|
|
|
}, 300); |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
handleAdl() { |
|
|
|
|
wx.navigateTo({ |
|
|
|
|
url: "/pages/adl/index", |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
handleAudio(e) { |
|
|
|
|
const { index } = e.currentTarget.dataset; |
|
|
|
|
const { messageList } = this.data; |
|
|
|
|
const messageItem = messageList[index]; |
|
|
|
|
const { url } = messageItem.msgContent[0]; |
|
|
|
|
const { url } = messageItem.content[0]; |
|
|
|
|
if (this.innerAudioContext) { |
|
|
|
|
if (messageItem.isPlay) { |
|
|
|
|
this.innerAudioContext.stop(); |
|
|
|
|