信达小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

113 lines
2.6 KiB

3 months ago
import dayjs from 'dayjs';
const app = getApp<IAppOption>();
4 months ago
Page({
data: {
list: [] as any[],
pagination: {
page: 1,
pages: 1,
count: 1,
},
},
3 months ago
onShow() {
3 months ago
app.waitLogin({ type: 2 }).then(() => {
this.getList();
});
},
4 months ago
getList(newPage = 1) {
wx.ajax({
method: 'GET',
3 months ago
url: '?r=xd/doctor/index/get-material-list',
4 months ago
data: {
page: newPage,
ContentType: '3,5',
4 months ago
},
}).then((res) => {
3 months ago
res.list.forEach((item) => {
item.PublishTime = dayjs(item.PublishTime).format('YYYY-MM-DD');
item.FileType = item.FileList[0]?.FileType || '';
3 months ago
});
4 months ago
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);
}
},
3 months ago
handleDetail(e) {
const { id, index } = e.currentTarget.dataset;
const params = this.data.list[index];
if (params.ContentType === '5' && params.FileList[0]) {
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',
});
},
4 months ago
});
},
3 months ago
onShareAppMessage(e) {
if (e.from === 'button') {
const { Title, CoverImgUrl, Id } = e.target.dataset.params;
app.mpBehavior({ PositionId: '2', OperateType: '3', OperateId: Id });
return {
title: Title,
path: `/pages/informationDetail/index?id=${Id}`,
imageUrl: CoverImgUrl,
};
}
return {};
},
4 months ago
});
export {};