yangyin
2024-07-03 e5501ada6eb3794251457f36a11b38c1e98a3d18
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
var Constant = require('../../utils/constant.js');
var app = getApp();
import Request  from "../../utils/api"
Page({
  data: {
    formEntity: {
      ProductResultStatus: 0,
      ProductResultStatusName: "",
 
      ImprovedFeedback: "",
      ResultOperateNote: "",
      ReplacePartInfo: "",
 
      longitude: 0, //经纬度
      latitude: 0,
      userLocAddress: "", //定位的地址(可能不是报修地址)    
 
      imageList: [], //图片 
      taskformid: 0,
 
      currentCorpID: 1,
      currentEmployeeID: 1 //当前用户ID
    },
    imageList: [] //图片 
  },
 
  onLoad: function (options) {
 
    var that = this;
 
    var userInfo = app.globalData.userInfo;
    if (userInfo) {
      this.setData({
        taskformid: options.taskformid,
        currentCorpID: userInfo.CorpID,
        currentEmployeeID: userInfo.EmployeeID
      });
    } else {
      wx.navigateTo({
        url: '/login/login/index',
      });
    }
    //
    setTimeout(function () {
      //获取当前经纬度
      that.getCurrentLocation();
    }, 1000);
 
 
  },
 
 
 
 
  //表单提交
  formSubmit: function (e) {
    var that = this;
    var taskformid = that.data.taskformid;
    if (that.data.longitude == 0 || that.data.latitude == 0) {
      that.getCurrentLocation(); //获取当前经纬度
    }
 
    var formDetail = e.detail.value; //表单所有数据
 
    // console.log("表单数据", formDetail, this.data.ProductResultStatus);
 
    if (formDetail.ProductResultStatusName == null || formDetail.ProductResultStatusName == '') {
      wx.showToast({
        title: '提醒:请选处理方式',
        icon: 'none'
      })
      return;
    }
     Request({
      url: Constant.BASE_SERVER_URL + "Repair/Task/Form/Finish@V1.0",
      method: 'POST',
      data: {
        ID: taskformid,
        Note:that.data.ProductResultStatusName
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success:res=>{
        console.log(res.data,379);
        var result = res.data;
        
        if (result.Code != 0) {
          wx.showModal({
            title: '',
            content: result.message,
          });
          return;
        }
        if(that.data.imageList.length==0){
          that.submitSuccess(taskformid);
          return
        }
        if(that.data.imageList.length>0){
          that.uploadNextImageFile(taskformid,0);
          return
        }
      },
      fail:err=>{
        console.log(err)
      }
     })
   
  },
 
 
  //迭代上传
  uploadNextImageFile: function (taskformid,index_image) {
    //console.log(taskFileId)
    
    var that = this;
    var image_count = this.data.imageList.length;
    if (index_image >= image_count)
      return;
    var url_image = this.data.imageList[index_image];
    let tokenInfo = wx.getStorageSync('AccessToken')
    wx.uploadFile({
      url: Constant.BASE_SERVER_URL + "Repair/Task/Form/UploadFile@V1.0",
      filePath: url_image,
      header:{'Authorization': 'Bearer ' + tokenInfo.Token},
      formData: {
        FormID : taskformid,
      },
      name: 'file',
      success: function (res) { //上传完成
        //  console.log(JSON.parse(res.data),"完成工单")
 
        wx.hideLoading();
 
        that.submitSuccess(taskformid);
 
      }
    });
 
  },
 
  //
  submitSuccess: function (taskFormId) {
    wx.showToast({
      title: "提交成功",
      icon: 'none'
    });
    // wx.navigateBack({
    //   delta: 2
    // });
 
    var pages = getCurrentPages();
    if (pages.length >= 3) {
      //var currPage = pages[pages.length - 1];   //当前页面
      var prevPage = pages[pages.length - 3]; //上上一个页面
      //console.log(prevPage.route)
      if (prevPage) {
        var fn = prevPage.refreshRepairInfo;
        if (typeof fn == "function")
          fn(taskFormId, "finishWork");
        wx.navigateBack({
          delta: 2
        });
      } else {
        wx.navigateBack({
          delta: 2
        });
      }
    } else {
      wx.navigateBack({
        delta: 2
      });
    }
 
    //wx.navigateTo({
    //  url: '/repair/myReport/index'
    //});
  },
 
 
 
  //维修结果下拉
  tapSelProductResult() {
    var that = this;
    var ProductResultStatusName = '';
    var ProductResultStatus = 0;
    wx.showActionSheet({
      itemList: ['维修成功', '无法维修保持现状', '无需维修', '设备报废', '其他状态'],
      success(res) {
        if (res.tapIndex == 0) {
          ProductResultStatusName = "维修成功";
          ProductResultStatus = 1;
        } else if (res.tapIndex == 1) {
          ProductResultStatusName = "无法维修保持现状";
          ProductResultStatus = 2;
        } else if (res.tapIndex == 2) {
          ProductResultStatusName = "无需维修";
          ProductResultStatus = 3;
        } else if (res.tapIndex == 3) {
          ProductResultStatusName = "设备报废";
          ProductResultStatus = 9;
        } else if (res.tapIndex == 4) {
          ProductResultStatusName = "其他状态";
          ProductResultStatus = 10;
        } else {
          return;
        }
        that.setData({
          ProductResultStatusName: ProductResultStatusName,
          ProductResultStatus: ProductResultStatus
        })
      },
      fail(res) {
        console.log(res.errMsg)
      }
    })
  },
 
 
 
 
  //加载定位
  getCurrentLocation: function () {
    var that = this;
    wx.getLocation({
      type: 'gcj02', // 默认为 wgs84 返回 gps 坐标,gcj02 返回可用于 wx.openLocation 的坐标
      success(resLoc) {
        console.log("getCurrentLocation", resLoc);
        if (resLoc.longitude == 0 || resLoc.latitude == 0) { //当前位置信号较弱,请换个位置尝试
          return;
        }
        wx.showToast({
          title: '成功获取当前位置',
          icon: 'none'
        });
        //
        that.setData({
          longitude: resLoc.longitude,
          latitude: resLoc.latitude,
        })
        //发送请求通过经纬度反查地址信息  
        var getAddressUrl = "https://apis.map.qq.com/ws/geocoder/v1/?location=" + resLoc.latitude + "," + resLoc.longitude + "&key=GFDBZ-D3NKX-LNL4Z-TSWGU-RYCE3-4HB3I";
        wx.request({
          url: getAddressUrl,
          success: function (result) {
            //console.log("getAddressUrl", result);
            that.setData({
              userLocAddress: result.data.result.address
            })
 
          }
        });
      }
    });
  },
 
 
 
 
 
  //图片上传
  chooseImage: function () {
    var that = this;
    var imageList = this.data.imageList;
    wx.chooseImage({
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      count: 9, //最多
      success: function (res) {
        var imgPaths = res.tempFilePaths;
        for (var i = 0; i < imgPaths.length; i++) {
          var imgPath = res.tempFilePaths[i];
          imageList.push(imgPath)
        };
        that.setData({
          imageList: imageList
        })
      }
    })
  },
  //查看图片
  previewImage: function (e) {
    var currentSrc = e.target.dataset.src
    wx.previewImage({
      current: currentSrc,
      urls: this.data.imageList
    })
  },
  //删除图片
  deleteImage: function (e) {
    var that = this;
    var imageList = that.data.imageList;
    var index = e.currentTarget.dataset.index; //获取当前长按图片下标
    wx.showModal({
      title: '系统提醒',
      content: '确定要删除此图片吗?',
      success: function (res) {
        if (res.confirm) {
          imageList.splice(index, 1);
        } else if (res.cancel) {
          return false;
        }
        that.setData({
          imageList: imageList
        });
      }
    })
  },
  //一键清空
  onImageDel() {
    var that = this;
    wx.showModal({
      title: '系统提醒',
      content: '确定要删除全部图片吗?',
      success: function (res) {
        if (res.confirm) {
          that.setData({
            imageList: []
          });
        } else if (res.cancel) {
          return false;
        }
 
      }
    });
  },
 
  onShow: function () {},
  /**用户点击右上角分享*/
  onShareAppMessage: function () {
    return Constant.Share;
  },
})