import dayjs from 'dayjs'; const app = getApp(); Page({ data: { doc: '1', id: '', detail: {} as any, 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({ 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, }, }).then((res) => { this.setData({ detail: { ...res, PublishTime: dayjs(res.PublishTime).format('YYYY-MM-DD'), }, }); }); }, handleDownload() { const { detail } = this.data; wx.showLoading({ title: '加载中', mask: true, }); app.mpBehavior({ PositionId: '1', OperateType: '1', OperateId: detail.Id as string }); wx.downloadFile({ url: detail.FileUrl, success: (res) => { if (res.statusCode === 200) { wx.openDocument({ filePath: res.tempFilePath, success: () => { wx.hideLoading(); }, fail: (err) => { wx.showToast({ title: '下载文件失败', icon: 'none', }); wx.hideLoading(); }, }); } else { wx.hideLoading(); wx.showToast({ title: '下载文件失败', icon: 'none', }); } }, fail() { wx.hideLoading(); wx.showToast({ title: '下载文件失败', icon: 'none', }); }, }); }, onShareAppMessage(e) { if (e.from === 'button') { const { Title, CoverImgUrl, Id } = this.data.detail; app.mpBehavior({ PositionId: '3', OperateType: '3', OperateId: Id }); return { title: Title, path: `/pages/informationDetail/index?id=${Id}`, imageUrl: CoverImgUrl, }; } return {}; }, }); export {};