forked from nsjcy/frontEnd/nsjcy

liuwh
2020-06-09 5a887acf1924950715086633d329db045223b5c4
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
// pages/progressQuery/progressQuery.js
const app = getApp();
var Validator = require("../../utils/validate.tools.js");
const verify = Validator.Validator;
Page({
 
  /**
   * 页面的初始数据
   */
  data: {
    contantType: ['电话号码', 'QQ', '电子邮箱'],
    user: app.globalData.imgUrl + '/image/user.svg',
    add: app.globalData.imgUrl + '/image/add.svg',
    del: app.globalData.imgUrl + '/image/del.svg',
    videoIcon: app.globalData.imgUrl + '/image/video.png',
    disabled: false,
    id: '',
    picType: '',
    evalList: {},
    picturesInfo: {},
    ReplyLogs: [],
    showType: 0
  },
 
  inputChange: function(e) {
    var name = e.currentTarget.dataset.name;
    this.setData({
      picturesInfo: {
        ...this.data.picturesInfo,
        [name]: e.detail.value
      }
    })
 
  },
  selectChange: function(e) {
    this.setData({
      "showType": e.detail.value,
    })
  },
  //选择地址
  chooseLocation: function(e) {
    var status = e.currentTarget.dataset.status;
    var that = this;
    if (status == 0) {
      wx.chooseLocation({
        success: function(res) {
          that.setData({
            picturesInfo: {
              ...that.data.picturesInfo,
              address: res.address
            }
          })
        },
      })
    } else {}
  },
 
  onLoad: function(option) {
    var that = this;
    console.log(option.type)
    this.setData({
      id: option.id,
      picType: option.type
    })
    var userinfo = wx.getStorageSync("user");
    wx.getLocation({
      success: function(res) {
        var url = "";
        if (that.data.id == 'new') {
          url = app.globalData.url + '/api/v1/pictures/find?id=' + that.data.id + '&flag=WX&lat=' + res.latitude + '&lng=' + res.longitude;
        } else {
          url = app.globalData.url + '/api/v1/pictures/find?id=' + that.data.id + '&flag=WX';
        }
        wx.request({
          url: url,
          success: function(res) {
            if (res.data.code == 0) {
              var data = res.data.data.pictures;
              var data1 = res.data.data.ReplyLogs || [];
              var status = data.status;
              var disabled = app.judgeDisable(status);
              var attList = data.attList || [];
              var evalList1015 = app.where(attList, {
                associateTypeId: 1015 //图片
              }) || [];
              var evalList1016 = app.where(attList, {
                associateTypeId: 1016 //视频
              }) || [];
              var evalList = {
                evalList1015,
                evalList1016
              };
              for (var i in evalList) {
                evalList[i] = evalList[i].map(({
                  path: pic,
                  id
                }) => ({
                  pic,
                  id
                }))
              }
              that.setData({
                picturesInfo: {
                  ...data,
                  createId: userinfo.id
                },
                disabled: disabled,
                evalList,
                id: data.id,
                showTime: app.formatDate(data.createTime),
                status,
                ReplyLogs:data1
              })
              console.log(that.data.picturesInfo);
            } else {
              wx.showModal({
                title: '提示',
                content: "请求失败!"
              })
            }
          }
        })
        res.latitude,
          res.longitude
 
      }
    })
 
  },
 
  submit: function(e) {
    var picturesInfo = this.data.picturesInfo;
    var status = e.currentTarget.dataset.type;
    picturesInfo.status = status;
    picturesInfo.picType = this.data.picType;
    var showType = this.data.showType;
    var title = '';
    if (status == "1") {
      const {
        evalList1015,
        evalList1016
      } = this.data.evalList;
      if (!picturesInfo.userName) {
        return app.showModal("请填写姓名!");
      }
      if (!picturesInfo.mobile) {
        if (showType == 0) {
          return app.showModal("请填写电话号码!");
        } else if (showType == 2) {
          return app.showModal("请填写电子邮箱!");
        }else{
          return app.showModal("请填写QQ号码!");
        }
       
      } else {
        if (showType == 0) {
          if (!verify.phone(picturesInfo.mobile)) {
            return app.showModal("手机号码格式不正确!")
          }
        } else if (showType == 2) {
          if (!verify.email(picturesInfo.mobile)) {
            return app.showModal("电子邮箱格式不正确!")
          }
        } else {
          if(!verify.length < 5 ){
            return app.showModal("QQ号码长度最少5位!")
          }
        }
      }
      if (!picturesInfo.address) {
        return app.showModal("请填写拍摄地址!");
      }
      if (!picturesInfo.content) {
        return app.showModal("请填写详细内容!");
      }
      if (evalList1015.length == 0 && evalList1016.length == 0) {
        return app.showModal("请上传照片/图片!");
      } 
      if (picturesInfo.idCard && !verify.carIdNumber(picturesInfo.idCard)) {
        return app.showModal("身份证号码格式不正确!")
      }
    }
    var that = this;
    wx.request({
      url: app.globalData.url + '/api/v1/pictures/save',
      data: picturesInfo,
      method: 'POST',
      header: {
        "Content-Type": "application/json"
      },
      success: function(res) {
        if (res.data.code == 0) {
          if (status == 0) {
            title = '保存草稿成功!';
          } else {
            title = '提交成功!';
          }
          wx.showToast({
            title,
            icon: 'success',
            duration: 2000
          })
          setTimeout(function() {
            wx.reLaunch({
              url: '../index/index',
            })
          }, 2000)
        } else {
          wx.showModal({
            title: '提示',
            content: "提交失败!"
          })
        }
      }
    })
  },
  reply: function (e) {
    var that = this;
    var openId = wx.getStorageSync("openId")
    var obj = {
      openId: openId,
      content: that.data.picturesInfo.replyContent,
      busType: 25,
      busId: that.data.id
    };
    wx.request({
      url: app.globalData.url + '/api/v1/pictures/reply',
      data: obj,
      method: 'POST',
      header: {
        "Content-Type": "application/json"
      },
      success: function (res) {
        if (res.data.code == 0) {
          wx.showToast({
            title: '提交回复成功',
            icon: 'success',
            duration: 2000
          })
          setTimeout(function () {
            wx.navigateBack({
              changed: true
            }); //返回上一页
          }, 2000)
        } else {
          wx.showModal({
            title: '提示',
            content: "提交失败!"
          })
        }
      }
    })
  },
  joinVideo: function(e) {
    var that = this;
    app.joinVideo(e, that)
  },
 
  // 删除图片
  clearImg: function(e) {
    var that = this;
    app.clearImg(e, that)
  },
 
  //预览图片
  previewImage: function(e) {
    app.previewImage(e)
  },
 
  //预览视频
  previewVideo: function(e) {
    console.log(e.currentTarget.dataset.src)
    var src = e.currentTarget.dataset.src;
    wx.navigateTo({
      url: '../videoPreview/videoPreview?src=' + src,
    })
  },
 
  goback: function() {
    wx.navigateBack({
      changed: true
    }); //返回上一页
  },
 
  uploadFiles: function(e) {
    var that = this;
    wx.showActionSheet({
      itemList: ['拍照上传', '选择图片', '选择视频'],
      success: function(res) {
        let xindex = res.tapIndex;
        if (xindex == 0 || xindex == 1) {
          app.joinPicture(e, that, 1015)
        } else if (xindex == 2) {
          app.joinVideo(e, that, 1016)
        }
      },
      fail: function(res) {}
    })
  },
})