const app = getApp() Page({ data: { popupShow: false, popupType: '', popupParams: { position: 'bottom', } as any, userInfo: {} as any, days: 0, cateList: [] as Array<{ CateId: string; CateName: string }>, activeCateId: '', picTextList: [] as Array, pagination: { page: 1, pages: 1, count: 0, }, videoList: [] as Array, configList: [] as Array, sectionList: [] as Array<{ code: string; visible: boolean }>, moduleVisible: { health: true, 'spread1': true, 'video-big': true, 'spread2': true, 'qiye-wx': true, 'education': true, } as Record, }, onLoad() { app.waitLogin({ type: 'any' }).then(() => { this.getMyInfo() this.getCateList() this.getList() this.getVideoList() this.getConfig() }) }, onShow() { if (app.globalData.loginState) { this.getMyInfo() } }, getConfig() { wx.ajax({ method: 'GET', url: `?r=psvt/mini-conf/get-config`, data: {}, }).then((res: any) => { const list = res || [] list.forEach((item: any) => { if ( (item.code === 'spread1' || item.code === 'spread2' || item.code === 'serviceConf') && item.subList ) { item.subList = item.subList.filter((subItem: any) => subItem.showStatus == 1) } }) const moduleVisible: Record = {} as any list.forEach((item: any) => { moduleVisible[item.code] = item.showStatus == 1 }) const sectionCodes = ['health', 'spread1', 'video-big', 'spread2'] const sectionList = sectionCodes .map((code) => { const conf = list.find((item: any) => item.code === code) return { code, visible: conf ? conf.showStatus == 1 : false } }) .sort((a, b) => { const aSeq = list.find((item: any) => item.code === a.code)?.sequence || 0 const bSeq = list.find((item: any) => item.code === b.code)?.sequence || 0 return Number(aSeq) - Number(bSeq) }) this.setData({ configList: list, moduleVisible, sectionList }) }) }, getMyInfo() { wx.ajax({ method: 'GET', url: '?r=psvt/patient/my-info', }).then((res: any) => { let days = 0 if (res.firstOpenTime) { const first = new Date(res.firstOpenTime.replace(/-/g, '/')) const now = new Date() days = Math.max(1, Math.ceil((now.getTime() - first.getTime()) / (1000 * 60 * 60 * 24))) } this.setData({ userInfo: res, days, }) }) }, getCateList() { wx.ajax({ method: 'GET', url: '?r=psvt/pic-text/cate-list', }).then((res: any) => { this.setData({ cateList: res || [], }) }) }, getList(page = 1, cateId = '', append = false) { const params: any = { page, count: 10, } if (cateId) { params.CateId = cateId } wx.ajax({ method: 'GET', url: '?r=psvt/pic-text/list', data: params, }).then((res: any) => { const list = res.list || [] this.setData({ picTextList: append ? this.data.picTextList.concat(list) : list, pagination: { page: res.page || 1, pages: res.pages || 1, count: Number(res.count) || 0, }, }) }) }, getVideoList() { wx.ajax({ method: 'GET', url: '?r=psvt/video/list', data: { page: 1, count: 10 }, }).then((res: any) => { this.setData({ videoList: res.list || [], }) }) }, handleCateTap(e: any) { const { cateid } = e.currentTarget.dataset this.setData({ activeCateId: cateid || '', }) this.getList(1, cateid || '') }, handleLoadMore() { const { pagination, activeCateId } = this.data if (pagination.page < pagination.pages) { this.getList(pagination.page + 1, activeCateId, true) } }, handlePopupOk() { const { popupType } = this.data if (popupType === 'argument') { wx.ajax({ method: 'POST', url: '?r=wtx/user/agree-guest-privacy', data: { WorkerId: app.globalData.scene?.workerId || '', }, }).then(() => { this.setData({ popupShow: false, popupType: '', popupParams: {}, }) const waitBindDoctorId = app.globalData.waitBindDoctorId if (waitBindDoctorId) { this.handleBindDoctor(waitBindDoctorId) } }) } if (popupType === 'conformBindDoctorConform') { this.setData({ popupShow: false, }) wx.ajax({ method: 'POST', url: '?r=wtx/account/wait-bind-doctor', data: { doctorId: app.globalData.waitBindDoctorId, }, }).then(() => { wx.navigateTo({ url: `/patient/pages/login/index`, }) }) } }, handlePopupCancel() { const { popupType } = this.data if (popupType === 'argument') { wx.exitMiniProgram() } if (popupType === 'conformBindDoctorConform') { this.setData({ popupShow: false, }) wx.ajax({ method: 'POST', url: '?r=wtx/account/wait-bind-doctor', data: { doctorId: app.globalData.waitBindDoctorId, }, }).then(() => { app.globalData.waitBindDoctorId = '' }) } }, handleWechatWork() { wx.navigateTo({ url: '/pages/wechatWork/index', }) }, onReachBottom() { this.handleLoadMore() }, handleBackTop() { wx.pageScrollTo({ scrollTop: 0 }) }, handleVideoMore() { wx.navigateTo({ url: '/pages/videoList/index', }) }, handleVideoDetail(e) { const { index } = e.currentTarget.dataset const { videoList } = this.data const { Id } = videoList[index] wx.navigateTo({ url: `/pages/videoDetail/index?id=${Id}&index=${index}`, }) }, handlePicTextDetail(e) { const { index } = e.currentTarget.dataset const { picTextList } = this.data const { Id, Type } = picTextList[index] if (Type == 1) { wx.navigateTo({ url: `/pages/articleDetail/index?id=${Id}`, }) } else if (Type == 2) { wx.navigateTo({ url: `/pages/articleVideoDetail/index?id=${Id}`, }) } }, handleGift() { wx.showToast({ title: '功能开发中,敬请期待', icon: 'none', }) }, }) export {}