#
whycq
2022-06-27 b8544ee0bc7d93762d6ffe2d1765129ecaef46f9
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
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
<template>
    <view class="content">
        <uni-card :is-shadow="false" is-full>
            <text class="uni-h6">故障上报后,售后人员会第一时间收到通知并解决故障。请填写真实描述及其他信息,方便相关后续方案。  ————  中扬立库</text>
        </uni-card>
        <view class="uni-common-mt">
            <form>
                <view class="uni-list">
                    <!-- 所属项目 -->
                    <view class="uni-list-cell">
                        <view class="uni-list-cell-left">
                            <view class="uni-label redDot">所属项目</view>
                        </view>
                        <view class="uni-list-cell-right">
                            <picker :range="host" @change="hostChange" :value="hostIndex" mode="selector">
                                <view class="uni-input">{{host[hostIndex]}}</view>
                            </picker>
                        </view>
                    </view>
                    <!-- 故障类型 -->
                    <view class="uni-list-cell">
                        <view class="uni-list-cell-left">
                            <view class="uni-label redDot">故障类型</view>
                        </view>
                        <view class="uni-list-cell-right">
                            <picker :range="issueType" @change="issueTypeChange" :value="issueTypeIndex" mode="selector">
                                <view class="uni-input">{{issueType[issueTypeIndex]}}</view>
                            </picker>
                        </view>
                    </view>
                    <!-- 联系人 -->
                    <view class="uni-list-cell">
                        <view class="uni-list-cell-left">
                            <view class="uni-label">联系人</view>
                        </view>
                        <view class="uni-list-cell-right">
                             <input class="uni-input" v-model="discoverer" placeholder="请输入" />
                        </view>
                    </view>
                    <!-- 联系方式 -->
                    <view class="uni-list-cell">
                        <view class="uni-list-cell-left">
                            <view class="uni-label redDot">联系方式</view>
                        </view>
                        <view class="uni-list-cell-right">
                             <input class="uni-input" v-model="tel" placeholder="请输入" />
                        </view>
                    </view>
                    <!-- 发生日期 -->
                    <view class="uni-list-cell">
                        <view class="uni-list-cell-left">
                            <view class="uni-label redDot">发生日期</view>
                        </view>
                        <view class="uni-list-cell-right">
                            <picker mode="date" :value="startTime" @change="bindDateChange">
                                <view class="uni-input">{{startTime}}</view>
                            </picker>
                        </view>
                    </view>
                </view>
                <view class="uni-list" style="margin-top: 15rpx;">
                    <view class="uni-title uni-common-pl redDot" style="padding: 20rpx 30rpx 10rpx 30rpx;">问题概述</view>
                    <view class="uni-textarea">
                        <textarea placeholder="请输入具体描述..." v-model="title"  style="text-indent:15rpx;"/>
                    </view>
                </view>
                <view class="uni-list" style="margin-top: 15rpx;">
                    <view class="uni-list-cell cell-pd">
                        <view class="uni-uploader">
                            <view class="uni-uploader-head">
                                <view class="uni-uploader-title">相关图片上传</view>
                                <view class="uni-uploader-info">{{imageList.length}}/9</view>
                            </view>
                            <view class="uni-uploader-body">
                                <view class="uni-uploader__files">
                                    <block v-for="(image,index) in imageList" :key="index">
                                        <view class="uni-uploader__file">
                                            <image class="uni-uploader__img" :src="image" :data-src="image" @tap="previewImage"></image>
                                        </view>
                                    </block>
                                    <view class="uni-uploader__input-box">
                                        <view class="uni-uploader__input" @tap="chooseImage"></view>
                                    </view>
                                </view>
                            </view>
                        </view>
                    </view>
                </view>
                <view style="margin-top: 15rpx;">
                    <template v-if="!videoSrc">
                        <view class="uni-hello-addfile" @tap="chooseVideo">+ 添加视频</view>
                    </template>
                    <template v-else>
                        <video :src="videoSrc" class="video"></video>
                    </template>
                </view>
                
                 <view class="uni-padding-wrap uni-common-mt" style="margin-bottom: 30rpx;">
                    <button type="primary" @click="save">确认提交</button>
                </view>
            </form>
        </view>
    </view>
