import dayjs from 'dayjs' const app = getApp() Page({ data: { list: [] as any[], pagination: { page: 1, pages: 1, count: 1, }, fileLabelIcon: { pdf: 'file-label1', doc: 'file-label2', docx: 'file-label3', pptx: 'file-label4', xls: 'file-label5', xlsx: 'file-label6', ppt: 'file-label7', }, }, onShow() { app.waitLogin({ type: [2] }).then(() => { app.mpBehavior({ doctor:true, PageName: 'PG_LibraryList' }) this.getList() }) }, getList(newPage = 1) { wx.ajax({ method: 'GET', url: '?r=xd/doctor/index/get-material-list', data: { page: newPage, ContentType: '3,5', }, }).then((res) => { res.list.forEach((item) => { item.PublishTime = dayjs(item.PublishTime).format('YYYY-MM-DD') item.FileType = item.FileList[0]?.FileType || '' }) const list = res.page === 1 ? res.list : [...this.data.list, ...res.list] this.setData({ total: res.count, list, pagination: { page: res.page, pages: res.pages, count: res.count, }, }) }) }, onReachBottom() { const { page, pages } = this.data.pagination if (pages > page) { this.getList(page + 1) } }, handleDetail(e) { app.mpBehavior({ doctor:true, PageName: 'BTN_LibraryListContent' }) const { id, index } = e.currentTarget.dataset const params = this.data.list[index] if (params.ContentType === '5' && params.FileList[0]) { app.oldMpBehavior({ PositionId: '1', OperateType: '1', OperateId: id as string }) this.handleFile(params.FileList[0]) } else { wx.navigateTo({ url: `/pages/informationDetail/index?id=${id}`, }) } }, handleFile({ FileUrl, FileName }) { wx.downloadFile({ url: FileUrl, filePath: `${wx.env.USER_DATA_PATH}/${FileName}`, success: (res) => { if (res.statusCode === 200) { wx.openDocument({ showMenu: false, filePath: res.filePath, success: () => { wx.hideLoading() }, fail: () => { 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') { app.mpBehavior({ doctor:true, PageName: 'BTN_LibraryListShare' }) const { Title, CoverImgUrl, Id } = e.target.dataset.params app.oldMpBehavior({ PositionId: '2', OperateType: '3', OperateId: Id }) return { title: Title, path: `/pages/informationDetail/index?id=${Id}`, imageUrl: CoverImgUrl, } } return {} }, }) export {}