Browse Source

feat:修复小程序巡检报告不能预览bug

master
zhaobing’ 2 years ago
parent
commit
693a8124f7
  1. 272
      weapp/package/inspectionReport/inspectionReport.js

272
weapp/package/inspectionReport/inspectionReport.js

@ -5,158 +5,158 @@ const moment = require("../../utils/moment");
Page({ Page({
/** /**
* 页面的初始数据 * 页面的初始数据
*/ */
data: { data: {
structures: [], // 结构物 structures: [], // 结构物
struLoading: false, struLoading: false,
curStruId: 'all', // 选中结构物id curStruId: 'all', // 选中结构物id
startTime: new Date().getTime(), startTime: new Date().getTime(),
endTime: new Date().getTime(), endTime: new Date().getTime(),
formatStartTime: moment(new Date().getTime()).format('YYYY-MM-DD'), formatStartTime: moment(new Date().getTime()).format('YYYY-MM-DD'),
formatEndTime: moment(new Date().getTime()).format('YYYY-MM-DD'), formatEndTime: moment(new Date().getTime()).format('YYYY-MM-DD'),
report: [], // 巡检报告 report: [], // 巡检报告
}, },
onClose(e) { onClose(e) {
// 获取报告 // 获取报告
this.getPatrolReport(); this.getPatrolReport();
}, },
onStruChange(e) { onStruChange(e) {
if (e.detail) { if (e.detail) {
this.setData({ this.setData({
curStruId: e.detail curStruId: e.detail
}) })
} }
}, },
// 时间选择 // 时间选择
onStartTimeChange(event) { onStartTimeChange(event) {
this.setData({ this.setData({
startTime: event.detail, startTime: event.detail,
formatStartTime: moment(event.detail).format('YYYY-MM-DD') formatStartTime: moment(event.detail).format('YYYY-MM-DD')
}); });
}, },
onEndTimeChange(event) { onEndTimeChange(event) {
this.setData({ this.setData({
endTime: event.detail, endTime: event.detail,
formatEndTime: moment(event.detail).format('YYYY-MM-DD'), formatEndTime: moment(event.detail).format('YYYY-MM-DD'),
}); });
}, },
download(e) { download(e) {
const { url } = e.currentTarget.dataset; const { url } = e.currentTarget.dataset;
wx.showLoading({ title: '下载中...' }); wx.showLoading({ title: '下载中...' });
wx.downloadFile({ wx.downloadFile({
url: getApp().globalData.imgUrl + url, url: getApp().globalData.imgUrl + url,
success(downloadRes) { success(downloadRes) {
wx.hideLoading();
console.log('downloadRes',downloadRes)
if (downloadRes.statusCode === 200) {
const filePath = downloadRes.tempFilePath;
wx.openDocument({
filePath:getApp().globalData.imgUrl + url,
showMenu: true,
success: function (res) {
console.log('打开文档成功');
},
fail: function (error) {
wx.hideLoading(); wx.hideLoading();
console.error('打开文档失败', error); if (downloadRes.statusCode === 200) {
} const filePath = downloadRes.tempFilePath;
}) wx.openDocument({
filePath,
showMenu: true,
fileType:url.includes('xlsx')?'xlsx':url.includes('docx')?'docx':'',
success: function (res) {
console.log('打开文档成功');
},
fail: function (error) {
wx.hideLoading();
console.error('打开文档失败', error);
}
})
}
}
})
},
getPatrolReport() {
const { curStruId, formatStartTime, formatEndTime } = this.data;
const params = {
projectId: curStruId === 'all' ? '' : curStruId,
startTime: formatStartTime + ' 00:00:00',
endTime: formatEndTime + ' 23:59:59',
} }
} wx.showLoading({ title: '查询中...' });
}) Request.get(getPatrolReport(params)).then(res => {
}, wx.hideLoading();
this.setData({
getPatrolReport() { report: res.rows.map(r => {
const { curStruId, formatStartTime, formatEndTime } = this.data; const fileName = r.excelPath.substring(r.excelPath.lastIndexOf('/') + 1);
const params = { return { ...r, fileName, inspectTm: moment(r.inspectTm).format('YYYY-MM-DD HH:mm:ss') }
projectId: curStruId === 'all' ? '' : curStruId, })
startTime: formatStartTime + ' 00:00:00', })
endTime: formatEndTime + ' 23:59:59',
}
wx.showLoading({ title: '查询中...' });
Request.get(getPatrolReport(params)).then(res => {
wx.hideLoading();
this.setData({
report: res.rows.map(r => {
const fileName = r.excelPath.substring(r.excelPath.lastIndexOf('/') + 1);
return { ...r, fileName, inspectTm: moment(r.inspectTm).format('YYYY-MM-DD HH:mm:ss') }
}) })
}) },
})
}, getStructuresList() {
this.setData({ struLoading: true });
getStructuresList() { Request.get(getStructuresList()).then(res => {
this.setData({ struLoading: true }); this.setData({
Request.get(getStructuresList()).then(res => { struLoading: false,
this.setData({ structures: [
struLoading: false, { text: '全部', value: 'all' },
structures: [ ...res.rows.map(s => ({ text: s.name, value: s.id }))
{ text: '全部', value: 'all' }, ]
...res.rows.map(s => ({ text: s.name, value: s.id })) }, () => { this.getPatrolReport(); })
] })
}, () => { this.getPatrolReport(); }) },
})
},
/** /**
* 生命周期函数--监听页面加载 * 生命周期函数--监听页面加载
*/ */
onLoad(options) { onLoad(options) {
this.getStructuresList(); this.getStructuresList();
}, },
/** /**
* 生命周期函数--监听页面初次渲染完成 * 生命周期函数--监听页面初次渲染完成
*/ */
onReady() { onReady() {
}, },
/** /**
* 生命周期函数--监听页面显示 * 生命周期函数--监听页面显示
*/ */
onShow() { onShow() {
}, },
/** /**
* 生命周期函数--监听页面隐藏 * 生命周期函数--监听页面隐藏
*/ */
onHide() { onHide() {
}, },
/** /**
* 生命周期函数--监听页面卸载 * 生命周期函数--监听页面卸载
*/ */
onUnload() { onUnload() {
}, },
/** /**
* 页面相关事件处理函数--监听用户下拉动作 * 页面相关事件处理函数--监听用户下拉动作
*/ */
onPullDownRefresh() { onPullDownRefresh() {
}, },
/** /**
* 页面上拉触底事件的处理函数 * 页面上拉触底事件的处理函数
*/ */
onReachBottom() { onReachBottom() {
}, },
/** /**
* 用户点击右上角分享 * 用户点击右上角分享
*/ */
onShareAppMessage() { onShareAppMessage() {
} }
}) })
Loading…
Cancel
Save