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.
374 lines
9.7 KiB
374 lines
9.7 KiB
import dayjs from 'dayjs' |
|
|
|
const app = getApp<IAppOption>() |
|
|
|
interface IMessageItem { |
|
msgId: string |
|
msgContentType: '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' // 1:文本 2: 出诊时间 3: adl卡片 4: 语音 5: 欢迎语 6:补充真实姓名 7: 提醒完善信息 8: 复诊卡片 9:患者恢复复诊消息 |
|
msgContent: any |
|
msgVisitTime: string |
|
msgFromType: '1' | '2' // 1: 患者 2: 医生 |
|
isPlay?: boolean |
|
welcomeMsg?: { |
|
hotQuestion: Item[] |
|
} |
|
msgCreateTime: string // 消息创建时间 |
|
msgCreateTimeName?: string // 消息创建时间 |
|
showTime?: boolean |
|
ReVisitInfo?: any |
|
} |
|
|
|
interface Item { |
|
questionId: string |
|
question: string |
|
} |
|
|
|
Page({ |
|
data: { |
|
expend: false, |
|
scrollTop: 0, |
|
scrollIntoView: '', |
|
doctorDetail: {} as any, |
|
|
|
questionActive: 0, |
|
questionList: [] as any, |
|
questionActiveList: [] as Item[], |
|
|
|
isLoad: false, |
|
isFinish: false, |
|
messageList: [] as IMessageItem[], |
|
nextMsgId: '', |
|
unReadCount: 0, |
|
firstNotReadMsgId: 0, |
|
isVisitAdl: 2, |
|
adlMsgId: 0, |
|
|
|
week: ['周一', '周二', '周三', '周四', '周五', '周六', '周日'], |
|
timeDay: { 1: '上午', 2: '下午' }, |
|
|
|
zdUserInfo: {}, |
|
}, |
|
innerAudioContext: null as WechatMiniprogram.InnerAudioContext | null, |
|
onLoad(options) { |
|
this.innerAudioContext = wx.createInnerAudioContext({ |
|
useWebAudioImplement: true, |
|
}) |
|
app.waitLogin({ type: [1] }).then(() => { |
|
app.mpBehavior({ PageName: 'PG_PatientImDetails' }) |
|
this.getDoctorDetail() |
|
this.getQuestionList() |
|
this.getMessageList() |
|
app.getZdUserInfo(this, true, (zdUserInfo) => { |
|
this.setData({ |
|
zdUserInfo, |
|
}) |
|
}) |
|
if (options.adlPushId) { |
|
wx.ajax({ |
|
method: 'POST', |
|
url: '?r=zd/push-click/adl-push-click', |
|
data: { adlPushId: options.adlPushId }, |
|
}) |
|
} |
|
if (options.taskPushId) { |
|
wx.ajax({ |
|
method: 'POST', |
|
url: '?r=zd/push-click/task-push-click', |
|
data: { taskPushId: options.taskPushId }, |
|
}) |
|
} |
|
}) |
|
}, |
|
onUnload() { |
|
if (this.innerAudioContext) { |
|
this.innerAudioContext.stop() |
|
} |
|
}, |
|
handleView(index = -1) { |
|
this.setData({ |
|
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, |
|
}) |
|
}) |
|
}, |
|
getMessageList() { |
|
if (this.data.isLoad || this.data.isFinish) return |
|
this.setData({ |
|
isLoad: true, |
|
}) |
|
const nextMsgId = this.data.nextMsgId |
|
wx.ajax({ |
|
method: 'GET', |
|
url: '?r=zd/message-interact/patient-get-message-list', |
|
data: { |
|
nextMsgId, |
|
}, |
|
}).then((res) => { |
|
res.messageList.map((item) => { |
|
if (item.msgContentType === '4') { |
|
item.msgContent = JSON.parse(item.msgContent) |
|
} |
|
if (item.msgContentType === '2') { |
|
item.msgVisitTime = item.msgVisitTimeType == 2 ? item.msgVisitTime : JSON.parse(item.msgVisitTime) |
|
} |
|
if (item.msgContentType === '5') { |
|
item.welcomeMsg = JSON.parse(item.welcomeMsg) |
|
} |
|
if (item.msgContentType === '9') { |
|
item.ReVisitInfo = JSON.parse(item.ReVisitInfo) |
|
item.ReVisitInfo.visitDateName = dayjs(item.ReVisitInfo.visitDate).format('YYYY年M月DD日') |
|
} |
|
|
|
return item |
|
}) |
|
this.setData({ |
|
messageList: [...res.messageList.reverse(), ...this.data.messageList], |
|
nextMsgId: res.nextMsgId, |
|
unReadCount: res.unReadCount, |
|
firstNotReadMsgId: res.firstNotReadMsgId, |
|
isVisitAdl: res.isVisitAdl, |
|
adlMsgId: res.adlMsgId, |
|
isLoad: false, |
|
isFinish: nextMsgId === res.nextMsgId, |
|
}) |
|
this.filterCreateTime() |
|
if (!nextMsgId) { |
|
this.handleView() |
|
} |
|
}) |
|
}, |
|
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] |
|
this.setData({ |
|
messageList: [ |
|
...messageList, |
|
{ |
|
msgId: '', |
|
msgContentType: '1', |
|
msgContent: hot?.question, |
|
msgVisitTime: '', |
|
msgFromType: '1', |
|
msgCreateTime: 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: '', |
|
msgContentType: '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: '', |
|
msgContentType: '1', |
|
msgContent: res, |
|
msgVisitTime: '', |
|
msgFromType: '2', |
|
msgCreateTime: dayjs().format('YYYY-MM-DD HH:mm:ss'), |
|
}, |
|
], |
|
}) |
|
this.filterCreateTime() |
|
this.handleView() |
|
}) |
|
}, |
|
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`) |
|
} else { |
|
msgCreateTimeName = dayjs(date).format('YYYY-MM-DD HH:mm') |
|
} |
|
return msgCreateTimeName |
|
}, |
|
filterCreateTime() { |
|
const gapTime = 5 * 60 * 1000 |
|
const { messageList } = this.data |
|
|
|
let preTime = 0 |
|
messageList.forEach((item, index) => { |
|
if (index === 0) { |
|
item.showTime = true |
|
preTime = dayjs(item.msgCreateTime).valueOf() |
|
item.msgCreateTimeName = this.formatTime(item.msgCreateTime) |
|
} else { |
|
const curTime = dayjs(item.msgCreateTime).valueOf() |
|
if (curTime - preTime > gapTime) { |
|
item.showTime = true |
|
item.msgCreateTimeName = this.formatTime(item.msgCreateTime) |
|
preTime = dayjs(item.msgCreateTime).valueOf() |
|
} |
|
} |
|
}) |
|
this.setData({ |
|
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: `/patient/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() { |
|
app.mpBehavior({ PageName: 'BTN_PatientImAsk' }) |
|
this.setData({ |
|
expend: !this.data.expend, |
|
}) |
|
if (this.data.expend) { |
|
setTimeout(() => { |
|
this.handleView() |
|
}, 300) |
|
} |
|
}, |
|
handleAdl() { |
|
wx.navigateTo({ |
|
url: '/patient/pages/adl/index', |
|
}) |
|
}, |
|
handleAudio(e) { |
|
const { index } = e.currentTarget.dataset |
|
const { messageList } = this.data |
|
const messageItem = messageList[index] |
|
const { url } = messageItem.msgContent[0] |
|
if (this.innerAudioContext) { |
|
if (messageItem.isPlay) { |
|
this.innerAudioContext.stop() |
|
messageItem.isPlay = false |
|
this.setData({ |
|
messageList, |
|
}) |
|
return |
|
} |
|
this.innerAudioContext.stop() |
|
this.innerAudioContext.src = url |
|
this.innerAudioContext.play() |
|
messageItem.isPlay = true |
|
this.innerAudioContext.onEnded(() => { |
|
messageItem.isPlay = false |
|
this.setData({ |
|
messageList, |
|
}) |
|
}) |
|
this.setData({ |
|
messageList, |
|
}) |
|
} |
|
}, |
|
handleFillUserInfo() { |
|
wx.navigateTo({ |
|
url: '/patient/pages/personalInformation/index', |
|
}) |
|
}, |
|
handleReferral() { |
|
this.setData({ |
|
referralFromShow: true, |
|
}) |
|
}, |
|
handleReferralReplay(e) { |
|
const params = e.detail |
|
this.setData({ |
|
messageList: [ |
|
...this.data.messageList, |
|
{ |
|
msgId: '', |
|
msgContentType: '9', |
|
msgVisitTime: '', |
|
msgContent: '', |
|
msgFromType: '1', |
|
msgCreateTime: dayjs().format('YYYY-MM-DD HH:mm:ss'), |
|
ReVisitInfo: { |
|
...params, |
|
visitDateName: dayjs(params.visitDate).format('YYYY年M月DD日'), |
|
}, |
|
}, |
|
], |
|
}) |
|
}, |
|
handleBack() { |
|
wx.navigateBack({ |
|
fail() { |
|
wx.reLaunch({ |
|
url: '/patient/pages/index/index', |
|
}) |
|
}, |
|
}) |
|
}, |
|
})
|
|
|