import dayjs from 'dayjs' const app = getApp() const licia = require('miniprogram-licia') Page({ data: { today: dayjs().format('YYYY年MM月DD日 dddd'), configList: [], infoList: [] as any, zdUserInfo: {} as any, anyWhere: false, regGuide: true, isLogin: 1, qolDetail: {}, hormoneDetail: { recordId: '' }, adlList: [], adlNum: '', adlNewRecord: {} as any, liveList: [], liveStatus: app.globalData.liveStatus, liveDownList: [], // toastShow: true, // toastType: "doubleStandards", // toastType: "healthCare", // toastType: "aldAlert", // toastType:"dedicatedDoctor", // toastType: 'public-toast', // toastType: 'drug-guide', toastShow: false, toastType: '', toastParams: {} as any, sliderTop: 0, unreadCount: 0, options: {} as any, }, onLoad(options) { const systemInfo = wx.getSystemInfoSync() if (options.visitors === '1') { wx.showToast({ title: '未完成注册,登录失败', icon: 'none', }) } app.zdGetTheme().then((res) => { this.setData({ theme: res, }) }) this.setData({ sliderTop: systemInfo.screenHeight - 160, options, }) }, onShow() { app.waitLogin({ type: [0, 1] }).then(() => { app.mpBehavior({ PageName: 'PG_PatientHome' }) this.setData({ anyWhere: app.globalData.anyWhere, isLogin: app.globalData.isLogin, }) if (this.data.options.es === '201501') { app.globalData.IsAliQiWei = 1 this.setData({ options: {}, }) } app.getZdUserInfo(this, true, (zdUserInfo) => { this.setData({ zdUserInfo, }) if (zdUserInfo.ExclusiveDoctorId) { app.mpBehavior({ PageName: 'PG_PatientHomeDoctorCard' }) } this.getPopup() this.getConfig(zdUserInfo) this.getSystemConfig() if (zdUserInfo.ExclusiveDoctorId > 0) { this.getUnreadCount() } }) }) }, async getPopup() { const data1 = await wx.ajax({ method: 'GET', url: '?r=zd/popup/info', data: { Type: 6, }, }) if (data1.showAlert) { this.setData({ toastShow: data1.showAlert, toastType: 'dedicatedDoctor', toastParams: {}, }) } const data2 = await wx.ajax({ method: 'GET', url: '?r=zd/popup/get-popup', data: { type: 1, }, }) if (data2.showAlert) { this.setData({ toastShow: data2.showAlert, toastType: 'drug-guide', toastParams: {}, }) } }, getUnreadCount() { wx.ajax({ method: 'GET', url: '?r=zd/message-interact/get-unread-count', data: {}, }).then((res) => { this.setData({ unreadCount: res, }) }) }, getSystemConfig() { wx.ajax({ method: 'GET', url: '?r=zd/common/get-config', data: {}, }).then((res) => { this.setData({ systemConfig: res, }) }) }, getConfig(zdUserInfo: any) { let UserType = zdUserInfo.UserType if (UserType <= 2) { UserType = 1 } wx.ajax({ method: 'GET', url: `?r=zd/mini-conf/get-config`, data: { userType: UserType > 3 ? 3 : 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 }) } return item }) this.setData({ configList: res, }) res.forEach((item) => { if (item.code == 'article') { this.getInfoList(item.configId) } if (item.code == 'adl') { this.getQol() } if (item.code == 'hormone') { this.getHormone() } if (item.code == 'activity2') { this.getActivity(item.configId, item.showNum, 'liveList') } if (item.code == 'activity1') { this.getActivity(item.configId, item.showNum, 'liveDownList') } }) }) }, setPopupInfo() { wx.ajax({ method: 'POST', url: '?r=zd/popup/update-click-status', data: { Type: 1, Id: this.data.toastParams.Id, }, }).then((_res) => {}) }, getInfoList(configId: string) { wx.ajax({ method: 'GET', url: '?r=zd/pic-text/index-list', data: { count: 0, ConfigId: configId, }, }).then((res) => { this.setData({ infoList: licia.chunk(res.list, 3), }) }) }, getQol() { wx.ajax({ method: 'GET', url: '?r=xd/qol/index', data: {}, }).then((res) => { this.setData({ qolDetail: { ...res.newRecord, CreateDate: dayjs(res.newRecord.CreateTime).format('YYYY-MM-DD'), }, }) }) }, getHormone() { wx.ajax({ method: 'GET', url: '?r=xd/hormone-dosage/get-last-record', data: {}, }).then((res) => { this.setData({ hormoneDetail: { ...res, createTime: dayjs(res.createTime).format('YYYY-MM-DD'), }, }) }) }, getActivity(ConfigId: string, count: number, key: string) { wx.ajax({ method: 'GET', url: '?r=zd/activity/index-list', 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 === 'doctor') { app.mpBehavior({ PageName: 'BTN_PatientHomeDoctorCard' }) } if (code === 'activity2' && url.includes('/patient/pages/live/index')) { app.mpBehavior({ PageName: 'BTN_PatientHomeLiveCard' }) } if (code === 'activity2' && url.includes('/patient/pages/liveDetail/index')) { app.mpBehavior({ PageName: 'BTN_PatientHomeLiveCard' }) } if (code === 'article' && url.includes('/patient/pages/repositoryDetail/index')) { app.mpBehavior({ PageName: 'BTN_PatientHomeContentCard' }) } if (url.includes('loginState')) { url = url + encodeURIComponent(app.globalData.loginState) wx.navigateTo({ url, }) return } wx.navigateTo({ url, fail() { app.globalData.active = active wx.switchTab({ url, }) }, }) }, handleReg() { app.zdPermissionVerification(3, 0, '') }, handleToastOk() { const { toastType } = this.data if (toastType === 'ndrlAldAlert') { wx.navigateTo({ url: '/patient/pages/adl/index?nrdl=1', }) this.handleToastCancel() } else if (toastType === 'doubleStandards') { wx.navigateTo({ url: '/patient/pages/adl/index', }) this.handleToastCancel() } else if (toastType === 'dedicatedDoctor') { wx.ajax({ method: 'POST', url: '?r=zd/popup/close-popup', data: { Type: 6, }, }).then((_res) => { wx.navigateTo({ url: '/patient/pages/interactivePatient/index', }) }) this.handleToastCancel(null, false) } else if (toastType === 'drug-guide') { wx.ajax({ method: 'POST', url: '?r=zd/popup/add-record', data: { type: 1 }, }).then(() => { wx.navigateTo({ url: '/patient/pages/personalInformation/index?bottom=1&submit=1', }) }) this.handleToastCancel(null, false) } }, handleToastCancel(_e = null, sure = true) { const { toastType } = this.data if (toastType === 'doubleStandards' && sure) { wx.ajax({ method: 'POST', url: '?r=zd/popup/close-popup', data: { Type: 5, }, }) } else if (toastType === 'dedicatedDoctor' && sure) { wx.ajax({ method: 'POST', url: '?r=zd/popup/close-popup', data: { Type: 6, }, }) } else if (toastType === 'drug-guide' && sure) { wx.ajax({ method: 'POST', url: '?r=zd/popup/add-record', data: { type: 1 }, }) } this.setData({ toastShow: false, toastType: '', toastParams: '', }) }, handleRegClose() { this.setData({ regGuide: false, }) }, handleToggleSave(e) { const { index, sindex } = e.currentTarget.dataset const list = this.data.infoList const { Id, IsCollect } = list[index][sindex] app.zdPermissionVerification(3, 3, `patient/pages/repository/index`).then(() => { if (IsCollect == 1) { wx.ajax({ method: 'POST', url: '?r=zd/pic-text/cancel-collection', data: { ContentId: Id, }, loading: true, }).then(() => { list[index][sindex].IsCollect = 0 list[index][sindex].CollectionPeopleNum = list[index][sindex].CollectionPeopleNum - 1 wx.showToast({ title: '取消收藏', icon: 'none', }) this.setData({ infoList: list, }) }) } else { wx.ajax({ method: 'POST', url: '?r=zd/pic-text/collection', data: { ContentId: Id, }, loading: true, }).then(() => { wx.showToast({ title: '收藏成功', icon: 'none', }) list[index][sindex].IsCollect = 1 list[index][sindex].CollectionPeopleNum = Number(list[index][sindex].CollectionPeopleNum) + 1 this.setData({ timeToastType: '10', saveLock: true, }) this.setData({ infoList: list, }) }) } }) }, })