import moment from '../../../utils/moment.min'; const taskservice = require('../../../service/taskservice'); const userservice = require('../../../service/userservice'); const app = getApp(); /** * 获取用户被巡查监管任务记录 */ module.exports = Behavior({ properties: {}, data: { userId: app.globalData.accessToken.userId, scene: undefined, startTime: '', endTime: '', subtasks: [], }, lifetimes: { ready: function () { this.init(); }, }, methods: { init() { // 获取最近三个月的起止时间 const endTime = moment().endOf('month'); const startTime = moment().subtract(2, 'month').startOf('month'); this.setData({ startTime: this.timeForamt(startTime), endTime: this.timeForamt(endTime), }); this.fetchScene(); }, timeForamt(time) { if (time == undefined) { return time; } if (typeof time === 'string') { time = moment(time); } return time.format('YYYY-MM-DD HH:mm:ss'); }, /** * 根据用户id从飞羽监管系统中获取对应用户的场景信息 */ fetchScene() { userservice.getSceneByUserId(this.data.userId, { success: data => { // 判断场景信息是否存在 if (data) { this.setData({ scene: data }); this.fetchSubtask(); } else { this._onFetchDone(); } }, fail: err => { this._onFetchDone(); }, complete: () => {}, }); }, /** * 获取企业用户的被巡查任务记录 */ fetchSubtask() { taskservice.getSubtaskByScene( { sceneId: this.data.scene.guid, startTime: this.data.startTime, endTime: this.data.endTime, }, { success: data => { data.forEach(d => { d.stPlanTime = this.timeForamt(d.stPlanTime); }); this.setData({ subtasks: data }); }, fail: err => {}, complete: () => { this._onFetchDone(); }, }, ); }, _onFetchDone() {}, }, });