import dayjs from 'dayjs' const app = getApp() Page({ data: { popupShow: false, popupType: 'popup5', // 绑定医生弹窗 popupParams: { position: 'bottom', } as any, pageShow: false, empty1: false, empty2: false, empty3: false, errorMsg: '', Timestamp: '', doc: '1', id: '', detail: {} as any, showShare: false, fileIcon: { pdf: 'file-icon1', doc: 'file-icon2', docx: 'file-icon3', pptx: 'file-icon4', xls: 'file-icon5', xlsx: 'file-icon6', ppt: 'file-icon7', none: 'file-icon8', }, }, onLoad(options) { this.setData({ id: options.id, }) app.waitLogin({ type: [2] }).then(() => { app.mpBehavior({ PageName: 'PG_LibraryDetails' }) app.oldMpBehavior({ PositionId: '1', OperateType: '1', OperateId: options.id as string }) this.getDetail() }) }, getDetail() { wx.ajax({ method: 'GET', url: '?r=xd/doctor/index/get-material-detail', data: { Id: this.data.id, }, showMsg: false, }) .then((res) => { if (res.ContentType == '4') { wx.hideShareMenu() wx.offCopyUrl() wx.setNavigationBarTitle({ title: '通知详情页', }) } this.setData({ pageShow: true, detail: { ...res, PublishTime: dayjs(res.PublishTime).format('YYYY-MM-DD'), }, showShare: res.ContentType !== '4', }) }) .catch((err) => { const { errorCode, errorMsg } = err.data.data const empty1 = errorCode === '1' const empty2 = errorCode === '2' this.setData({ pageShow: false, errorMsg, empty1, empty2, empty3: !empty1 && !empty2, }) }) }, handlePopup(e) { const { index } = e.currentTarget.dataset this.setData({ popupShow: true, popupType: 'popup5', popupParams: { position: 'bottom', index, }, }) }, handlePopupOk() { const { popupType } = this.data if (popupType === 'popup5') { this.handleDownload() this.handlePopupCancel() } }, handlePopupCancel() { this.setData({ popupShow: false, }) }, handleDownload() { const { detail, popupParams: { index }, } = this.data const params = detail.FileList[index] wx.showLoading({ title: '加载中', mask: true, }) app.oldMpBehavior({ PositionId: '1', OperateType: '2', OperateId: detail.Id as string }) wx.downloadFile({ url: params.FileUrl, filePath: `${wx.env.USER_DATA_PATH}/${params.FileName}`, success: (res) => { if (res.statusCode === 200) { wx.openDocument({ showMenu: true, filePath: res.filePath, success: () => { wx.hideLoading() }, fail: (err) => { wx.showToast({ title: '下载文件失败', icon: 'none', }) wx.hideLoading() }, }) } else { wx.hideLoading() wx.showToast({ title: '下载文件失败', icon: 'none', }) } }, fail(err) { wx.hideLoading() wx.showToast({ title: '下载文件失败', icon: 'none', }) }, }) }, handleBackHome() { wx.reLaunch({ url: '/pages/home/index', }) }, onShareAppMessage() { app.mpBehavior({ PageName: 'BTN_LibraryDetailsShare' }) const { Title, CoverImgUrl, Id } = this.data.detail app.oldMpBehavior({ PositionId: '1', OperateType: '3', OperateId: Id as string }) return { title: Title, path: `/pages/informationDetail/index?id=${Id}`, imageUrl: CoverImgUrl, } }, }) export {}