import dayjs from 'dayjs' const app = getApp() const licia = require('miniprogram-licia') Page({ data: { today: dayjs().format('YYYY年MM月DD日 dddd'), qolShow: false, hormoneShow: false, medicalInsuranceShow: false, hospitalMapShow: false, medicalInsuranceJump: false, hospitalMapJump: false, configList: [], infoList: [] as any, zdUserInfo: {} as any, anyWhere: false, regGuide: true, isLogin: 1, qolDetail: {} as any, hormoneDetail: { recordId: '' }, adlList: [], adlNum: '', adlNewRecord: {} as any, liveList: [], liveStatus: app.globalData.liveStatus, liveDownList: [], // toastShow: true, // toastType: "dedicatedDoctor", // toastType: 'medical-guide', // toastType: 'question-toast', // toastType: 'guideEnterInfo', // toastType: 'guideEnterInfoJump', // toastType: 'noteGuide', // toastType: 'followGuide', toastShow: false, toastType: '', toastParams: { close: true } as any, sliderTop: 0, unreadCount: 0, followLatest: null as any, 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, }) }) if (options.jump == '1') { this.setData({ toastShow: true, toastType: 'guideEnterInfoJump', }) } 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() this.getFollowLatest() if (zdUserInfo.ExclusiveDoctorId > 0) { this.getUnreadCount() } }) }) }, async getPopup() { // https://fa0ci3qr2z.feishu.cn/wiki/EBX6woN7xiaartkYkBpcfbYQnfn if (this.data.toastShow) return const data4 = await wx.ajax({ method: 'GET', url: '?r=zd/popup/get-need-popup', data: { type: 1, }, }) if (data4.showAlert) { this.setData({ toastShow: data4.showAlert, toastType: 'guideEnterInfo', toastParams: {}, }) return } const data5 = await wx.ajax({ method: 'GET', url: '?r=zd/popup/get-popup', data: { type: 4, }, }) if (data5.showAlert) { this.setData({ toastShow: data5.showAlert, toastType: 'followGuide', toastParams: { close: true }, }) } const noteGuideShown = wx.getStorageSync('noteGuideShown') if (!noteGuideShown) { this.setData({ toastShow: true, toastType: 'noteGuide', toastParams: { position: 'bottom', close: false }, }) wx.setStorageSync('noteGuideShown', true) return } 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: {}, }) return } const data3 = await wx.ajax({ method: 'GET', url: '?r=zd/popup/get-popup', data: { type: 3, }, }) if (data3.showAlert) { this.setData({ toastShow: data3.showAlert, toastType: 'medical-guide', toastParams: { close: true }, }) } }, getUnreadCount() { wx.ajax({ method: 'GET', url: '?r=zd/message-interact/get-unread-count', data: {}, }).then((res) => { this.setData({ unreadCount: res, }) }) }, getFollowLatest() { wx.ajax({ method: 'GET', url: '?r=xd/follow-up-reminder/latest', data: {}, }).then((res: any) => { if (res && res.nextVisitTime) { const date = dayjs(res.nextVisitTime) const year = date.format('YYYY') this.setData({ followLatest: { ...res, year, yearPrefix: year.slice(0, 2), yearSuffix: year.slice(2), month: date.format('MM'), day: date.format('DD'), week: date.format('dddd'), }, }) } else { this.setData({ followLatest: null }) } }).catch(() => { this.setData({ followLatest: null }) }) }, getSystemConfig() { wx.ajax({ method: 'GET', url: '?r=zd/common/get-config', data: {}, }).then((res) => { this.setData({ systemConfig: res, }) }) }, getConfig(zdUserInfo: any) { // 处理用户类型 const UserType = zdUserInfo.UserType <= 2 ? 1 : Math.min(zdUserInfo.UserType, 3) wx.ajax({ method: 'GET', url: `?r=zd/mini-conf/get-config`, data: { userType: UserType }, }).then((res) => { // 过滤子列表 const processedRes = res.map((item: any) => { if (['spread1', 'spread2', 'serviceConf'].includes(item.code)) { item.subList = item.subList?.filter((subItem: any) => subItem.showStatus == 1) || [] } return item }) // 初始化显示状态 const statusMap = { qolShow: false, hormoneShow: false, medicalInsuranceShow: false, hospitalMapShow: false, medicalInsuranceJump: false, hospitalMapJump: false, } // 处理配置项 processedRes.forEach((item: any) => { const { code, showStatus, configId, showNum, openStatus } = item // 设置显示状态 if (code === 'medicalInsurance' && showStatus == 1) { statusMap.medicalInsuranceShow = true if (openStatus == 1) statusMap.medicalInsuranceJump = true } if (code === 'hospitalMap' && showStatus == 1) { statusMap.hospitalMapShow = true if (openStatus == 1) statusMap.hospitalMapJump = true } if (code === 'adl' && showStatus == 1) { statusMap.qolShow = true } if (code === 'hormone' && showStatus == 1) { statusMap.hormoneShow = true } // 调用对应方法 switch (code) { case 'article': this.getInfoList(configId) break case 'adl': this.getQol() break case 'hormone': this.getHormone() break case 'activity2': this.getActivity(configId, showNum, 'liveList') break case 'activity1': this.getActivity(configId, showNum, 'liveDownList') break } }) this.setData({ configList: processedRes, ...statusMap, }) }) }, 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, isTodayRecord: res.isTodayRecord, CreateDate: dayjs(res.newRecord.CreateTime).format('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('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, status } = e.currentTarget.dataset if (status === false) { wx.showToast({ icon: 'none', title: '功能正在建设中,敬请期待', }) return } 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, }) }, }) }, handleAddQol() { const { qolDetail } = this.data const url = qolDetail.Id && qolDetail.isTodayRecord ? `/patient/pages/qolAdd/index?id=${qolDetail.Id}&edit=1` : `/patient/pages/qol/index` wx.navigateTo({ url, success() { if (qolDetail.isTodayRecord) { wx.showToast({ icon: 'none', title: '每日仅录入1次,您可修改选项', }) } }, }) }, handleHormone() { const { hormoneDetail } = this.data if (hormoneDetail.recordId > 0) { wx.navigateTo({ url: `/patient/pages/hormones/index?id=${hormoneDetail.recordId}`, }) } else { wx.navigateTo({ url: '/patient/pages/hormonesStart/index', }) } }, 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 === 'medical-guide') { wx.ajax({ method: 'POST', url: '?r=zd/popup/add-record', data: { type: 3 }, }).then(() => { wx.navigateTo({ url: '/patient/pages/medical/index', }) }) this.handleToastCancel(null, false) } else if (toastType === 'guideEnterInfo') { wx.ajax({ method: 'POST', url: '?r=zd/popup/close-need-popup', data: { type: 1 }, }).then(() => { wx.navigateTo({ url: '/patient/pages/personalInformation/index', }) this.handleToastCancel(null, false) }) } else if (toastType === 'guideEnterInfoJump') { wx.navigateTo({ url: '/patient/pages/personalInformation/index', }) this.handleToastCancel(null, false) } else if (toastType === 'followGuide') { wx.ajax({ method: 'POST', url: '?r=zd/popup/add-record', data: { type: 4 }, }).then(() => { wx.navigateTo({ url: '/patient/pages/followForm/index', }) }) 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 === 'medical-guide' && sure) { wx.ajax({ method: 'POST', url: '?r=zd/popup/add-record', data: { type: 3 }, }) } else if (toastType === 'guideEnterInfo' && sure) { wx.ajax({ method: 'POST', url: '?r=zd/popup/close-need-popup', data: { type: 1 }, }) } else if (toastType === 'followGuide' && sure) { wx.ajax({ method: 'POST', url: '?r=zd/popup/add-record', data: { type: 4 }, }) } 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, }) }) } }) }, handleQuestionToast(e) { const { type } = e.currentTarget.dataset this.setData({ toastShow: true, toastType: 'question-toast', toastParams: { title: { 1: '生活质量自评', 2: '激素记录', }[type], type, close: true, }, }) }, handleFollow() { wx.navigateTo({ url: '/patient/pages/follow/index', }) }, handleFollowEmpty() { wx.navigateTo({ url: '/patient/pages/followForm/index', }) }, })