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.
311 lines
7.9 KiB
311 lines
7.9 KiB
import dayjs from 'dayjs' |
|
const licia = require('miniprogram-licia') |
|
|
|
const app = getApp<IAppOption>() |
|
|
|
interface IMessageItem { |
|
msgId: string |
|
msgContentType: '1' | '2' // 1:欢迎语 2: 文本 |
|
msgContent: any |
|
msgVisitTime: string |
|
msgFromType: '1' | '2' // 1: 患者 2: 医生 |
|
msgCreateTime: string // 消息创建时间 |
|
msgCreateTimeName?: string // 消息创建时间 |
|
showTime?: boolean |
|
questionId?: string // 问题ID |
|
Reference?: string // 参考资料 |
|
LikeTimes?: number // 点赞次数 |
|
IsLike?: boolean // 是否点赞 |
|
HasAnswer?: boolean // 是否有答案 |
|
} |
|
|
|
Page({ |
|
data: { |
|
popupShow: false, |
|
popupType: 'selectDoctor', |
|
popupParams: {}, |
|
|
|
expend: false, |
|
scrollTop: 0, |
|
scrollIntoView: '', |
|
doctorDetail: {} as any, |
|
doctorList: {}, |
|
|
|
questionActive: 0, |
|
questionList: [] as any, |
|
questionActiveList: [] as any[], |
|
headerQuestionList: [] as any, |
|
|
|
isLoad: false, |
|
isFinish: false, |
|
messageList: [ |
|
// { msgFromType: '2', msgContentType: '1', msgContent: '你的注射日还未填写,随访计划还未生成哦!' }, |
|
// { msgFromType: '2', msgContentType: '2', msgContent: '' }, |
|
// { msgFromType: '2', msgContentType: '3', msgContent: '' }, |
|
// { msgFromType: '2', msgContentType: '4', msgContent: '' }, |
|
// { msgFromType: '2', msgContentType: '5', msgContent: '' }, |
|
] as IMessageItem[], |
|
nextMsgId: '', |
|
unReadCount: 0, |
|
firstNotReadMsgId: 0, |
|
isVisitAdl: 2, |
|
adlMsgId: 0, |
|
|
|
LikeTimes: 0, |
|
|
|
userInfo: {}, |
|
}, |
|
onLoad() { |
|
app.waitLogin({ type: 1 }).then(() => { |
|
app.mpBehavior({ PageName: 'PG_FAQ' }) |
|
app.getUserInfo().then((userInfo) => { |
|
this.setData({ |
|
userInfo, |
|
}) |
|
}) |
|
this.getBindDoctorList() |
|
this.getQuestionCommonList(this.data.questionActive) |
|
this.getMessageList() |
|
}) |
|
}, |
|
onShow() { |
|
if (app.globalData.loginState) { |
|
this.getBindDoctorList() |
|
} |
|
}, |
|
getBindDoctorList() { |
|
wx.ajax({ |
|
method: 'GET', |
|
url: '?r=wtx/account/get-bind-doctor-list', |
|
data: {}, |
|
}).then((res) => { |
|
this.setData({ |
|
doctorList: res, |
|
}) |
|
}) |
|
}, |
|
getMessageList() { |
|
if (this.data.isLoad || this.data.isFinish) return |
|
this.setData({ |
|
isLoad: true, |
|
}) |
|
const nextMsgId = this.data.nextMsgId |
|
wx.ajax({ |
|
method: 'GET', |
|
url: '?r=wtx/message-interact/get-message-list', |
|
data: { |
|
nextMsgId, |
|
}, |
|
}).then((res) => { |
|
res.messageList.map((item) => { |
|
if (item.msgContentType === '1') { |
|
item.msgOtherInfo = JSON.parse(item.msgOtherInfo) |
|
} |
|
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() |
|
} |
|
}, |
|
handleView(index = -1) { |
|
this.setData({ |
|
scrollIntoView: index > -1 ? `view${index}` : `place`, |
|
}) |
|
}, |
|
getQuestionCommonList(questionActive: number) { |
|
wx.ajax({ |
|
method: 'GET', |
|
url: '?r=wtx/message-interact/get-question-list', |
|
data: {}, |
|
}).then((res) => { |
|
this.setData({ |
|
questionList: res, |
|
questionActiveList: res[questionActive].questionList, |
|
}) |
|
}) |
|
}, |
|
handleQuestion(e: any) { |
|
const { id, name } = e.currentTarget.dataset |
|
this.handleSendQuestion(name) |
|
wx.ajax({ |
|
method: 'POST', |
|
url: '?r=wtx/message-interact/send-question-message', |
|
data: { |
|
questionId: id, |
|
}, |
|
}).then((res) => { |
|
this.handleAskQuestion(res) |
|
}) |
|
}, |
|
handleSendQuestion(qName) { |
|
const { messageList } = this.data |
|
this.setData({ |
|
messageList: [ |
|
...messageList, |
|
{ |
|
msgId: new Date().getTime().toString(), |
|
msgContentType: '2', |
|
msgContent: qName, |
|
msgVisitTime: '', |
|
msgFromType: '1', |
|
msgCreateTime: dayjs().format('YYYY-MM-DD HH:mm:ss'), |
|
}, |
|
], |
|
}) |
|
this.filterCreateTime() |
|
this.handleView() |
|
}, |
|
handleAskQuestion(aName) { |
|
const { messageList } = this.data |
|
this.setData({ |
|
messageList: [ |
|
...messageList, |
|
{ |
|
msgId: new Date().getTime().toString(), |
|
msgContentType: '2', |
|
msgContent: aName, |
|
msgVisitTime: '', |
|
msgFromType: '2', |
|
msgCreateTime: dayjs().format('YYYY-MM-DD HH:mm:ss'), |
|
}, |
|
], |
|
}) |
|
this.filterCreateTime() |
|
this.handleView() |
|
}, |
|
handleQuestionClick(Id) { |
|
wx.ajax({ |
|
method: 'POST', |
|
url: '?r=wtx/common-question/click', |
|
data: { Id }, |
|
}) |
|
}, |
|
handleLike(e) { |
|
const { index } = e.currentTarget.dataset |
|
const { messageList, LikeTimes } = this.data |
|
const item = messageList[index] |
|
const LikeTimesKey = `messageList[${index}].LikeTimes` |
|
const IsLikeKey = `messageList[${index}].IsLike` |
|
this.setData({ |
|
[LikeTimesKey]: Number(item.LikeTimes) + 1, |
|
[IsLikeKey]: true, |
|
LikeTimes: LikeTimes + 1, |
|
}) |
|
this.likePost(item.questionId) |
|
}, |
|
likePost: licia.debounce(function (this: any, Id) { |
|
const { LikeTimes } = this.data |
|
this.setData({ |
|
LikeTimes: 0, |
|
}) |
|
wx.ajax({ |
|
method: 'POST', |
|
url: '?r=wtx/common-question/like', |
|
data: { |
|
Id, |
|
LikeTimes, |
|
}, |
|
}) |
|
}, 1000), |
|
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, |
|
}) |
|
}, |
|
handleSendDate() { |
|
this.setData({ |
|
popupShow: true, |
|
popupType: 'selectDoctor', |
|
popupParams: {}, |
|
}) |
|
}, |
|
handleQuestionTab(e) { |
|
const { index } = e.currentTarget.dataset |
|
this.setData({ |
|
questionActive: index, |
|
questionActiveList: this.data.questionList[index].questionList, |
|
}) |
|
}, |
|
handleFooter() { |
|
this.setData({ |
|
expend: !this.data.expend, |
|
}) |
|
if (this.data.expend) { |
|
setTimeout(() => { |
|
this.handleView() |
|
}, 300) |
|
} |
|
}, |
|
handleDoctorList() { |
|
wx.navigateTo({ |
|
url: '/patient/pages/doctorList/index', |
|
}) |
|
}, |
|
handlePopupCancel() { |
|
this.setData({ |
|
popupShow: false, |
|
}) |
|
}, |
|
handleBack() { |
|
wx.navigateBack() |
|
}, |
|
})
|
|
|