riku
2023-11-29 9b09d13712c0c005891450a3bf4b6d848ec0ff37
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
// 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
    });
  },
})