riku
2024-11-13 48145f787eda81815f653ad21161a60e89b6a303
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
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() {},
  },
});