// pages/mExtra/pSupervisionchange/pSupervisionchange.js import moment from '../../../utils/moment.min' import bLoadingStatus from '../../../base/behaviors/bLoadingStatus' import bLoadingToast from '../../../base/behaviors/bLoadingToast' const taskservice = require('../../../service/taskservice') Page({ behaviors: [bLoadingStatus, bLoadingToast], /** * 页面的初始数据 */ data: { enable: false, reason: '该链接已超时失效', subTask: {}, problemList: [], previewImageUrls:[], previewCurrent: 0, showPreview: false, }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { console.log(options); if (options.time) { let now = new Date() now = now.getTime() if (now - options.time <= (1000 * 60 * 60 * 24 * 2)) { this.setData({ enable: true, }) if (options.subTaskId) { this.sId = options.subTaskId this.getSubtask() this.getProblems() } else { this.setData({ enable: false, reason: '该巡查任务已失效', }) } } } // this.sId = 'TUIk7Jf3UKmaZM90' // this.getSubtask() // this.getProblems() }, onShow() { wx.hideHomeButton({ success: (res) => {}, fail: (res) => {}, complete: (res) => {}, }) }, getSubtask() { var that = this taskservice.getSubtask(this.sId, { success(data) { data.planstarttime = moment(data.planstarttime).format('YYYY年MM月DD日') that.setData({ subTask: data }) }, fail(err) { }, complete() { } }) }, getProblems() { var that = this this.setData({loading: true}) taskservice.getProblem(this.sId, { success(data) { data.forEach(d => { d.proPics = [] d.changePics = [] if (d.mediafileList) { d.mediafileList.forEach(m => { const pic = taskservice.imgUrl + m.extension1 + m.guid + '.jpg' if (m.ischanged) { d.changePics.push(pic) } else { d.proPics.push(pic) } }); } }); that.setData({ problemList: data }) }, fail(err) { that.setData({ problemList: [] }) }, complete() { that.setData({ loading: false }) } }) }, changeProblem(e) { const index = e.currentTarget.dataset.index; const pro = this.data.problemList[index] wx.navigateTo({ url: '/pages/mExtra/pSupervisionchangeDetail/pSupervisionchangeDetail', events: { uploadOver: (data) => { console.log(data); setTimeout(() => { this.getProblems() }, 1000); } }, success: (res) => { res.eventChannel.emit('acceptDataFromOpenerPage', { data: [pro], index: index }) }, }) }, //图片放大预览 previewImage(e) { const {index, type} = e.currentTarget.dataset; const previewImageUrls = [] const pro = this.data.problemList[index[0]] if (type == 'pro') { pro.proPics.forEach(p => { previewImageUrls.push(p) }); } else { pro.changePics.forEach(p => { previewImageUrls.push(p) }); } this.setData({ previewImageUrls, previewCurrent: index[1], showPreview: true, title: pro.problemname }); }, })