武田小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

453 lines
11 KiB

import dayjs from "dayjs";
1 year ago
const app = getApp<IAppOption>();
1 year ago
interface IMessageItem {
msgId: string;
contentType: "1" | "2" | "3" | "4" | "5"; // 1:文本 2: 语音 3. 图片 4. 视频 5. 提示信息
content: any;
fromDoctorId: string;
doctorImg: string;
msgVisitTime: string;
createTime: "";
isSelf: 1 | 2;
isRead: 1 | 2;
1 year ago
}
interface Item {
questionId: string;
question: string;
1 year ago
}
Page({
1 year ago
data: {
id: "",
show1: false,
1 year ago
fold: true,
scrollTop: 0,
scrollIntoView: "",
1 year ago
doctorDetail: {} as any,
questionActive: 0,
questionList: [] as any,
questionActiveList: [] as Item[],
roomDoctors: [],
newRoomDoctors: [],
case: {} as any,
chatGroupInfo: {},
chatDoctor: {},
1 year ago
isLoad: false,
isFinish: false,
messageList: [
{
msgId: "686",
contentType: "2",
msgContent: "重症肌无力患者复查的频率取决于多种因素",
welcomeMsg: "",
msgVisitTime: "",
msgFromType: "2",
msgCreateTime: "2024-10-10 09:37:40",
1 year ago
},
{
msgId: "686",
contentType: "3",
msgContent: "重症肌无力患者复查的频率取决于多种因素",
welcomeMsg: "",
msgVisitTime: "",
msgFromType: "2",
msgCreateTime: "2024-10-10 09:37:40",
1 year ago
},
{
msgId: "686",
contentType: "2",
msgContent: "重症肌无力患者复查的频率取决于多种因素",
welcomeMsg: "",
msgVisitTime: "",
msgFromType: "1",
msgCreateTime: "2024-10-10 09:37:40",
1 year ago
},
{
msgId: "686",
contentType: "3",
msgContent: "重症肌无力患者复查的频率取决于多种因素",
welcomeMsg: "",
msgVisitTime: "",
msgFromType: "1",
msgCreateTime: "2024-10-10 09:37:40",
1 year ago
},
{
msgId: "681",
contentType: "1",
msgContent: "重症肌无力是否有遗传性?",
welcomeMsg: "",
msgVisitTime: "",
msgFromType: "1",
msgCreateTime: "2024-10-10 09:37:17",
1 year ago
},
{
msgId: "681",
contentType: "1",
msgContent: "重症肌无力是否有遗传性?",
welcomeMsg: "",
msgVisitTime: "",
msgFromType: "1",
msgCreateTime: "2024-10-10 09:37:17",
1 year ago
},
{
msgId: "483",
contentType: "4",
1 year ago
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",
1 year ago
},
{
msgId: "483",
contentType: "4",
1 year ago
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",
1 year ago
},
],
lastMsgId: "",
1 year ago
unReadCount: 0,
firstNotReadMsgId: 0,
isVisitAdl: 2,
adlMsgId: 0,
week: ["周一", "周二", "周三", "周四", "周五", "周六", "周日"],
timeDay: { 1: "上午", 2: "下午" },
1 year ago
userInfo: {},
},
innerAudioContext: null as WechatMiniprogram.InnerAudioContext | null,
videoContext: null as WechatMiniprogram.VideoContext | null,
onLoad(options) {
this.setData({
id: options.id,
});
this.videoContext = wx.createVideoContext("video");
app.waitLogin().then(() => {
// this.getAgree();
this.getMessageList();
this.getDetail();
});
1 year ago
},
onUnload() {
if (this.innerAudioContext) {
this.innerAudioContext.stop();
1 year ago
}
},
getAgree() {
wx.ajax({
method: "GET",
url: "?r=takeda/chat/get-agree",
data: {
roomId: this.data.id,
},
}).then((res) => {
this.setData({
show1: res === 2,
});
});
},
onAgreeClose() {
wx.navigateBack();
},
handleSubmitAgree() {
wx.ajax({
method: "POST",
url: "?r=takeda/chat/agree-room",
data: {
roomId: this.data.id,
},
}).then(() => {
this.setData({
show1: false,
});
});
},
getDetail() {
wx.ajax({
method: "GET",
url: "?r=takeda/chat/get-room-detail",
data: { roomId: this.data.id },
}).then((res) => {
this.setData({
roomDoctors: res.roomDoctors,
newRoomDoctors: res.roomDoctors.slice(0, 4),
case: res.case,
chatGroupInfo: res.chatGroupInfo,
chatDoctor: res.chatDoctor,
});
});
},
handleRoomDetail() {
wx.navigateTo({
url: `/module1/pages/chatRoomInfo/index?id=${this.data.id}&cid=${this.data.case.caseId}`,
});
},
1 year ago
handleView(index = -1) {
this.setData({
scrollIntoView: index > -1 ? `view${index}` : `place`,
});
1 year ago
},
getDoctorDetail() {
wx.ajax({
method: "GET",
url: "?r=zd/message-interact/get-bind-doctor-info",
1 year ago
data: {},
}).then((res) => {
this.setData({
doctorDetail: {
...res,
},
});
});
1 year ago
},
getQuestionList() {
wx.ajax({
method: "GET",
url: "?r=zd/message-interact/get-question-list",
1 year ago
data: {},
}).then((res) => {
this.setData({
questionList: res,
questionActiveList: res[0].questionList,
});
});
1 year ago
},
getMessageList() {
if (this.data.isLoad || this.data.isFinish) return;
1 year ago
this.setData({
isLoad: true,
});
const lastMsgId = this.data.lastMsgId;
1 year ago
wx.ajax({
method: "GET",
url: "?r=takeda/chat/get-message-list",
1 year ago
data: {
lastMsgId,
roomId: this.data.id,
1 year ago
},
}).then((res) => {
res.map((item) => {
//消息内容类型,1-文本,2-语音,3-图片,4-视频,5-提示信息
if (["2", "3", "4"].includes(item.contentType)) {
item.msgContent = JSON.parse(item.msgContent);
1 year ago
}
return item;
});
1 year ago
this.setData({
messageList: [...res.messageList.reverse(), ...this.data.messageList],
lastMsgId: res.lastMsgId,
1 year ago
unReadCount: res.unReadCount,
firstNotReadMsgId: res.firstNotReadMsgId,
isVisitAdl: res.isVisitAdl,
adlMsgId: res.adlMsgId,
isLoad: false,
isFinish: lastMsgId === res.lastMsgId,
});
this.filterCreateTime();
if (!lastMsgId) {
this.handleView();
1 year ago
}
});
1 year ago
},
scrolltoupper(e) {
// if (e.detail.direction === 'top') {
// this.getMessageList()
// }
},
handleHot(e) {
const { index, mindex } = e.currentTarget.dataset;
const { messageList } = this.data;
const hotList = messageList[mindex].welcomeMsg?.hotQuestion;
const hot = hotList?.[index];
1 year ago
this.setData({
messageList: [
...messageList,
{
msgId: "",
contentType: "1",
1 year ago
msgContent: hot?.question,
msgVisitTime: "",
msgFromType: "1",
msgCreateTime: dayjs().format("YYYY-MM-DD HH:mm:ss"),
1 year ago
},
],
});
this.handleView();
this.sendQuestion(hot?.questionId);
1 year ago
},
handleQuestion(e) {
const { index } = e.currentTarget.dataset;
const { questionActiveList, messageList } = this.data;
const question = questionActiveList[index];
1 year ago
this.setData({
messageList: [
...messageList,
{
msgId: "",
contentType: "1",
1 year ago
msgContent: question.question,
msgVisitTime: "",
msgFromType: "1",
msgCreateTime: dayjs().format("YYYY-MM-DD HH:mm:ss"),
1 year ago
},
],
});
this.sendQuestion(question.questionId);
1 year ago
},
sendQuestion(questionId) {
wx.ajax({
method: "POST",
url: "?r=zd/message-interact/send-question-message",
1 year ago
data: {
questionId,
},
}).then((res) => {
this.setData({
messageList: [
...this.data.messageList,
{
msgId: "",
contentType: "1",
1 year ago
msgContent: res,
msgVisitTime: "",
msgFromType: "2",
msgCreateTime: dayjs().format("YYYY-MM-DD HH:mm:ss"),
1 year ago
},
],
});
this.filterCreateTime();
this.handleView();
});
1 year ago
},
formatTime(date: string) {
let msgCreateTimeName = "";
if (dayjs().format("YYYY-MM-DD") === dayjs(date).format("YYYY-MM-DD")) {
msgCreateTimeName = 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")}`;
} else if (dayjs().diff(date, "day") < 7) {
msgCreateTimeName = dayjs(date).format(`dddd HH:mm`);
1 year ago
} else {
msgCreateTimeName = dayjs(date).format("YYYY-MM-DD HH:mm");
1 year ago
}
return msgCreateTimeName;
1 year ago
},
filterCreateTime() {
const gapTime = 5 * 60 * 1000;
const { messageList } = this.data;
1 year ago
let preTime = 0;
1 year ago
messageList.forEach((item, index) => {
if (index === 0) {
item.showTime = true;
preTime = dayjs(item.msgCreateTime).valueOf();
item.msgCreateTimeName = this.formatTime(item.msgCreateTime);
1 year ago
} else {
const curTime = dayjs(item.msgCreateTime).valueOf();
1 year ago
if (curTime - preTime > gapTime) {
item.showTime = true;
item.msgCreateTimeName = this.formatTime(item.msgCreateTime);
preTime = dayjs(item.msgCreateTime).valueOf();
1 year ago
}
}
});
1 year ago
this.setData({
messageList,
});
1 year ago
},
handleQuestionTab(e) {
const { index } = e.currentTarget.dataset;
1 year ago
this.setData({
questionActive: index,
questionActiveList: this.data.questionList[index].questionList,
});
1 year ago
},
handleDoctorDetail() {
const { doctorId } = this.data.doctorDetail;
1 year ago
wx.navigateTo({
url: `/pages/doctorDetail/index?id=${doctorId}`,
});
1 year ago
},
handleRead() {
const { firstNotReadMsgId, messageList } = this.data;
const index = messageList.findIndex((item) => `${item.msgId}` === `${firstNotReadMsgId}`);
this.handleView(index);
1 year ago
this.setData({
unReadCount: 0,
});
1 year ago
},
handleFooter() {
this.setData({
fold: !this.data.fold,
});
1 year ago
if (this.data.fold) {
setTimeout(() => {
this.handleView();
}, 300);
1 year ago
}
},
handleAdl() {
wx.navigateTo({
url: "/pages/adl/index",
});
1 year ago
},
handleAudio(e) {
const { index } = e.currentTarget.dataset;
const { messageList } = this.data;
const messageItem = messageList[index];
const { url } = messageItem.msgContent[0];
1 year ago
if (this.innerAudioContext) {
if (messageItem.isPlay) {
this.innerAudioContext.stop();
messageItem.isPlay = false;
1 year ago
this.setData({
messageList,
});
return;
1 year ago
}
this.innerAudioContext.stop();
this.innerAudioContext.src = url;
this.innerAudioContext.play();
messageItem.isPlay = true;
1 year ago
this.innerAudioContext.onEnded(() => {
messageItem.isPlay = false;
1 year ago
this.setData({
messageList,
});
});
1 year ago
this.setData({
messageList,
});
1 year ago
}
},
handlePreview(e) {
const { url } = e.currentTarget.dataset;
1 year ago
wx.previewImage({
urls: [url],
});
1 year ago
},
handleVideo() {
if (this.videoContext) {
this.videoContext.play();
this.videoContext.requestFullScreen({});
1 year ago
}
},
});