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.

461 lines
12 KiB

1 month ago
import dayjs from 'dayjs'
const app = getApp<IAppOption>()
const licia = require('miniprogram-licia')
Page({
data: {
configList: [],
bannerList: [] as any[],
4 weeks ago
infoList: [] as any[],
storyList: [] as any[],
1 month ago
userInfo: {} as any,
anyWhere: false,
regGuide: true,
4 weeks ago
greeting: '晚上好',
greetingIcon: 'icon77',
1 month ago
adlList: [],
adlNum: '',
adlNewRecord: {} as any,
liveList: [],
liveStatus: app.globalData.liveStatus,
liveDownList: [],
detail: {},
toastShow: false,
toastType: '',
4 weeks ago
// toastType: 'dedicatedDoctor', // 绑定医生弹窗
1 month ago
toastParams: {} as any,
sliderTop: 0,
unreadCount: 0,
options: {} as any,
firstLogin: '',
3 weeks ago
nextVisitDays: '--',
1 month ago
},
onLoad(options) {
const systemInfo = wx.getSystemInfoSync()
this.setData({
sliderTop: systemInfo.screenHeight - 160,
options,
firstLogin: options.fl,
})
},
onShow() {
app.waitLogin({}).then(() => {
app.mpBehavior({ PageName: 'PG_PATIENTHOME' })
this.setData({
anyWhere: app.globalData.anyWhere,
})
1 month ago
app.getUserInfo(this, true, (userInfo) => {
this.setData({
userInfo,
})
4 weeks ago
this.updateGreeting()
3 weeks ago
this.updateNextVisitDays(userInfo)
1 month ago
if (this.data.firstLogin != '1' || userInfo.EntryFourPeriod != 1) {
this.getPopup()
} else {
this.setData({
firstLogin: '',
})
}
this.getConfig(userInfo)
this.getSystemConfig()
if (userInfo.ExclusiveDoctorId > 0) {
this.getUnreadCount()
}
if (userInfo.UserType == 4) {
this.getLastRecord()
}
})
})
},
getUnreadCount() {
wx.ajax({
method: 'GET',
4 weeks ago
url: '?r=igg4/message-interact/get-unread-count',
1 month ago
data: {},
}).then((res) => {
this.setData({
unreadCount: res,
})
})
},
getSystemConfig() {
wx.ajax({
method: 'GET',
4 weeks ago
url: '?r=igg4/common/get-config',
1 month ago
data: {},
}).then((res) => {
this.setData({
systemConfig: res,
})
})
},
3 weeks ago
updateNextVisitDays(userInfo: any) {
if (userInfo.NextVisitDate) {
const diff = dayjs(userInfo.NextVisitDate).diff(dayjs(), 'day')
this.setData({ nextVisitDays: diff >= 0 ? diff : 0 })
} else {
this.setData({ nextVisitDays: '--' })
}
},
4 weeks ago
updateGreeting() {
const hour = new Date().getHours()
let greeting = '晚上好'
let greetingIcon = 'icon77'
if (hour >= 6 && hour < 12) {
greeting = '早上好'
greetingIcon = 'icon75'
} else if (hour >= 12 && hour < 18) {
greeting = '下午好'
greetingIcon = 'icon76'
}
if (this.data.userInfo.UserType == 4) {
if (hour >= 6 && hour < 12) {
greetingIcon = 'icon78'
} else if (hour >= 12 && hour < 18) {
greetingIcon = 'icon79'
} else {
greetingIcon = 'icon65'
}
}
this.setData({ greeting, greetingIcon })
},
1 month ago
getLastRecord() {
wx.ajax({
method: 'GET',
4 weeks ago
url: '?r=igg4/medication/last-record',
1 month ago
}).then((res) => {
this.setData({
detail: {
weekName: dayjs(res.InjectionDate).format('ddd'),
days: dayjs().diff(res.InjectionDate, 'day'),
...res,
},
})
})
},
getConfig(userInfo: any) {
let UserType = userInfo.UserType
if (UserType <= 2) {
UserType = 1
}
wx.ajax({
method: 'GET',
4 weeks ago
url: `?r=igg4/mini-conf/get-config`,
1 month ago
data: { userType: UserType },
}).then((res) => {
res = res.map((item: any) => {
if (item.code == 'spread1' || item.code == 'spread2' || item.code == 'serviceConf') {
item.subList = item.subList.filter((subItem) => {
return subItem.showStatus == 1
})
}
if (item.name === 'BANNER-MINIDOVTOR') {
item.subList = item.subList.filter((subItem: any) => {
if (subItem.linkUrl == 'MINIDOCTOR-4.0' && userInfo.EntryFourPeriod != 1) {
return false
}
// if (subItem.linkUrl == 'MINIDOCTOR-1.0') {
// return false
// }
if (subItem.linkUrl == 'MINIDOCTOR' && userInfo.EntryTwoPeriowd != 1) {
return false
}
return true
})
}
return item
})
this.setData({
configList: res,
bannerList: res.find((item: any) => item.code == 'spread1' && item.showStatus == 1)?.subList || [],
1 month ago
})
res.forEach((item) => {
if (item.code == 'article') {
this.getInfoList(item.configId)
}
if (item.code == 'story') {
this.getStoryList(item.configId)
}
if (item.code == 'adl') {
this.getAdl()
}
if (item.code == 'activity2') {
this.getActivity(item.configId, item.showNum, 'liveList')
}
if (item.code == 'activity1') {
this.getActivity(item.configId, item.showNum, 'liveDownList')
}
})
})
},
async getPopup() {
const data3 = await wx.ajax({
method: 'GET',
4 weeks ago
url: '?r=igg4/popup/info',
1 month ago
data: {
Type: 6,
},
})
if (data3.showAlert) {
this.setData({
toastShow: data3.showAlert,
toastType: data3.isRecommend ? 'recommendBindDoctor' : 'dedicatedDoctor',
toastParams: {
...data3.doctorInfo,
},
})
}
},
getInfoList(configId: string) {
wx.ajax({
method: 'GET',
4 weeks ago
url: '?r=igg4/pic-text/index-list',
1 month ago
data: {
count: 0,
ConfigId: configId,
},
}).then((res) => {
this.setData({
infoList: licia.chunk(res.list, 3),
})
})
},
getStoryList(configId: string) {
wx.ajax({
method: 'GET',
4 weeks ago
url: '?r=igg4/story/index-list',
1 month ago
data: {
count: 0,
ConfigId: configId,
},
}).then((res) => {
this.setData({
4 weeks ago
storyList: licia.chunk(res.list, 3),
1 month ago
})
})
},
getAdl() {
wx.ajax({
method: 'GET',
4 weeks ago
url: '?r=igg4/adl/index',
1 month ago
data: {},
}).then((res) => {
const newRecord = res.newRecord
this.setData({
adlList: res.list,
adlNum: res.count,
adlNewRecord: {
days: dayjs().diff(newRecord.CreateTime, 'day'),
...newRecord,
newCreateTime: dayjs(newRecord.CreateTime).format('YYYY-MM-DD'),
},
})
})
},
getActivity(ConfigId: string, count: number, key: string) {
wx.ajax({
method: 'GET',
4 weeks ago
url: '?r=igg4/activity/index-list',
1 month ago
data: { ConfigId, count },
}).then((res) => {
this.setData({
[key]: res.list.map((item) => {
item.EndTimeValue = dayjs(item.EndTime).valueOf()
item.BeginTimeValue = dayjs(item.BeginTime).valueOf()
item.SignUpDeadlineValue = dayjs(item.SignUpDeadline).valueOf()
item.BeginDate = dayjs(item.BeginTime).format('YYYY-MM-DD')
item.EndDate = dayjs(item.EndTime).format('YYYY-MM-DD')
item.isDay = item.BeginDate == item.EndDate
item.BeginHm = dayjs(item.BeginTime).format('HH:mm')
item.EndHm = dayjs(item.EndTime).format('HH:mm')
item.BeginTime = dayjs(item.BeginTime).format('YYYY-MM-DD HH:mm')
item.EndTime = dayjs(item.EndTime).format('YYYY-MM-DD HH:mm')
return item
}),
})
})
},
routerTo(e) {
let { url, active, code } = e.currentTarget.dataset
if (!url) return
if (code === 'adl') {
app.mpBehavior({ PageName: 'BTN_PATIENTHOMEADLMODULE' })
}
if (code === 'drugs') {
app.mpBehavior({ PageName: 'BTN_PATIENTHOMEMEDICATIONMODULE' })
}
if (code === 'story' && url === '/pages/story/index') {
app.mpBehavior({ PageName: 'BTN_PATIENTHOMESTORIESVIEWALL' })
}
if (code === 'story' && url.includes('/pages/publishStoryDetail/index')) {
app.mpBehavior({ PageName: 'BTN_PATIENTHOMESTORYCLICK' })
}
if (code === 'activity2' && url === '/pages/live/index') {
app.mpBehavior({ PageName: 'BTN_PATIENTHOMEONLINEACTIVITIESVIEWALL' })
}
if (code === 'activity2' && url === '/pages/live/index?index=0') {
app.mpBehavior({ PageName: 'BTN_PATIENTHOMEONLINEACTIVITIESMONTHLYPOSTER' })
}
if (code === 'activity2' && url.includes('/pages/liveDetail/index')) {
app.mpBehavior({ PageName: 'BTN_PATIENTHOMEONLINEACTIVITIESCARD' })
}
if (code === 'activity1' && url === '/pages/live/index') {
app.mpBehavior({ PageName: 'BTN_PATIENTHOMEOFFLINEACTIVITIESVIEWALL' })
}
if (code === 'activity1' && url.includes('/pages/liveDetail/index')) {
app.mpBehavior({ PageName: 'BTN_PATIENTHOMEOFFLINEACTIVITIESCARD' })
}
if (code === 'article' && url === '/pages/repository/index') {
app.mpBehavior({ PageName: 'BTN_PATIENTHOMERECOMMENDEDREADINGVIEWALL' })
}
if (code === 'article' && url.includes('/pages/repositoryDetail/index')) {
app.mpBehavior({ PageName: 'BTN_PATIENTHOMERECOMMENDEDREADINGARTICLE' })
}
if (code === 'serviceConf') {
app.mpBehavior({ PageName: 'BTN_PATIENTHOMESERVICE' })
}
if (url === '/pages/interactivePatient/index') {
app.mpBehavior({ PageName: 'BTN_PATIENTHOMEDOCTORCARD' })
}
if (url.includes('loginState')) {
url = url + encodeURIComponent(app.globalData.loginState)
app.permissionVerification(2, 11, `/pages/repository/index`).then(() => {
wx.navigateTo({
url,
})
})
return
}
wx.navigateTo({
url,
fail() {
app.globalData.active = active
wx.switchTab({
url,
})
},
})
},
handleReg() {
app.permissionVerification(3, 0, '')
},
handleMiniDoctor(e) {
const { link } = e.currentTarget.dataset
let period = ''
if (link === 'MINIDOCTOR-1.0') {
period = '2'
}
wx.navigateTo({
url: `/pages/webview/index?period=${period}`,
})
},
handleQuestion() {
app.permissionVerification(2, 11, `/pages/repository/index`).then(() => {
const webviewUrl = encodeURIComponent(
`${app.globalData.url}/zdcare/#/info?loginState=${app.globalData.loginState}`,
)
wx.navigateTo({
url: `/pages/webview/index?url=${webviewUrl}`,
})
})
},
handleToastOk() {
const { toastType } = this.data
4 weeks ago
if (toastType === 'dedicatedDoctor' || toastType === 'recommendBindDoctor') {
1 month ago
wx.ajax({
method: 'POST',
4 weeks ago
url: '?r=igg4/popup/close-popup',
1 month ago
data: {
Type: 6,
},
}).then((_res) => {
if (toastType === 'dedicatedDoctor') {
wx.navigateTo({
url: '/pages/interactivePatient/index',
})
}
app.getUserInfo(this, true)
})
this.handleToastCancel(null, false)
}
},
handleToastCancel(_e = null, sure = true) {
const { toastType } = this.data
4 weeks ago
if ((toastType === 'dedicatedDoctor' || toastType === 'recommendBindDoctor') && sure) {
1 month ago
wx.ajax({
method: 'POST',
4 weeks ago
url: '?r=igg4/popup/close-popup',
1 month ago
data: {
Type: 6,
},
})
app.getUserInfo(this, true)
}
this.setData({
toastShow: false,
toastType: '',
toastParams: '',
})
},
handleMp(e: any) {
const { code } = e.currentTarget.dataset
const PageName = {
spread1: 'BTN_PATIENTHOMEBANNER1',
spread2: 'BTN_PATIENTHOMEBANNER2',
}[code]
app.mpBehavior({ PageName })
},
handleRegClose() {
this.setData({
regGuide: false,
})
},
4 weeks ago
handleArticleView(e: any) {
const { id } = e.currentTarget.dataset
wx.navigateTo({
url: `/pages/repositoryDetail/index?id=${id}`,
})
},
handleArticleSave(e: any) {
const { id, saved } = e.currentTarget.dataset
4 weeks ago
const url = saved ? '?r=igg4/pic-text/cancel-collection' : '?r=igg4/pic-text/collection'
app.permissionVerification(3, 3, `/pages/index/index`, id).then(() => {
wx.ajax({
method: 'POST',
url,
data: {
ContentId: id,
},
loading: true,
}).then(() => {
const { infoList } = this.data
const newList = infoList.map((page: any) =>
3 weeks ago
page.map((item: any) => (item.ArticleId === id ? { ...item, IsCollect: saved ? 0 : 1 } : item)),
4 weeks ago
)
this.setData({ infoList: newList })
wx.showToast({
title: saved ? '已取消收藏' : '收藏成功',
icon: 'none',
})
4 weeks ago
})
})
},
1 month ago
})