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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import { parseLedgerStat,parseSelfPatrol, refreshLedgerStatus } from '../../../../model/ledger';
const selfpatrolservice = require('../../../../service/selfpatrolservice');
const moment = require('../../../../utils/moment.min');
const app = getApp();
 
Component({
  properties: {},
 
  offsetTopList: [],
  data: {
    refresh: false,
    sideBarIndex: 0,
    scrollTop: 0,
    categories: [
      // {
      //   label: '选项五',
      //   title: '标题五',
      //   badgeProps: {
      //     count: 8,
      //   },
      //   items: [],
      // },
    ],
  },
 
  lifetimes: {
    attached: function () {
      this.fetchSelfPatrolTask();
    },
  },
 
  // pageLifetimes: {
  //   show: function () {
  //     this.fetchSelfPatrolTask();
  //   },
  // },
 
  methods: {
    fetchSelfPatrolTask() {
      const date = moment().format('YYYY-MM-DD');
      selfpatrolservice.getTask(app.globalData.accessToken.userId, date, {
        success: res => {
          const categories = res.data.map(item => {
            item.deadline = moment(item.spDeadline).format('YYYY-MM-DD HH时');
            return {
              label: moment(item.spCreateTime).format('MM月DD日'),
              // title: '标题五',
              taskId: item.spGuid,
              badgeProps: {
                dot: item.spTaskStatus == 1,
              },
              items: [],
              task: item,
            };
          });
          this.setData({ sideBarIndex: 0 });
          if (categories.length > 0) {
            const { taskId } = categories[0];
            this.fetchTaskRecord(taskId, 0);
          }
          this.setData({ categories, refresh: false });
        },
      });
    },
 
    fetchTaskRecord(taskId, index) {
      selfpatrolservice.getTaskRecord(taskId, {
        success: res => {
          let r = parseSelfPatrol(res.data);
          this.setData({
            [`categories[${index}].items`]: r.items[0],
          });
        },
      });
    },
 
    onSideBarChange(e) {
      const { value } = e.detail;
      const { categories } = this.data;
      const { taskId } = categories[value];
      this.fetchTaskRecord(taskId, value);
      this.setData({ sideBarIndex: value });
    },
 
    gotoLedgerDetail(e) {
      var i = e.currentTarget.dataset.index.split(',');
      var indexGroup = [parseInt(i[0]), parseInt(i[1])];
      const item = this.data.categories[indexGroup[0]];
      const { taskId } = item;
      var ledger = item.items[indexGroup[1]];
 
      var that = this;
      wx.navigateTo({
        url: '/pages/mLedger/ledgerupload/ledgerupload',
        events: {
          uploadOver: function (data) {
            let i = data.indexGroup;
            const item = that.data.categories[indexGroup[0]];
            let s = item.items[indexGroup[1]];
            s.upLoad = true;
            refreshLedgerStatus(s);
            that.setData({
              [`categories[${indexGroup[0]}].items[${indexGroup[1]}]`]: s,
            });
          },
        },
        success: res => {
          // 通过 eventChannel 向被打开页面传送数据
          res.eventChannel.emit('acceptDataFromOpenerPage', {
            ledger: ledger,
            indexGroup: indexGroup,
            type: 1,
            taskId: taskId,
            barTitle: '上传应急自巡查',
          });
        },
      });
    },
  },
});