武田基因病B开发环境
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.

312 lines
7.9 KiB

2 months ago
import dayjs from 'dayjs'
const licia = require('miniprogram-licia')
const app = getApp<IAppOption>()
interface IMessageItem {
msgId: string
msgContentType: '1' | '2' // 1:欢迎语 2: 文本
2 months ago
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: {},
2 months ago
expend: false,
scrollTop: 0,
scrollIntoView: '',
doctorDetail: {} as any,
doctorList: {},
2 months ago
questionActive: 0,
questionList: [] as any,
questionActiveList: [] as any[],
headerQuestionList: [] as any,
isLoad: false,
isFinish: false,
1 month ago
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: '' },
1 month ago
] as IMessageItem[],
2 months ago
nextMsgId: '',
unReadCount: 0,
firstNotReadMsgId: 0,
isVisitAdl: 2,
adlMsgId: 0,
LikeTimes: 0,
userInfo: {},
},
onLoad() {
2 weeks ago
app.waitLogin({ type: 1 }).then(() => {
2 months ago
app.mpBehavior({ PageName: 'PG_FAQ' })
app.getUserInfo().then((userInfo) => {
this.setData({
userInfo,
})
})
this.getBindDoctorList()
this.getQuestionCommonList(this.data.questionActive)
this.getMessageList()
2 months ago
})
},
2 weeks ago
onShow() {
if (app.globalData.loginState) {
this.getBindDoctorList()
}
},
getBindDoctorList() {
2 months ago
wx.ajax({
method: 'GET',
url: '?r=wtx/account/get-bind-doctor-list',
2 months ago
data: {},
}).then((res) => {
this.setData({
doctorList: res,
2 months ago
})
})
},
getMessageList() {
if (this.data.isLoad || this.data.isFinish) return
this.setData({
isLoad: true,
})
const nextMsgId = this.data.nextMsgId
2 months ago
wx.ajax({
method: 'GET',
url: '?r=wtx/message-interact/get-message-list',
data: {
nextMsgId,
},
2 months ago
}).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()
}
2 months ago
})
},
scrolltoupper(e) {
if (e.detail.direction === 'top') {
this.getMessageList()
}
},
handleView(index = -1) {
this.setData({
scrollIntoView: index > -1 ? `view${index}` : `place`,
})
},
getQuestionCommonList(questionActive: number) {
2 months ago
wx.ajax({
method: 'GET',
url: '?r=wtx/message-interact/get-question-list',
2 months ago
data: {},
}).then((res) => {
this.setData({
questionList: res,
questionActiveList: res[questionActive].questionList,
2 months ago
})
})
},
handleQuestion(e: any) {
const { id, name } = e.currentTarget.dataset
this.handleSendQuestion(name)
2 months ago
wx.ajax({
method: 'POST',
url: '?r=wtx/message-interact/send-question-message',
2 months ago
data: {
questionId: id,
2 months ago
},
}).then((res) => {
this.handleAskQuestion(res)
2 months ago
})
},
handleSendQuestion(qName) {
2 months ago
const { messageList } = this.data
this.setData({
messageList: [
...messageList,
{
msgId: new Date().getTime().toString(),
msgContentType: '2',
msgContent: qName,
2 months ago
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,
2 months ago
{
msgId: new Date().getTime().toString(),
msgContentType: '2',
msgContent: aName,
2 months ago
msgVisitTime: '',
msgFromType: '2',
msgCreateTime: dayjs().format('YYYY-MM-DD HH:mm:ss'),
},
],
})
this.filterCreateTime()
2 months ago
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,
})
},
2 weeks ago
handleSendDate() {
this.setData({
popupShow: true,
popupType: 'selectDoctor',
popupParams: {},
})
},
2 months ago
handleQuestionTab(e) {
const { index } = e.currentTarget.dataset
this.setData({
questionActive: index,
questionActiveList: this.data.questionList[index].questionList,
2 months ago
})
},
handleFooter() {
this.setData({
expend: !this.data.expend,
})
if (this.data.expend) {
setTimeout(() => {
this.handleView()
}, 300)
}
},
2 months ago
handleDoctorList() {
wx.navigateTo({
url: '/patient/pages/doctorList/index',
})
},
2 weeks ago
handlePopupCancel() {
this.setData({
popupShow: false,
})
},
2 months ago
handleBack() {
wx.navigateBack()
},
})