|
|
|
|
import dayjs from 'dayjs'
|
|
|
|
|
|
|
|
|
|
const app = getApp<IAppOption>()
|
|
|
|
|
|
|
|
|
|
interface IMessageItem {
|
|
|
|
|
msgId: string
|
|
|
|
|
msgContentType: '1' | '2' | '5' | '10' | '11' | '12'
|
|
|
|
|
msgContent: any
|
|
|
|
|
msgVisitTime: string
|
|
|
|
|
msgVisitTimeType?: string
|
|
|
|
|
msgFromType: '1' | '2'
|
|
|
|
|
isPlay?: boolean
|
|
|
|
|
msgCreateTime: string
|
|
|
|
|
msgCreateTimeName?: string
|
|
|
|
|
showTime?: boolean
|
|
|
|
|
msgCustomSendStatus?: number | string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface Item {
|
|
|
|
|
wordId: string
|
|
|
|
|
word: string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Page({
|
|
|
|
|
data: {
|
|
|
|
|
pageTop: 0,
|
|
|
|
|
|
|
|
|
|
popupShow: false,
|
|
|
|
|
popupType: 'popup9',
|
|
|
|
|
popupParams: {} as any,
|
|
|
|
|
|
|
|
|
|
doctor: {} as any,
|
|
|
|
|
|
|
|
|
|
patientId: '',
|
|
|
|
|
messageListShow: false,
|
|
|
|
|
patientDetail: {},
|
|
|
|
|
|
|
|
|
|
inputShow: false,
|
|
|
|
|
maxTextArea: false,
|
|
|
|
|
focus: false,
|
|
|
|
|
|
|
|
|
|
isLoad: false,
|
|
|
|
|
isFinish: false,
|
|
|
|
|
scrollTop: 0,
|
|
|
|
|
scrollIntoView: '',
|
|
|
|
|
messageList: [] as IMessageItem[],
|
|
|
|
|
nextMsgId: '',
|
|
|
|
|
|
|
|
|
|
wordIndex: 0,
|
|
|
|
|
wordList: [] as Item[],
|
|
|
|
|
|
|
|
|
|
week: ['周一', '周二', '周三', '周四', '周五', '周六', '周日'],
|
|
|
|
|
timeDay: { 1: '上午', 2: '下午' },
|
|
|
|
|
|
|
|
|
|
customMessage: '',
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
onLoad(options) {
|
|
|
|
|
const menuButton = wx.getMenuButtonBoundingClientRect()
|
|
|
|
|
const pageTop = menuButton.bottom + 8
|
|
|
|
|
this.setData({ pageTop })
|
|
|
|
|
|
|
|
|
|
this.setData({
|
|
|
|
|
patientId: options.patientId,
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
onShow() {
|
|
|
|
|
app.waitLogin().then((_res) => {
|
|
|
|
|
app.mpBehavior({ doctor: true, PageName: 'PG_DoctorIMDetail' })
|
|
|
|
|
this.getDoctorDetail()
|
|
|
|
|
this.getPatientDetail()
|
|
|
|
|
this.getMessageList()
|
|
|
|
|
this.getWordList()
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
getDoctorDetail() {
|
|
|
|
|
wx.ajax({
|
|
|
|
|
method: 'GET',
|
|
|
|
|
url: '?r=zd/doctor/account/info',
|
|
|
|
|
data: {},
|
|
|
|
|
}).then((res) => {
|
|
|
|
|
this.setData({
|
|
|
|
|
doctor: res.doctor,
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
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(' ', '')
|
|
|
|
|
}
|
|
|
|
|
this.setData({
|
|
|
|
|
patientDetail: {
|
|
|
|
|
...res,
|
|
|
|
|
BecomePatientTime: dayjs(res.BecomePatientTime).format('YYYY-MM-DD'),
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
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/doctor/message-interact/doctor-get-message-list',
|
|
|
|
|
data: {
|
|
|
|
|
nextMsgId,
|
|
|
|
|
patientId: this.data.patientId,
|
|
|
|
|
},
|
|
|
|
|
}).then((res) => {
|
|
|
|
|
res.messageList.map((item) => {
|
|
|
|
|
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)
|
|
|
|
|
}
|
|
|
|
|
return item
|
|
|
|
|
})
|
|
|
|
|
if (!this.data.nextMsgId && !res.messageList.length) {
|
|
|
|
|
res.messageList = [
|
|
|
|
|
{
|
|
|
|
|
msgId: '0',
|
|
|
|
|
msgContentType: '0',
|
|
|
|
|
msgContent: '',
|
|
|
|
|
msgVisitTime: '',
|
|
|
|
|
msgFromType: '2',
|
|
|
|
|
},
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
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()
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
getWordList() {
|
|
|
|
|
wx.ajax({
|
|
|
|
|
method: 'GET',
|
|
|
|
|
url: '?r=zd/doctor/message-interact/get-common-word-list',
|
|
|
|
|
data: {},
|
|
|
|
|
}).then((res) => {
|
|
|
|
|
this.setData({
|
|
|
|
|
wordList: res,
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
handleSendDate() {
|
|
|
|
|
app.mpBehavior({ doctor: true, PageName: 'BTN_DoctorIMDetailClinicHours' })
|
|
|
|
|
const {
|
|
|
|
|
messageList,
|
|
|
|
|
doctor: { Clinic },
|
|
|
|
|
} = this.data
|
|
|
|
|
if (!Clinic || (Array.isArray(Clinic) && !Clinic.length)) {
|
|
|
|
|
wx.showModal({
|
|
|
|
|
title: '完善出诊时间?',
|
|
|
|
|
content: '您还没有录入出诊时间',
|
|
|
|
|
confirmText: '录入',
|
|
|
|
|
confirmColor: 'rgba(22, 121, 203, 1)',
|
|
|
|
|
success: (res) => {
|
|
|
|
|
if (res.confirm) {
|
|
|
|
|
wx.navigateTo({
|
|
|
|
|
url: '/doctor/pages/d_userInfo/index',
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
wx.showModal({
|
|
|
|
|
title: '提示',
|
|
|
|
|
content: '将您的出诊时间发送给患者?',
|
|
|
|
|
confirmColor: 'rgba(22, 121, 203, 1)',
|
|
|
|
|
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()
|
|
|
|
|
wx.ajax({
|
|
|
|
|
method: 'POST',
|
|
|
|
|
url: '?r=zd/doctor/message-interact/send-visit-time',
|
|
|
|
|
data: {
|
|
|
|
|
patientId: this.data.patientId,
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
this.handleView()
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
handleSendShow() {
|
|
|
|
|
app.mpBehavior({ doctor: true, PageName: 'BTN_DoctorIMDetailSendMessage' })
|
|
|
|
|
this.setData({
|
|
|
|
|
messageListShow: true,
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
handlePopupMessageClose() {
|
|
|
|
|
this.setData({
|
|
|
|
|
messageListShow: false,
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
handleInputShow() {
|
|
|
|
|
this.setData({
|
|
|
|
|
inputShow: true,
|
|
|
|
|
focus: true,
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
toggleMaxTextarea() {
|
|
|
|
|
this.setData({
|
|
|
|
|
maxTextArea: !this.data.maxTextArea,
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
handleWord(e) {
|
|
|
|
|
const { index } = e.currentTarget.dataset
|
|
|
|
|
this.setData({
|
|
|
|
|
wordIndex: index,
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
handleSendWord() {
|
|
|
|
|
const { messageList, wordList, wordIndex } = this.data
|
|
|
|
|
const { wordId, word } = wordList[wordIndex]
|
|
|
|
|
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()
|
|
|
|
|
wx.ajax({
|
|
|
|
|
method: 'POST',
|
|
|
|
|
url: '?r=zd/doctor/message-interact/send-word-message',
|
|
|
|
|
data: {
|
|
|
|
|
patientId: this.data.patientId,
|
|
|
|
|
wordId,
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
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,
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
handleView(index = -1) {
|
|
|
|
|
this.setData({
|
|
|
|
|
scrollIntoView: index > -1 ? `view${index}` : `place`,
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
handlePatientDetail() {
|
|
|
|
|
app.mpBehavior({ doctor: true, PageName: 'BTN_DoctorIMDetailPatient' })
|
|
|
|
|
wx.navigateTo({
|
|
|
|
|
url: `/doctor/pages/d_patientDetail/index?id=${this.data.patientId}`,
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
handleHideKeyboard() {
|
|
|
|
|
if (this.data.inputShow) {
|
|
|
|
|
this.setData({
|
|
|
|
|
inputShow: false,
|
|
|
|
|
focus: false,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
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,
|
|
|
|
|
}).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({
|
|
|
|
|
fail() {
|
|
|
|
|
wx.reLaunch({
|
|
|
|
|
url: '/doctor/pages/d_home/index',
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
})
|