yangyin
2024-08-29 2c41dc4162446120feae6a09ecf1d07118850f88
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
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
// repair/abnormal/index.js
var Constant = require('../../utils/constant.js');
var app = getApp();
var userInfo = app.globalData.userInfo; //登陆用户的相关信息
var CorpID = 0; //登陆用户的公司id
var EmployeeID = 0; //登录用户的员工id
var TaskID = null;
var PointInfo = {};//异常地址坐标
Page({
 
  /**
   * 页面的初始数据
   */
  data: {
    showViewPageName: "main", //控制报修窗口显示和隐藏
    imageList: [], //图片
 
    longitude: 0, //经纬度
    latitude: 0,
    userLocAddress: "", //定位的地址(可能不是报修地址)
 
    currentCorpID: 1,
    currentUserID: 1, //当前用户ID
  },
 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options.TaskID);
    TaskID = options.TaskID
    
    var that = this;
    var userInfo = app.globalData.userInfo;
    if (userInfo) {
      this.setData({
        currentCorpID: userInfo.CorpID,
        currentUserID: userInfo.EmployeeID
      });
    }
    else{
      return;
    }
    var CorpID = userInfo.CorpID; //登陆用户的公司id
    var EmployeeID = userInfo.EmployeeID; //登录用户的员工id
 
    setTimeout(function () {
      //获取当前经纬度
      that.getCurrentLocation();
    }, 1000);
  },
  //表单提交
  formSubmitCb: function (e) {
    this.setData({
      formNote: e.detail.value.Note
    });
    console.log('打印输入的备注的值', this.data.formNote);
 
    if (this.data.longitude == 0 || this.data.latitude == 0) {
      this.getCurrentLocation(); //获取当前经纬度
    }
    var that = this;
    wx.showModal({
      title: '提醒',
      content: '请问是否提交?',
      confirmColor: '#007aff',
      cancelColor: '#007aff',
      confirmText: '是',
      cancelText: '否',
      success: function (resDlg) {
        if (resDlg.confirm) {
          that.formSubmit();
        } else if (resDlg.cancel) {
          //wx.showToast({ title: '点击了 否', icon: 'none' });
        }
      }
    });
  },
  //提交
  formSubmit: function () {
    var that = this;
    wx.request({
      url: "https://api.beng35.com/Inspect/SiteTask/SubmitTaskProblem_Picture",
      method: 'POST',
      data: {
        CorpID: CorpID,
        TaskID: TaskID,
        PointInfo: PointInfo,
        Description: that.data.formNote
      },
      header: {
        'content-type': 'application/json'
      },
      fail: function (err) {
        // wx.showModal({
        //   title: '',
        //   content: '通讯失败',
        // })
      }, //请求失败
      complete: function () {}, //请求完成后执行的函数
      success: function (res) {
        console.log('提交成功');
        
          console.log(res.data)
        var result = res.data;
        if (result.Code != 0) {
          wx.showModal({
            title: '',
            content: result.Message
          });
          return;
        }
 
        var formId = res.data.Data;
        if (formId <= 0) {
          wx.showModal({
            title: '',
            content: "error 236"
          });
          return;
        }
        //console.log(formId)
 
        // if (imageList.length > 0) { //上传图片 
        //   wx.showLoading({
        //     title: '上传中...',
        //     mask: true
        //   });
        //    // 上传图片的方法 that.uploadNextImageFile(formId, 0);
        // } else {
        //   that.submitSuccess(formId);
        //   return;
        // }
      }
    });
  },
  //重置
  formResetCb: function (e) {
    //console.log('form发生了reset事件,携带数据为:', e.detail.value)
    //this.setData({
    //  chosen: ''
    //})
  },
  //赋值选择位置进行 选择当前位置
  tapChooseLocation() {
    let that = this;
    wx.chooseLocation({
      success: function (res) {
        //console.log("chooseLocation",res)
        that.setData({
          addressInfo: res.address
        })
      }
    });
  },
  isShowFilterProductComb() {
    var that = this;
    that.setData({
      isShowFilterProductComb: false
    })
  },
  //图片上传
  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)
        };
        //console.log(imageList, 55)
        that.setData({
          imageList: imageList
        })
      }
    })
  },
  //查看图片
  previewImage: function (e) {
    // console.log(this.data.imageList,e.target.dataset.src)
    var currentSrc = e.target.dataset.src
    wx.previewImage({
      current: currentSrc,
      urls: this.data.imageList
    })
    console.log(currentSrc, this.data.imageList, "ywg")
  },
  //删除图片
  deleteImage: function (e) {
    var that = this;
    var imageList = that.data.imageList;
    var index = e.currentTarget.dataset.index; //获取当前长按图片下标
    // console.log(imageList, 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;
        }
 
      }
    });
  },
  //迭代上传图片
  uploadNextImageFile: function (formId, index_image) {
    var that = this;
    var image_count = this.data.imageList.length;
    if (index_image >= image_count)
      return;
    var url_image = this.data.imageList[index_image];
 
    wx.uploadFile({
      url: Constant.BASE_SERVER_URL + "Repair/Service/RequestFileHandler.ashx?cmd=AddImageFile4MiniPro",
      filePath: url_image,
      formData: {
        FormID: formId,
        DispName: index_image
      },
      name: 'file',
      success: function (res) {
        //console.log(res.data)
        if (index_image < image_count - 1) {
          index_image++;
          that.uploadNextImageFile(formId, index_image); //迭代下一张
          return;
        }
        wx.hideLoading();
        that.submitSuccess(formId);
      }
    });
  },
  //重置
  onReset: function () {
    //   wx.showModal({
    //     title: '提醒',
    //     content: '返回上一页数据将被清空,确定返回吗?',
    //     confirmColor: '#007aff',
    //     cancelColor: '#007aff',
    //     confirmText: '是',
    //     cancelText: '否',
    //     success: function (res) {
    //       if (res.confirm) {
    //         wx.showToast({ title: '点击了 是', icon: 'none' });
    //         // wx.redirectTo({url: '/Report/report_form/report_form',})//指定界面
    //       } else if (res.cancel) {
    //         wx.showToast({ title: '点击了 否', icon: 'none' });
    //       }
    //     }
    //   })
 
    this.setData({
      urgencyLevel: 0
    })
  },
  //加载定位
  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'
        });
        var point= {
          X:resLoc.latitude,
          Y:resLoc.longitude
        }
        PointInfo = point //获取异常经纬度坐标
        console.log('PointInfo',PointInfo);
        
        //
        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({
              addressInfo: result.data.result.address,
              userLocAddress: result.data.result.address
            })
 
          }
        });
      }
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
 
  },
 
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
 
  },
 
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
 
  },
 
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
 
  },
 
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
 
  },
 
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
 
  },
 
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return Constant.Share;
  },
})