</template>
 
<script>
    import permision from "@/common/permission.js"
    import uniPopup from '@/components/uni-popup/uni-popup.vue'
    var util = require('../../common/util.js');
    
    var formatLocation = util.formatLocation;
    var sourceType = [
        ['camera'],
        ['album'],
        ['camera', 'album']
    ]
    var sizeType = [
        ['compressed'],
        ['original'],
        ['compressed', 'original']
    ]
    function getParam(path, name) {
        var reg = new RegExp("(^|\\?|&)" + name + "=([^&]*)(\\s|&|$)", "i");
        if (reg.test(path))
        return unescape(RegExp.$2.replace(/\+/g, " "));
        return "";
    }
    function getDate(type) {
        const date = new Date();
 
        let year = date.getFullYear();
        let month = date.getMonth() + 1;
        let day = date.getDate();
 
        if (type === 'start') {
            year = year - 10;
        } else if (type === 'end') {
            year = year + 10;
        }
        month = month > 9 ? month : '0' + month;;
        day = day > 9 ? day : '0' + day;
 
        return `${year}-${month}-${day}`;
    }
    function isEmpty(obj){
        return typeof obj == "undefined" || obj == null || obj === "";
    }
    export default {
        components: {
            uniPopup
        },
        data() {
            return {
                // 表单数据
                title: null,
                tel: null,
                discoverer: null,
                startTime: getDate({
                    format: true
                }),
                desc: null,
                memo: null,
                imageList: [],
                imageFileList: [],
                hostIndex: 0,
                host: ["请选择项目"],
                issueTypeIndex: 0,
                issueType: ["请选择类型"],
                sourceTypeIndex: 2,
                sourceType: ['拍照', '相册', '拍照或相册'],
                countIndex: 8,
                count: [1, 2, 3, 4, 5, 6, 7, 8, 9],
                hasLocation: false,
                location: {},
                locationAddress: '',
                type: '',
                videoSrc: ''
            }
        },
        onLoad() {
            this.initHost();
            this.initIssueType();
        },
        methods: {
            // 初始化项目列表
            initHost: function() {
                uni.request({
                    url: this.baseUrl + '/app/host/list/auth',
                    data: {
                    },
                    header: {
                        "token": uni.getStorageSync('token')
                    },
                    success: (result) => {
                        let res = result.data;
                        if (res.code == 200) {
                            for    (let item of res.data) {
                                this.host.push(item.name);
                            }
                        } else if (res.code == 403) {
                            uni.showToast({title: res.msg, icon: "none",position: 'top'})
                            setTimeout(() => {
                                uni.reLaunch({
                                    url: '../login/login'
                                });
                            }, 500);
                        } else {
                            uni.showToast({title: res.msg,icon: "none",position: 'top'})
                        }
                    }
                });
            },
            // 初始化故障类型
            initIssueType: function() {
                uni.request({
                    url: this.baseUrl + '/app/issue/type/auth',
                    data: {
                    },
                    header: {
                        // "token": uni.getStorageSync('token')
                    },
                    success: (result) => {
                        let res = result.data;
                        if (res.code == 200) {
                            for    (let item of res.data) {
                                this.issueType.push(item.name);
                            }
                        } else if (res.code == 403) {
                            uni.showToast({title: res.msg, icon: "none",position: 'top'})
                            setTimeout(() => {
                                uni.reLaunch({
                                    url: '../login/login'
                                });
                            }, 500);
                        } else {
                            uni.showToast({title: res.msg,icon: "none",position: 'top'})
                        }
                    }
                });
            },
            // 保存提交
            save: function() {
                let that = this;
                if (that.hostIndex === 0) {
                    uni.showToast({title: "请选择所属项目",icon: "none",position: 'top'})
                    return;
                }
                let hostName = that.host[that.hostIndex];
                if (that.issueTypeIndex === 0) {
                    uni.showToast({title: "请选择故障类型",icon: "none",position: 'top'})
                    return;
                }
                let issueTypeName = that.issueType[that.issueTypeIndex];
                if (isEmpty(that.tel)) {
                    uni.showToast({title: "请输入联系方式",icon: "none",position: 'top'})
                    return;
                }
                if (isEmpty(that.title)) {
                    uni.showToast({title: "请输入问题概述",icon: "none",position: 'top'})
                    return;
                }
                uni.showLoading();
                uni.request({
                    url: that.baseUrl + '/app/issue/save/auth',
                    data: {
                        hostName: hostName,
                        issueTypeName: issueTypeName,
                        discoverer: that.discoverer,
                        tel: that.tel,
                        startTime: that.startTime,
                        title: that.title,
                        imgArr: that.imageList,
                        memo: that.memo,
                        videoSrc: [that.videoSrc]
                    },
                    header: {
                        "token": uni.getStorageSync('token')
                    },
                    success: (result) => {
                        uni.hideLoading();
                        let res = result.data;
                        if (res.code == 200) {
                            uni.showToast({title: res.msg,position: 'top'})
                            that.hostIndex = 0;
                            that.issueTypeIndex = 0;
                            that.discoverer = null;
                            that.tel = null;
                            that.title = null;
                            that.memo = null;
                            that.imageList = [];
                            that.imageFileList = [];
                            that.startTime = getDate({
                                format: true
                            });
                            that.videoSrc = null;
                        } else if (res.code == 403) {
                            uni.showToast({title: res.msg, icon: "none", position: 'top'})
                            setTimeout(() => {
                                uni.reLaunch({
                                    url: '../login/login'
                                });
                            }, 500);
                        } else {
                            uni.showToast({title: res.msg,icon: "none",position: 'top'})
                        }
                    }
                });
            },
            chooseLocation: function () {
                uni.chooseLocation({
                    success: (res) => {
                        this.hasLocation = true,
                            this.location = formatLocation(res.longitude, res.latitude),
                            this.locationAddress = res.address
                    }
                })
            },
            issueTypeChange: function(e) {
                this.issueTypeIndex = parseInt(e.detail.value);
            },
            hostChange: function(e) {
                this.hostIndex = parseInt(e.detail.value);
            },
            sumbit: function(e){
                uni.showToast({title: "ok",icon: "none",position: 'top'})
            },
            bindPickerChange: function(e) {
                this.index = e.detail.value
            },
            bindDateChange: function(e) {
                this.startTime = e.detail.value
            },
            chooseImage: async function() {
                // #ifdef APP-PLUS
                // TODO 选择相机或相册时 需要弹出actionsheet,目前无法获得是相机还是相册,在失败回调中处理
                if (this.sourceTypeIndex !== 2) {
                    let status = await this.checkPermission();
                    if (status !== 1) {
                        return;
                    }
                }
                // #endif
            
                if (this.imageList.length === 9) {
                    let isContinue = await this.isFullImg();
                    if (!isContinue) {
                        return;
                    }
                }
                uni.chooseImage({
                    sourceType: sourceType[this.sourceTypeIndex],
                    sizeType: sizeType[this.sizeTypeIndex],
                    count: this.imageList.length + this.count[this.countIndex] > 9 ? 9 - this.imageList.length : this.count[this.countIndex],
                    success: (res) => {
                        let that = this;
                        uni.showLoading();
                        for (var filePath of res.tempFilePaths) {
                            uni.uploadFile({
                                   url : that.baseUrl + '/upload.action',
                                   filePath: filePath,
                                   name: 'file',
                                   success: function (result) {
                                        var result0 = JSON.parse(result.data);
                                        if(result0.code === 200) {
                                            that.imageList = that.imageList.concat(result0.data.url);
                                        } else {
                                            uni.showToast({title: result0.msg,icon: "none",position: 'top'})
                                        }
                                   }
                            });
                        }
                        uni.hideLoading();
                        uni.showToast({title: "照片上传成功,请耐心等待...",icon: "none",position: 'top'})
                        that.imageFileList = that.imageFileList.concat(res.tempFiles);
                        // this.imageList = this.imageList.concat(res.tempFilePaths);
                    },
                    fail: (err) => {
                        // #ifdef APP-PLUS
                        if (err['code'] && err.code !== 0 && this.sourceTypeIndex === 2) {
                            this.checkPermission(err.code);
                        }
                        // #endif
                        // #ifdef MP
                        if(err.errMsg.indexOf('cancel') !== '-1'){
                            return;
                        }
                        uni.getSetting({
                            success: (res) => {
                                let authStatus = false;
                                switch (this.sourceTypeIndex) {
                                    case 0:
                                        authStatus = res.authSetting['scope.camera'];
                                        break;
                                    case 1:
                                        authStatus = res.authSetting['scope.album'];
                                        break;
                                    case 2:
                                        authStatus = res.authSetting['scope.album'] && res.authSetting['scope.camera'];
                                        break;
                                    default:
                                        break;
                                }
                                if (!authStatus) {
                                    uni.showModal({
                                        title: '授权失败',
                                        content: 'Hello uni-app需要从您的相机或相册获取图片,请在设置界面打开相关权限',
                                        success: (res) => {
                                            if (res.confirm) {
                                                uni.openSetting()
                                            }
                                        }
                                    })
                                }
                            }
                        })
                        // #endif
                    }
                })
            },
            isFullImg: function() {
                return new Promise((res) => {
                    uni.showModal({
                        content: "已经有9张图片了,是否清空现有图片?",
                        success: (e) => {
                            if (e.confirm) {
                                this.imageList = [];
                                this.imageFileList = [];
                                res(true);
                            } else {
                                res(false)
                            }
                        },
                        fail: () => {
                            res(false)
                        }
                    })
                })
            },
            previewImage: function(e) {
                var current = e.target.dataset.src
                uni.previewImage({
                    current: current,
                    urls: this.imageList
                })
            },
            async checkPermission(code) {
                let type = code ? code - 1 : this.sourceTypeIndex;
                let status = permision.isIOS ? await permision.requestIOS(sourceType[type][0]) :
                    await permision.requestAndroid(type === 0 ? 'android.permission.CAMERA' :
                        'android.permission.READ_EXTERNAL_STORAGE');
            
                if (status === null || status === 1) {
                    status = 1;
                } else {
                    uni.showModal({
                        content: "没有开启权限",
                        confirmText: "设置",
                        success: function(res) {
                            if (res.confirm) {
                                permision.gotoAppSetting();
                            }
                        }
                    })
                }
            
                return status;
            }
            ,
            // 定位
            togglePopup(type) {
                this.type = type;
            },
            showConfirm() {
                this.type = 'showpopup';
            },
            hideConfirm() {
                this.type = '';
            },
            async getLocation() {
                // #ifdef APP-PLUS
                let status = await this.checkPermission();
                if (status !== 1) {
                    return;
                }
                // #endif
                // #ifdef MP-WEIXIN || MP-TOUTIAO || MP-QQ
                let status = await this.getSetting();
                if (status === 2) {
                    this.showConfirm();
                    return;
                }
                // #endif
        
                this.doGetLocation();
            },
            doGetLocation() {
                uni.getLocation({
                    success: (res) => {
                        this.hasLocation = true;
                        this.location = formatLocation(res.longitude, res.latitude);
                    },
                    fail: (err) => {
                        // #ifdef MP-BAIDU
                        if (err.errCode === 202 || err.errCode === 10003) { // 202模拟器 10003真机 user deny
                            this.showConfirm();
                        }
                        // #endif
                        // #ifndef MP-BAIDU
                        if (err.errMsg.indexOf("auth deny") >= 0) {
                            uni.showToast({
                                title: "访问位置被拒绝"
                            })
                        } else {
                            uni.showToast({
                                title: err.errMsg
                            })
                        }
                        // #endif
                    }
                })
            },
            getSetting: function() {
                return new Promise((resolve, reject) => {
                    uni.getSetting({
                        success: (res) => {
                            if (res.authSetting['scope.userLocation'] === undefined) {
                                resolve(0);
                                return;
                            }
                            if (res.authSetting['scope.userLocation']) {
                                resolve(1);
                            } else {
                                resolve(2);
                            }
                        }
                    });
                });
            },
            openSetting: function() {
                this.hideConfirm();
                uni.openSetting({
                    success: (res) => {
                        if (res.authSetting && res.authSetting['scope.userLocation']) {
                            this.doGetLocation();
                        }
                    },
                    fail: (err) => {}
                })
            },
            async checkPermission() {
                let status = permision.isIOS ? await permision.requestIOS('location') :
                    await permision.requestAndroid('android.permission.ACCESS_FINE_LOCATION');
        
                if (status === null || status === 1) {
                    status = 1;
                } else if (status === 2) {
                    uni.showModal({
                        content: "系统定位已关闭",
                        confirmText: "确定",
                        showCancel: false,
                        success: function(res) {
                        }
                    })
                } else if (status.code) {
                    uni.showModal({
                        content: status.message
                    })
                } else {
                    uni.showModal({
                        content: "需要定位权限",
                        confirmText: "设置",
                        success: function(res) {
                            if (res.confirm) {
                                permision.gotoAppSetting();
                            }
                        }
                    })
                }
        
                return status;
            },
            clear: function() {
                this.hasLocation = false;
            },
            chooseVideo: function() {
                let that = this;
                uni.chooseVideo({
                    camera: 'back',
                    sourceType: ['camera', 'album'],
                    success: (res) => {
                        uni.showLoading();
                        uni.uploadFile({
                               url : that.baseUrl + '/upload.action',
                               filePath: res.tempFilePath,
                               name: 'file',
                               success: function (result) {
                                       uni.hideLoading();
                                    var result0 = JSON.parse(result.data);
                                    if(result0.code === 200) {
                                        that.videoSrc = result0.data.url;
                                    } else {
                                        uni.showToast({title: result0.msg,icon: "none",position: 'top'})
                                    }
                               }
                        });
                        uni.showToast({title: "视频上传成功,请耐心等待...",icon: "none",position: 'top'})                     },
                    fail: (err) => {
                        uni.getSetting({
                            success: (res) => {
                                let authStatus = false;
                                switch (this.sourceTypeIndex) {
                                    case 0:
                                        authStatus = res.authSetting['scope.camera'];
                                        break;
                                    case 1:
                                        authStatus = res.authSetting['scope.album'];
                                        break;
                                    case 2:
                                        authStatus = res.authSetting['scope.album'] && res.authSetting['scope.camera'];
                                        break;
                                    default:
                                        break;
                                }
                                if (!authStatus) {
                                    uni.showModal({
                                        title: '授权失败',
                                        content: '需要从您的相机或相册获取视频,请在设置界面打开相关权限',
                                        success: (res) => {
                                            if (res.confirm) {
                                                uni.openSetting()
                                            }
                                        }
                                    })
                                }
                            }
                        })
                    }
                })
            }
        }
    }
</script>
 
<style>
    @import '../../common/uni.css';
        
    .uni-title {
        color: rgb(102, 102, 102);
    }
    .uni-label {
        color: rgb(102, 102, 102);
    }
    .uni-form-item .title {
        padding: 20rpx 0;
    }
    .cell-pd {
        padding: 22rpx 30rpx;
    }
    
    .list-pd {
        margin-top: 50rpx;
    }
    .redDot:after {
        content: ' *';
        color: red;
    }
    .popup-view {
        width: 500rpx;
    }
    
    .popup-title {
        display: block;
        font-size: 16px;
        line-height: 3;
        margin-bottom: 10px;
        text-align: center;
    }
    
    .popup-buttons button {
        margin-left: 4px;
        margin-right: 4px;
    }
    
    .video {
        width: 100%;
    }
    
    .camera-tips {
        padding: 10rpx 30rpx;
    }
</style>