王飞
2025-01-23 99365608dec6eade7d645a91fb0f2205a332d1f1
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
375
376
377
378
379
380
381
382
383
384
385
386
387
var req_url = getApp().globalData.base_url;
var Public_array = []; //全局公共图片数组
Page({
    /**
     * 页面的初始数据
     */
    data: {
        sign:'',
        img:'',
        name: "",
        number: '',
        radio: '1',
        reason: '',
        bumen: '',
        opinion: '',
        tempFilePaths: '', //上传图片路径
        signtempFilePaths: '',
        safetymeasure:'',
    },
    showPopup() {
        wx.navigateTo({
            url: '../sign/sign?opinion=' + this.data.opinion + '&bumen=' + this.data.bumen + '&name=' + this.data.number
        })
        // this.setData({ show: true });
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        console.log(options);
        this.setData({
            name: options.zyptepe,
            number: options.zypcode,
            bumen: options.bumen,
            opinion: options.opinion,
            safetymeasure:options.safetymeasure
        })
    },
 
    onChange(event) {
        this.setData({
            radio: event.detail,
        });
    },
 
    //点击调用照相机和本地相册功能
    camera: function (event) {
        var that = this
        wx.chooseMedia({
            count: 1,
            itemList: ['拍照', '从相册中选择'],
            mediaType: ['image'],
            sourceType: ['album', 'camera'],
            camera: 'back',
            success: function (res) {
                console.log(res);
                if (res.tapIndex == 0) {
                    sourceType = 'camera'
                } else if (res.tapIndex == 1) {
                    sourceType = 'album'
                }
                that.setData({
                    tempFilePaths: res.tempFiles[0].tempFilePath,
                })
            }
        })
    },
    previewImage: function (e) {
        wx.previewImage({
            current: this.data.tempFilePaths, // 当前显示图片的链接,不填则默认为 urls 的第一张
            urls: [this.data.tempFilePaths] // 需要预览的图片链接列表
        })
    },
 
    previewsign: function (e) {
        wx.previewImage({
            current: this.data.signtempFilePaths, // 当前显示图片的链接,不填则默认为 urls 的第一张
            urls: [this.data.signtempFilePaths] // 需要预览的图片链接列表
        })
    },
    deletesign(e) {
        let index = e.currentTarget.dataset.index;
        Public_array.splice(index, 1) //根据下标删除1个图片
        this.setData({
            signtempFilePaths: '',
        })
    },
    //删除图片
    deleteImage(e) {
        let index = e.currentTarget.dataset.index;
        Public_array.splice(index, 1) //根据下标删除1个图片
        this.setData({
            tempFilePaths: '',
        })
    },
    reasonBindInput(event) {
        var that = this
        that.setData({
            reason: event.detail
        })
    },
    
    processing(e) {
        if (this.data.name=='动火作业') {
            wx.navigateTo({
                url: '../fireSafetymeasure/fireSafetymeasure?safetymeasure=' + this.data.safetymeasure+'&zypcode=' + this.data.number
            })
        }else if (this.data.name=='高处安全') {
            wx.navigateTo({
                url: '../AltitudeSafetymeasure/AltitudeSafetymeasure?safetymeasure=' + this.data.safetymeasure+'&zypcode=' + this.data.number
            })
        }else if (this.data.name=='受限空间') {
            wx.navigateTo({
                url: '../SpanceSafetymeasure/SpanceSafetymeasure?safetymeasure=' + this.data.safetymeasure+'&zypcode=' + this.data.number
            })
        }else if (this.data.name=='吊装安全') {
            wx.navigateTo({
                url: '../LiftingSafetymeasure/LiftingSafetymeasure?safetymeasure=' + this.data.safetymeasure+'&zypcode=' + this.data.number
            })
        }else if (this.data.name=='临时用电安全') {
            wx.navigateTo({
                url: '../ElectricitySafetymeasure/ElectricitySafetymeasure?safetymeasure=' + this.data.safetymeasure+'&zypcode=' + this.data.number
            })
        }else if (this.data.name=='动土安全') {
            wx.navigateTo({
                url: '../GroundSafetymeasure/GroundSafetymeasure?safetymeasure=' + this.data.safetymeasure+'&zypcode=' + this.data.number
            })
        }else if (this.data.name=='断路安全作业') {
            wx.navigateTo({
                url: '../CircuitSafetymeasure/CircuitSafetymeasure?safetymeasure=' + this.data.safetymeasure+'&zypcode=' + this.data.number
            })
        }else if (this.data.name=='盲板抽堵安全') {
            wx.navigateTo({
                url: '../BilndSafetymeasure/BilndSafetymeasure?safetymeasure=' + this.data.safetymeasure+'&zypcode=' + this.data.number
            })
        }
    },
 
 
    submitForm: function (e) {
        wx.showLoading({
            title: '正在上传',//加载转圈显示
        });
        var that = this;
        if (that.data.radio == 1) {
            if (that.data.bumen!='完工验收负责人') {
                if (!that.data.tempFilePaths) {
                    wx.showToast({
                        title: '请上传照片',
                        icon: 'error',
                        duration: 2000
                    });
                    return false
                }
            }
 
        }
        if (that.data.radio == 2) {
            if (!that.data.reason) {
                wx.showToast({
                    title: '请填写处理意见',
                    icon: 'error',
                    duration: 2000
                });
                return false
            }
            console.log(that.data.reason);
            wx.request({
                url: req_url + "/smszyp",
                method: 'get',
                data: {
                    // opinion: that.data.opinion,
                    bumen: that.data.bumen,
                    // zyptype: that.data.name,
                    zypcode: that.data.number,
                    handleidea: that.data.reason,
                    // picture: img,
                    // sign: sign,
                    // isgive: that.data.radio,
                },
                header: {
                    'Content-Type': 'application/json'
                },
                success: (res) => {
                    if (res.errMsg == "request:ok") {
                        wx.showToast({
                            title: '操作成功',
                            icon: 'success',
                            duration: 2000
                        });
                    } else {
                        wx.showToast({
                            title: '操作失败',
                        })
                    }
                }
                // })
            });
        }
        // if (that.data.radio == 3) {
        //     // if (!that.data.signtempFilePaths) {
        //         if (!that.data.tempFilePaths) {
        //             wx.showToast({
        //                 title: '请上传照片',
        //                 icon: 'error',
        //                 duration: 2000
        //             });
        //             return false
        //         }
        //     // }
 
        // }
 
        var sign = ''
        console.log(that.data.signtempFilePaths);
        if (that.data.signtempFilePaths) {
            var pic_url = that.data.signtempFilePaths; // 选中的图片路径
            console.log(11111111111);
            that.uploadPerPic(pic_url,that.data.signtempFilePaths, function back(res) {
                sign = res
                console.log(res);
                // that.setData({
                //     sign: res
                // })
                var img = ''
                console.log(that.data.tempFilePaths);
                if (that.data.tempFilePaths) {
                    var pic_url = that.data.tempFilePaths; // 选中的图片路径
                    console.log(11111111111);
                    that.uploadPerPic(pic_url, null, function back(resp) {
                        img = resp
                        // that.setData({
                        //     img: res
                        // })
                        wx.request({
                            url: req_url + "/addHandle",
                            method: 'post',
                            data: {
                                opinion: that.data.opinion,
                                bumen: that.data.bumen,
                                zyptype: that.data.name,
                                zypcode: that.data.number,
                                handleidea: that.data.reason,
                                picture: resp ,
                                sign: res,
                                isgive: that.data.radio,
                            },
                            header: {
                                'Content-Type': 'application/json'
                            },
                            success: (res) => {
                                if (res.errMsg == "request:ok") {
                                    var content= that.data.bumen+":"+wx.getStorageSync('username')+"处理编号为:"+that.data.number+"的动火作业票"
                                    wx.request({
                                        url: req_url + "/addZypLog",
                                        method: 'post',
                                        data: {
                                            name:wx.getStorageSync('username'),
                                            zyptype:"动火作业",
                                            bumen: that.data.bumen,
                                            zypcode: that.data.number,
                                            content: content,
                                        },
                                        header: {
                                            'Content-Type': 'application/json'
                                        },
                                        success: (res) => {
                                            console.log(res);
                                           
                                        }
                                    });
 
                                    wx.showToast({
                                        title: '操作成功',
                                        icon: 'success',
                                        duration: 2000
                                    });
                                    wx.navigateTo({
                                        url: '../index/index',
                                    })
                                } else {
                                    wx.showToast({
                                        title: '操作失败',
                                    })
                                }
                            }
                            // })
                        });
                        console.log(res);
                    })
                }
 
            })
        }
        console.log(sign);
      
        console.log(that.data.sign);
    
        // var pic_url = that.data.tempFilePaths; // 选中的图片路径
        // var img = ''
        // that.uploadPerPic(pic_url, function back(res) {
        //     console.log(res);
        //     img = res
        //     wx.request({
        //         url: req_url + "/addHandle",
        //         method: 'post',
        //         data: {
        //             opinion:that.data.opinion,
        //             bumen:that.data.bumen,
        //             zyptype:that.data.name,
        //             zypcode: that.data.number,
        //             handleidea: that.data.reason,
        //             picture: img,
        //             sign:sign,
        //             isgive: that.data.radio,
        //         },
        //         header: {
        //             'Content-Type': 'application/json'
        //         },
        //         success: (res) => {
        //             if (res.errMsg == "request:ok") {
        //                 wx.showToast({
        //                     title: '操作成功',
        //                     icon: 'success',
        //                     duration: 2000
        //                 });
        //                 wx.navigateTo({
        //                     url: '../index/index',
        //                 })
        //             } else {
        //                 wx.showToast({
        //                     title: '操作失败',
        //                 })
        //             }
        //         }
        //     // })
        // });
    },
 
    uploadPerPic(url, sign, back) {
        var name = ''
        var that=this
        if (sign) {
            name = 'sign'+that.data.number
        } else {
            name = that.data.number
        }
        console.log(name);
        wx.uploadFile({
            url: req_url + "addpic",
            method: "POST",
            filePath: url,
            name: 'file',
            formData: {
                'opinion': that.data.opinion,
                'bumen': that.data.bumen,
                'name': name,
            },
            success(res) {
                if (sign) {
                    that.setData({
                        img: res
                    })
 
                } else {
                    that.setData({
                        sign: res
                    })
                }
                console.log(res);
                back(res.data);
            },
            fail(e) { }
        })
    },
    bindViewTap() {
        wx.navigateTo({
            url: '../index/index'
        })
    },
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {
        Public_array = []; //清空公共数组
    },
})