日照项目的居民端小程序
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.
 
 
 

306 lines
6.8 KiB

// subpages/work/pages/workguide/detail.js
import {
wxRequestPost,
wxNavigateTo,
wxPreviewImage,
wxPreviewMedia,
wxOpenDocument,
wxDownloadFile,
} from "@utils/promise-wx-api";
import { cookRichContent } from "@utils/tools";
const app = getApp();
Page({
/**
* 页面的初始数据
*/
data: {
current: 0,
iniLoading: false,
tabsList: [
{
id: 0,
name: "办事指南",
},
{
id: 1,
name: "附件目录",
},
],
showContent: false,
guideId: "",
info: {},
swiperH: "calc(100vh - 336rpx);",
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: async function (options) {
this.setData({
guideId: options.guideId,
});
console.log("onLoad", this.data.info);
// this.setData({
// iniLoading: true
// })
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: async function () {
await app.doAfterLogin();
await this.getInfo(this.data.guideId);
this.setData({
iniLoading: true,
});
console.log("onReady", this.data.info);
await this.computedSwiperHeight();
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {},
handleSwiperChange(e) {
const {
detail: { current, source },
} = e;
if (source == "touch") {
this.setData({ current });
}
},
handleTabs(e) {
const id = e.currentTarget.dataset.id;
this.setData({ current: id });
},
handleCell(e) {
const index = e.currentTarget.dataset.index;
let { info } = this.data;
let item = info.moduleList[index];
item.isOpen = !item.isOpen;
this.setData({
info,
});
},
handleOpenLink() {
const { info } = this.data;
let item = info.externalLinks[0];
item.isOpen = !item.isOpen;
this.setData({
info,
});
},
handleLink() {
const { info } = this.data;
wxNavigateTo("/subpages/index/pages/workguide/link", {
url: info.externalLinks[0].externalLink,
});
},
handleCliboard(e) {
const url = e.currentTarget.dataset.url;
wx.setClipboardData({
data: url,
success(res) {
wx.getClipboardData({
success(ress) {
console.log(ress.data); // data
wx.showToast({
title: "复制成功",
icon: "none",
duration: 1500,
});
},
});
},
});
},
// 动态计算轮播高度
computedSwiperHeight() {
let that = this;
let query = wx.createSelectorQuery().in(this);
// const ress = wx.getSystemInfoSync()
query
.select(".detail-header")
.boundingClientRect(function (res) {
console.log("res.height", res);
let h = res.height + "px";
let _h = `calc(100vh - ${h} - 120rpx)`;
that.setData({
swiperH: _h,
});
})
.exec();
},
async handleOpenDocument(e) {
const index = e.currentTarget.dataset.index;
let { info } = this.data;
let item = info.attachmentList[index];
// if (item.type === "doc" || item.type == 'docx' || item.type == 'xlsx' || item.type == 'ppt' || item.type == 'pdf'|| item.type == 'xls'|| item.type == 'PDF') {
// } else
if (item.type === "video") {
const res = await wxPreviewMedia({
sources: [
{
url: item.url,
type: item.type,
},
],
});
if (res.msg === "previewMedia:fail:not supported") {
return wx.showToast({
title: "当前环境不支持查看视频",
icon: "none",
duration: 2000,
});
}
} else if (item.type === "image") {
wxPreviewImage({
urls: [item.url],
});
} else {
if (!item.tempFilePath) {
wx.showLoading({
title: "加载中",
});
const { msg, data } = await wxDownloadFile({
url: item.url,
filePath: wx.env.USER_DATA_PATH + "/" + item.name,
});
wx.hideLoading();
if (msg === "success") {
item.tempFilePath = data.filePath;
}
// this.setData({ showList });
}
wxOpenDocument({
filePath: item.tempFilePath,
showMenu: true,
});
}
},
async handleCollect() {
const { info } = this.data;
const {
data: {
data: { code, data },
},
msg,
} = await wxRequestPost(
"gov/voice/guidecollection/collection",
{
guideId: info.guideId,
},
{
// isMock: true,
// isQuiet: true
}
);
if (msg === "success" && code === 0) {
if (info.collectionFlag == "1") {
wx.showToast({
title: "已取消",
icon: "none",
duration: 1500,
});
info.collectionFlag = "0";
} else {
wx.showToast({
title: "已收藏",
icon: "none",
duration: 1500,
});
info.collectionFlag = "1";
}
this.setData({
info,
});
} else {
wx.showToast({
title: msg,
icon: "none",
duration: 1500,
});
}
},
async getInfo(guideId) {
const {
data: {
data: { code, data },
},
msg,
} = await wxRequestPost(
"gov/voice/guide/detail",
{
guideId,
},
{
// isMock: true,
// isQuiet: true
}
);
if (msg === "success" && code === 0) {
let moduleList = data.moduleList
.filter((item) => item.moduleContent)
.map((n, i) => {
let isOpen = i === 0 ? true : false;
return {
...n,
moduleContent: cookRichContent(n.moduleContent),
isOpen,
};
});
let externalLinks = data.externalLinks.map((n, i) => {
return {
...n,
isOpen: false,
};
});
this.setData({
info: {
...data,
moduleList,
externalLinks,
},
});
} else {
wx.showToast({
title: msg,
icon: "none",
duration: 1500,
});
}
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {},
});