// pages/mExtra/pSupervisiontask/pSupervisiontask.js import bLoadingStatus from '../../../base/behaviors/bLoadingStatus' import bLoadingToast from '../../../base/behaviors/bLoadingToast' import {sceneTypes2} from '../../../data/sceneTypes' import moment from '../../../utils/moment.min' import $f from "../../../service/baserequest"; const taskservice = require('../../../service/taskservice') Page({ behaviors: [bLoadingStatus, bLoadingToast], /** * 页面的初始数据 */ data: { //场景类型 sceneTypes: [], sIndex: 0, //总任务 taskList: [], tIndex: 0, //子任务 subTaskList: [[], []], //统计 changedSubTask: 0, unChangedSubTask: 0, tabIndex: 0, }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { this.setData({ sceneTypes: sceneTypes2 }) this.getTopTask() }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, onShow() { this.refreshTopMargin() }, onShareAppMessage(e) { console.log(e); if (e.from == 'button') { const i = e.target.dataset.index const subTask = this.data.subTaskList[this.data.tabIndex][i] console.log(subTask); let t = new Date() t = t.getTime() console.log(t); return { title: `[待整改]${subTask.sceneName}`, path: `/pages/mExtra/pSupervisionchange/pSupervisionchange?subTaskId=${subTask.stGuid}&time=${t}`, imageUrl: $f.baseIconUrl + 'res/change_icon.png' } } }, /** * 动态刷新列表顶部外边距 */ refreshTopMargin() { let that = this; let query = this.createSelectorQuery().in(this); //必须要先创建一个查询 query.select('.page__hd').boundingClientRect(function (rect) { that.setData({ topMargin: rect.height + 'px' }); }).exec(); }, /** * 获取总任务 */ getTopTask() { var that = this this.setData({loading: true}) taskservice.getTopTask({ success(data) { that.setData({ taskList: data }) }, fail(err) { that.setData({ taskList: [] }) }, complete() { that.setData({ loading: false }) } }) }, /** * 获取总任务下的子任务统计 */ getSubTaskSummary() { var that = this this.setData({loading: true}) const {sceneTypes, sIndex, taskList, tIndex} = this.data const topTaskId = taskList[tIndex].tguid const sceneTypeId = sceneTypes[sIndex].value taskservice.getSubTaskSummary(topTaskId, sceneTypeId, { success(data) { data.sort((a, b) => { return moment(b.stPlanTime).diff(moment(a.stPlanTime)) }) const subTaskList = [[], []] let changedSubTask = 0 let unChangedSubTask = 0 data.forEach(d => { d.stPlanTime = moment(d.stPlanTime).format('YYYY年MM月DD日') if (d.proNum > 0 && d.proNum > d.changeNum) { subTaskList[0].push(d) unChangedSubTask++ } else { subTaskList[1].push(d) changedSubTask++ } }); that.setData({subTaskList, unChangedSubTask, changedSubTask}) }, fail(err) { that.setData({ subTaskList: [[], []] }) }, complete() { that.setData({ loading: false }) } }) }, selectTab(e) { let i = e.currentTarget.dataset.index this.setData({ tabIndex: i, }) }, bindTaskChange(e) { let t = e.detail.value this.setData({ tIndex: t, }) }, bindSceneTypeChange(e) { let s = e.detail.value this.setData({ sIndex: s, }) } })