forked from nsjcy/frontEnd/nsjcy

LiuWenHaoU
2020-05-18 bd09ddbe5eae5e780393d37b72b4da6d4e92fdb8
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
var qcloud = require('./lib/index');
//app.js
App({
  onLaunch: function() {
    // 展示本地存储能力
    var logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)
  },
  globalData: {
    userInfo: null,
    pageData: {},
    //  url: 'https://nsjcy.hugeinfo.com.cn/nsjc-charge',
    // url: 'http://1p885086k1.iok.la/nsjc-charge',
    //url: 'http://localhost:6060/nsjc-charge',
    imgUrl: 'https://nsjcy.hugeinfo.com.cn/nsjc-charge',
    url: 'http://nsjc.vaiwan.com/nsjc-charge',
    // imgUrl: 'http://nsjc.vaiwan.com/nsjc-charge'
  },
  // 过滤数组
  where: (collection, source) => {
    var sourceKeys = Object.keys(source);
    return collection.filter(function(obj) {
      for (var i = 0; i < sourceKeys.length; i++) {
        if (!obj.hasOwnProperty(sourceKeys[i]) || obj[sourceKeys[i]] !== source[sourceKeys[i]]) {
          return false;
        }
        return true
      }
    })
  },
 
  //控制是否能够编辑
  judgeDisable: function(status) {
    if (status == null || status == 0 || status == 4) {
      return false; //可以
    } else {
      return true; //不可以
    }
  },
 
  //提示弹窗
  showModal: function(warn) {
    wx.showModal({
      title: '提示',
      content: warn
    })
  },
  //添加图片
  joinPicture: function(e, these, associateTypeId, attId) {
    var th = this;
    var index = e.currentTarget.dataset.index;
    var associateTypeId = e.currentTarget.dataset.associatetypeid || associateTypeId;
    var evalListType = 'evalList' + associateTypeId;
    var evalList = these.data.evalList;
    var that = these;
    var attId = attId || these.data.id;
    var imgNumber = evalList[evalListType];
    wx.chooseImage({
      count: 9,
      sizeType: ["original", "compressed"],
      sourceType: ["album", "camera"],
      success: (res) => {
        console.log(res)
        for (var i = 0; i < res.tempFilePaths.length; i++) {
          console.log(res.tempFilePaths[i])
          if (associateTypeId == 1015) {
            th.upload(these, res.tempFilePaths[i], associateTypeId, 'materialsDisk', attId);
          } else {
            th.upload(these, res.tempFilePaths[i], associateTypeId, 'materials', attId);
          }
        }
      },
    })
  },
 
  // 上传视频
  joinVideo: function(e, these, associateTypeId, attId) {
    var th = this;
    var index = e.currentTarget.dataset.index;
    var associateTypeId = e.currentTarget.dataset.associatetypeid || associateTypeId;
    var evalListType = 'evalList' + associateTypeId;
    var evalList = these.data.evalList;
    var that = these;
    var attId = attId || these.data.id;
    wx.chooseVideo({
      sizeType: ["original", "compressed"],
      sourceType: ["album", "camera"],
      success: (res) => {
        th.upload(these, res.tempFilePath, associateTypeId, 'materialsDisk', attId);
      },
    })
  },
  //上传文件
  upload: function(these, path, associateTypeId, way, id) {
    console.log(these)
    console.log(path)
    console.log(associateTypeId)
    console.log(way)
    console.log(id)
    var status = these.data['status'];
    var batch;
    if (status == 4) {
      batch = 1
    } else {
      batch = 0
    }
    console.log(batch)
    wx.showToast({
      icon: "loading",
      title: "正在上传"
    });
    wx.uploadFile({
      url: this.globalData.url + '/api/v1/attachment/' + way, //接口处理在下面有写
      filePath: path,
      name: 'file',
      header: {
        "Content-Type": "multipart/form-data"
      },
      formData: {
        entityId: id,
        associateTypeId: associateTypeId,
        batch
      },
      success: function(res) {
        console.log(res)
        var evalList = these.data.evalList;
        var evalListType = 'evalList' + associateTypeId;
        var data = JSON.parse(res.data)
        console.log(data)
        console.log('path', path)
        console.log('evalList', evalList)
        console.log('associateTypeId', associateTypeId)
        these.setData({
          evalList: {
            ...evalList,
            [evalListType]: evalList[evalListType].concat({
              id: data.data[0].id,
              pic: path
            })
          },
        })
      },
      complete: function() {
        wx.hideToast(); //隐藏Toast
      }
    })
    // }
  },
 
  //删除图片
  clearImg: function(e, these) {
    var id = e.currentTarget.id;
    var index = e.currentTarget.dataset.index;
    var associateTypeId = e.currentTarget.dataset.associatetypeid;
    var evalListType = 'evalList' + associateTypeId;
    var evalList = these.data.evalList;
    var img = evalList[evalListType];
    wx.showToast({
        icon: "loading",
        title: "正在删除"
      }),
      wx.request({
        url: this.globalData.url + '/api/v1/attachment/delete/' + id,
        success: function(res) {
          if (res.data.code == 0) {
            console.log('删除成功!')
          }
        },
        complete: function() {
          wx.hideToast(); //隐藏Toast
        }
      })
    img.splice(index, 1);
    these.setData({
      evalList: {
        ...evalList,
        [evalListType]: img
      }
    })
  },
 
  // 预览图片
  previewImage: function(e) {
    wx.previewImage({
      current: e.currentTarget.dataset.src, // 当前显示图片的http链接
      urls: [e.currentTarget.dataset.src] // 需要预览的图片http链接列表
    })
  },
 
  //转换时间戳
  formatDate: function(ts) {
    var now = new Date(ts);
    var year = now.getFullYear();
    var month = now.getMonth() + 1;
    var date = now.getDate();
    var hour = now.getHours() < 10 ? '0' + now.getHours() : now.getHours();
    var minute = now.getMinutes() < 10 ? '0' + now.getMinutes() : now.getMinutes();
    var second = now.getSeconds();
    return year + "-" + month + "-" + date + " " + hour + ":" + minute;
  },
 
  //转换时间戳
  formatDateday: function(ts) {
    var now = new Date(ts);
    var year = now.getFullYear();
    var month = now.getMonth() + 1;
    var date = now.getDate();
    var hour = now.getHours() < 10 ? '0' + now.getHours() : now.getHours();
    var minute = now.getMinutes() < 10 ? '0' + now.getMinutes() : now.getMinutes();
    var second = now.getSeconds();
    return year + "-" + month + "-" + date;
  },
 
  // 页面正在开发中
  developIng: function() {
    wx.navigateTo({
      url: '../developIng/developIng',
    })
  },
 
  // 判断时间段
  period: function() {
    var now = new Date(),
      hour = now.getHours(),
      word = '';;
    if (hour < 6) {
      word = "凌晨好!"
    } else if (hour < 9) {
      word = "早上好!"
    } else if (hour < 12) {
      word = "上午好!"
    } else if (hour < 14) {
      word = "中午好!"
    } else if (hour < 17) {
      word = "下午好!"
    } else if (hour < 19) {
      word = "傍晚好!"
    } else if (hour < 22) {
      word = "晚上好!"
    } else {
      word = "夜里好!"
    }
    return word;
  },
 
  // 根据身份证获取生日,性别,年龄
  IdCard: function(UUserCard, num) {
    if (num == 1) {
      //获取出生日期
      var birth = UUserCard.substring(6, 10) + "-" + UUserCard.substring(10, 12) + "-" + UUserCard.substring(12, 14);
      return birth;
    }
    if (num == 2) {
      //获取性别
      if (parseInt(UUserCard.substr(16, 1)) % 2 == 1) {
        //男
        return 1;
      } else {
        //女
        return 2;
      }
    }
    if (num == 3) {
      //获取年龄
      var myDate = new Date();
      var month = myDate.getMonth() + 1;
      var day = myDate.getDate();
      var age = myDate.getFullYear() - UUserCard.substring(6, 10) - 1;
      if (UUserCard.substring(10, 12) < month || UUserCard.substring(10, 12) == month && UUserCard.substring(12, 14) <= day) {
        age++;
      }
      return age;
    }
  },
  getPermission: function(url) {
    wx.getLocation({
      success: function(res) {
        wx.navigateTo({
          url,
        })
      },
      fail: function() {
        wx.getSetting({
          success: function(res) {
            var statu = res.authSetting;
            if (!statu['scope.userLocation']) {
              wx.showModal({
                title: '是否授权当前位置',
                content: '需要获取您的地理位置,请确认授权,否则地图功能将无法使用',
                success: function(tip) {
                  if (tip.confirm) {
                    wx.openSetting({
                      success: function(data) {
                        if (data.authSetting["scope.userLocation"] === true) {
                          wx.showToast({
                            title: '授权成功',
                            icon: 'success',
                            duration: 1000
                          })
                          //授权成功之后,再调用chooseLocation选择地方
                          wx.getLocation({
                            success: function(res) {
                              wx.navigateTo({
                                url,
                              })
                            },
                          })
                        } else {
                          wx.showToast({
                            title: '授权失败',
                            icon: 'success',
                            duration: 1000
                          })
                        }
                      }
                    })
                  }
                }
              })
            }
          },
          fail: function(res) {
            wx.showToast({
              title: '调用授权窗口失败',
              icon: 'success',
              duration: 1000
            })
          }
        })
      }
    })
  }
})