信达小程序
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.

539 lines
14 KiB

import dayjs from 'dayjs'
10 months ago
const app = getApp<IAppOption>()
10 months ago
interface IMessageItem {
msgId: string
4 hours ago
msgContentType: '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' | '10' | '11' | '12' | '13' | '14' | '15' | '16' | '17' // 1:文本 2: 出诊时间 3: adl卡片 4: 语音 5: 欢迎语 6:补充真实姓名 7: 提醒完善信息 8: 复诊卡片 9:患者恢复复诊消息 12:复诊提醒 13:复诊提醒-快速问答 14:未复诊原因 15:未复诊原因回复 16:未复诊鼓励 17:下一步
msgContent: any
msgVisitTime: string
msgVisitTimeType?: string
msgFromType: '1' | '2' // 1: 患者 2: 医生
isPlay?: boolean
msgCreateTime: string // 消息创建时间
msgCreateTimeName?: string // 消息创建时间
showTime?: boolean
4 hours ago
ReVisitInfo?: any
6 months ago
msgCustomSendStatus?: number | string
4 hours ago
msgTipsInfo?: string
followUpStatus?: number // 复诊状态,>0 表示已回复
replyMsgId?: number // 回复消息ID,>0 表示已回复
followUpTitle?: string // 复诊原因标题
followUpTitleChoice?: string // 复诊原因多选提示
10 months ago
}
interface Item {
wordId: string
word: string
10 months ago
}
Page({
data: {
6 months ago
popupShow: false,
popupType: 'popup9',
popupParams: {} as any,
10 months ago
doctor: {} as any,
patientId: '',
messageListShow: false,
patientDetail: {},
inputShow: false,
maxTextArea: false,
focus: false,
10 months ago
isLoad: false,
isFinish: false,
scrollTop: 0,
scrollIntoView: '',
messageList: [] as IMessageItem[],
nextMsgId: '',
wordIndex: 0,
wordList: [] as Item[],
week: ['周一', '周二', '周三', '周四', '周五', '周六', '周日'],
timeDay: { 1: '上午', 2: '下午' },
6 months ago
customMessage: '',
10 months ago
},
innerAudioContext: null as WechatMiniprogram.InnerAudioContext | null,
onLoad(options) {
this.innerAudioContext = wx.createInnerAudioContext({
useWebAudioImplement: true,
})
10 months ago
this.setData({
patientId: options.patientId,
})
10 months ago
},
onShow() {
app.waitLogin({ type: [2] }).then((_res) => {
app.mpBehavior({ doctor: true, PageName: 'PG_DoctorIMDetail' })
this.getDoctorDetail()
this.getPatientDetail()
this.getMessageList()
this.getWordList()
})
10 months ago
},
onUnload() {
if (this.innerAudioContext) {
this.innerAudioContext.stop()
10 months ago
}
},
getDoctorDetail() {
wx.ajax({
method: 'GET',
url: '?r=zd/doctor/account/info',
data: {},
}).then((res) => {
this.setData({
doctor: res.doctor,
})
})
10 months ago
},
getPatientDetail() {
wx.ajax({
method: 'GET',
url: '?r=zd/doctor/message-interact/get-patient-info',
data: {
patientId: this.data.patientId,
},
}).then((res) => {
if (res.LastAdlTime) {
res.LastAdlTimeName = dayjs(res.LastAdlTime).from(dayjs().format('YYYY-MM-DD')).replace(' ', '')
10 months ago
}
this.setData({
patientDetail: {
...res,
BecomePatientTime: dayjs(res.BecomePatientTime).format('YYYY-MM-DD'),
},
})
})
10 months ago
},
getMessageList() {
if (this.data.isLoad || this.data.isFinish)
return
10 months ago
this.setData({
isLoad: true,
})
const nextMsgId = this.data.nextMsgId
10 months ago
wx.ajax({
method: 'GET',
url: '?r=zd/doctor/message-interact/doctor-get-message-list',
data: {
nextMsgId,
patientId: this.data.patientId,
},
}).then((res) => {
res.messageList.map((item) => {
if (item.msgContentType === '4') {
item.msgContent = JSON.parse(item.msgContent)
10 months ago
}
if (item.msgContentType === '2') {
item.msgVisitTime = item.msgVisitTimeType == 2 ? item.msgVisitTime : JSON.parse(item.msgVisitTime)
10 months ago
}
if (item.msgContentType === '5') {
item.welcomeMsg = JSON.parse(item.welcomeMsg)
10 months ago
}
if (item.msgContentType === '9') {
item.ReVisitInfo = JSON.parse(item.ReVisitInfo)
item.ReVisitInfo.visitDateName = dayjs(item.ReVisitInfo.visitDate).format('YYYY年M月DD日')
10 months ago
}
4 hours ago
if (item.msgContentType === '13') {
const rawInfo = JSON.parse(item.ReVisitInfo)
// 解析结构:{title, lastVisitTitle, visitDate, mySolutionTitle, reVisitSolution}
item.ReVisitInfo = rawInfo
}
if (item.msgContentType === '14') {
const rawInfo = JSON.parse(item.ReVisitInfo)
// 解析结构:{title, titleChoice, missionReasonList, reasonList}
const missionReasonList = rawInfo.missionReasonList || {}
const reasonList = rawInfo.reasonList || []
item.ReVisitInfo = Object.keys(missionReasonList).map(key => ({
key,
label: missionReasonList[key],
isSelected: reasonList.includes(key),
}))
item.followUpTitle = rawInfo.title || '请问您没能按时复诊的主要原因是?'
item.followUpTitleChoice = rawInfo.titleChoice || '(多选)'
}
if (item.msgContentType === '15') {
const rawInfo = JSON.parse(item.ReVisitInfo)
// 解析结构:{title, reasonInfoList}
const reasonInfoList = rawInfo.reasonInfoList || {}
item.followUpTitle = rawInfo.title || '没能按时复诊的主要原因是?'
item.ReVisitInfo = Object.keys(reasonInfoList).map(key => reasonInfoList[key])
}
10 months ago
return item
})
10 months ago
if (!this.data.nextMsgId && !res.messageList.length) {
res.messageList = [
{
msgId: '0',
msgContentType: '0',
msgContent: '',
msgVisitTime: '',
msgFromType: '2',
},
]
10 months ago
}
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()
10 months ago
if (!nextMsgId) {
this.handleView()
10 months ago
}
})
10 months ago
},
scrolltoupper(e) {
if (e.detail.direction === 'top') {
this.getMessageList()
10 months ago
}
},
getWordList() {
wx.ajax({
method: 'GET',
url: '?r=zd/doctor/message-interact/get-common-word-list',
data: {},
}).then((res) => {
this.setData({
wordList: res,
})
})
10 months ago
},
handleSendDate() {
app.mpBehavior({ doctor: true, PageName: 'BTN_DoctorIMDetailClinicHours' })
10 months ago
const {
messageList,
doctor: { Clinic },
} = this.data
10 months ago
if (!Clinic || (Array.isArray(Clinic) && !Clinic.length)) {
wx.showModal({
title: '完善出诊时间?',
content: '您还没有录入出诊时间',
confirmText: '录入',
10 months ago
confirmColor: '#8c75d0',
10 months ago
success: (res) => {
if (res.confirm) {
wx.navigateTo({
url: '/pages/d_userInfo/index',
})
10 months ago
}
},
})
return
10 months ago
}
wx.showModal({
title: '提示',
content: '将您的出诊时间发送给患者?',
10 months ago
confirmColor: '#8c75d0',
10 months ago
success: (res) => {
if (res.confirm) {
this.setData({
messageList: [
...messageList,
{
msgId: '',
msgContentType: '2',
msgContent: '',
msgVisitTime: this.data.doctor.Clinic,
msgVisitTimeType: this.data.doctor.ClinicType,
msgFromType: '2',
msgCreateTime: dayjs().format('YYYY-MM-DD HH:mm:ss'),
},
],
})
this.filterCreateTime()
10 months ago
wx.ajax({
method: 'POST',
url: '?r=zd/doctor/message-interact/send-visit-time',
data: {
patientId: this.data.patientId,
},
})
this.handleView()
10 months ago
}
},
})
10 months ago
},
handleSendShow() {
app.mpBehavior({ doctor: true, PageName: 'BTN_DoctorIMDetailSendMessage' })
10 months ago
this.setData({
messageListShow: true,
})
10 months ago
},
handlePopupMessageClose() {
this.setData({
messageListShow: false,
})
10 months ago
},
handleInputShow() {
this.setData({
inputShow: true,
focus: true,
})
},
toggleMaxTextarea() {
this.setData({
maxTextArea: !this.data.maxTextArea,
})
},
10 months ago
handleWord(e) {
const { index } = e.currentTarget.dataset
10 months ago
this.setData({
wordIndex: index,
})
10 months ago
},
handleSendWord() {
const { messageList, wordList, wordIndex } = this.data
const { wordId, word } = wordList[wordIndex]
10 months ago
this.setData({
messageList: [
...messageList,
{
msgId: '',
msgContentType: '1',
msgContent: word,
msgVisitTime: '',
msgFromType: '2',
msgCreateTime: dayjs().format('YYYY-MM-DD HH:mm:ss'),
},
],
})
this.filterCreateTime()
this.handlePopupMessageClose()
this.handleView()
10 months ago
wx.ajax({
method: 'POST',
url: '?r=zd/doctor/message-interact/send-word-message',
data: {
patientId: this.data.patientId,
wordId,
},
})
10 months ago
},
handleSendUserConform(e) {
const { id } = e.currentTarget.dataset
10 months ago
const title = {
6: '发送后患者将收到补充姓名通知',
7: '发送后患者将收到完善信息通知',
}[id]
10 months ago
wx.showModal({
title,
10 months ago
confirmColor: '#8c75d0',
10 months ago
success: (res) => {
if (res.confirm) {
this.handleSendUser(id)
10 months ago
}
},
})
10 months ago
},
handleSendUser(id) {
const { messageList } = this.data
10 months ago
const content = {
6: '请完善您的真实姓名,以便我清楚了解您的病情',
7: '请完善您的个人信息,以便我清楚了解您的病情',
}[id]
10 months ago
this.setData({
messageList: [
...messageList,
{
msgId: '',
msgContentType: id,
msgContent: content,
msgVisitTime: '',
msgFromType: '2',
msgCreateTime: dayjs().format('YYYY-MM-DD HH:mm:ss'),
},
],
})
this.filterCreateTime()
this.handlePopupMessageClose()
this.handleView()
10 months ago
const url = {
6: '?r=zd/doctor/message-interact/send-remind-name',
7: '?r=zd/doctor/message-interact/send-remind-init',
}[id]
10 months ago
wx.ajax({
method: 'POST',
url,
data: {
patientId: this.data.patientId,
},
})
10 months ago
},
formatTime(date: string) {
let msgCreateTimeName = ''
10 months ago
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')
10 months ago
}
return msgCreateTimeName
10 months ago
},
filterCreateTime() {
const gapTime = 5 * 60 * 1000
const { messageList } = this.data
10 months ago
let preTime = 0
10 months ago
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()
10 months ago
if (curTime - preTime > gapTime) {
item.showTime = true
item.msgCreateTimeName = this.formatTime(item.msgCreateTime)
preTime = dayjs(item.msgCreateTime).valueOf()
10 months ago
}
}
})
10 months ago
this.setData({
messageList,
})
10 months ago
},
handleView(index = -1) {
this.setData({
scrollIntoView: index > -1 ? `view${index}` : `place`,
})
10 months ago
},
handlePatientDetail() {
app.mpBehavior({ doctor: true, PageName: 'BTN_DoctorIMDetailPatient' })
10 months ago
wx.navigateTo({
url: `/pages/d_patientDetail/index?id=${this.data.patientId}`,
})
10 months ago
},
handleAudio(e) {
const { index } = e.currentTarget.dataset
const { messageList } = this.data
const messageItem = messageList[index]
const { url } = messageItem.msgContent[0]
10 months ago
if (this.innerAudioContext) {
if (messageItem.isPlay) {
this.innerAudioContext.stop()
messageItem.isPlay = false
10 months ago
this.setData({
messageList,
})
return
10 months ago
}
this.innerAudioContext.stop()
this.innerAudioContext.src = url
this.innerAudioContext.play()
messageItem.isPlay = true
10 months ago
this.innerAudioContext.onEnded(() => {
messageItem.isPlay = false
10 months ago
this.setData({
messageList,
})
})
10 months ago
this.innerAudioContext.onStop(() => {
messageItem.isPlay = false
10 months ago
this.setData({
messageList,
})
})
10 months ago
this.setData({
messageList,
})
10 months ago
}
},
handleAdl() {
wx.showToast({
title: '患者点击此按钮可进入ADL测评页面',
icon: 'none',
})
10 months ago
},
handleHideKeyboard() {
if (this.data.inputShow) {
this.setData({
inputShow: false,
focus: false,
})
}
},
6 months ago
handleConfirm() {
const { customMessage } = this.data
this.handleHideKeyboard()
this.handleSendCustomMessage(customMessage)
},
handleSendCustomMessage(customMessage: string) {
if (!customMessage)
return
const { messageList, patientId } = this.data
wx.ajax({
method: 'POST',
url: '?r=zd/doctor/message-interact/send-text-message',
data: {
text: customMessage,
patientId,
},
loading: true,
loadingText: '发送中...',
6 months ago
}).then((res) => {
if (res.errcode == 10001) {
this.setData({
popupShow: true,
popupType: 'popup9',
popupParams: {
message: res.errmsg,
},
})
return
}
const pushMessage: IMessageItem[] = [
{
msgId: '',
msgContentType: '12',
msgContent: customMessage,
msgVisitTime: '',
msgFromType: '2',
msgCreateTime: dayjs().format('YYYY-MM-DD HH:mm:ss'),
},
]
this.setData({
customMessage: '',
messageList: [...messageList, ...pushMessage],
})
this.filterCreateTime()
this.handleView()
})
},
handlePopupOk() {
this.setData({
popupShow: false,
})
},
handlePopupCancel() {
this.setData({
popupShow: false,
})
},
handleBack() {
wx.navigateBack()
},
})