ll
liukangdong
2024-12-23 5c53a09ff28e5be90af9c1bc0534a4320fc5aec0
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
<template>
    <view class="main_app">
        <view v-if="info.status || info.status == 0" class="head_bg" :style="{
            background: `linear-gradient(180deg, ${statusM[info.status].color} 0%, rgba(247, 247, 247, 0) 100%)`
        }"></view>
        <view class="info">
            <image v-if="info.status == 2" class="icon" src="@/static/side/ic_dabiaoed.png" mode=""></image>
            <image v-if="info.status == 3" class="icon" src="@/static/side/ic_dabiao.png" mode=""></image>
            <view class="head">
                <view class="name">{{ info.title || info.planTitle }}</view>
                <view class="status" v-if="info.status || info.status == 0" :style="{color: statusM[info.status].color}">
                    {{statusM[info.status].name}}
                </view>
            </view>
            <view class="line">
                <view class="la">任务日期:</view>
                <view class="val" v-if="info.startDate">{{ info.startDate.slice(0, 10) }}</view>
            </view>
            <view class="line">
                <view class="la">执行时间:</view>
                <view class="val" v-if="info.startDate && info.endDate">{{ info.startDate.slice(11,16) }} 至
                    {{ info.endDate.slice(11, 16) }}
                </view>
            </view>
            <view class="line">
                <view class="la">完成情况:</view>
                <view class="val">{{info.finishNum || 0}}/{{info.patrolNum}}</view>
            </view>
        </view>
        <view class="title">巡检点列表({{list.length}})</view>
        <view class="list">
            <view class="item" v-for="item in list" @click="itemClick(item)">
                <view class="icon"></view>
                <view class="content">
                    <view class="head">
                        <view>{{item.pointName}}</view>
                        <view class="status" :class="{ gray: item.status == 1 }">
                            <image v-if="item.status == 1" src="@/static/plan_ic_finish@2x.png" class="icon" mode=""></image>
                            <text>{{ item.status == 1 ? '已巡检' : '待巡检' }}</text>
                        </view>
                    </view>
                    <template v-if="item.status == 1">
                        <view class="line">
                            <view class="la">巡检结果:</view>
                            <view class="val" :class="{ red: item.dealStatus == 1 }">{{ item.dealStatus == 0 ? '正常' : '异常' }}</view>
                        </view>
                        <view class="line">
                            <view class="la">巡检时间:</view>
                            <view class="val">
                                <text>{{item.dealDate}}</text>
                                <text v-if="item.status == 1" class="detail">查看详情</text>
                            </view>
                        </view>
                    </template>
                    <view class="desc" v-else>{{item.content}}</view>
                </view>
            </view>
        </view>
        <view class="footer" @click="openSc" v-if="flag">
            <view class="sub_btn">扫码巡检</view>
        </view>
        <!--  -->
        <view class="reader-box" @click="stopScan" v-if="isScaning">
            <view class="reader" id="reader"></view>
        </view>
    </view>
</template>
 
<script>
    import {
        ywPatrolDetail,
        ywPatrolTaskRecord,
        getPointRecordByCode
    } from '@/api'
    import dayjs from 'dayjs';
    import {
        Html5Qrcode
    } from 'html5-qrcode';
    export default {
        data() {
            return {
                id: '',
                info: {},
                list: [],
                flag: false,
                statusM: [{
                        color: '#4593f7',
                        name: '待开始'
                    },
                    {
                        color: '#73e09a',
                        name: '进行中'
                    },
                    {
                        color: '#f1a93f',
                        name: '已超期'
                    },
                    {
                        color: '#b9b9b9',
                        name: '已处理'
                    },
                ],
                html5Qrcode: null,
                isScaning: false,
            };
        },
        onLoad(option) {
            this.id = option.id
            // this.getDetail()
        },
        onShow() {
            this.getDetail()
        },
        methods: {
            openSc() {
                this.isScaning = true;
                Html5Qrcode.getCameras().then((devices) => {
                    if (devices && devices.length) {
                        this.html5Qrcode = new Html5Qrcode('reader');
                        this.html5Qrcode.start({
                                facingMode: 'environment'
                            }, {
                                focusMode: 'continuous', //设置连续聚焦模式
                                fps: 5, //设置扫码识别速度
                                qrbox: 280 //设置二维码扫描框大小
                            },
                            (decodeText, decodeResult) => {
                                if (decodeText) { //这里decodeText就是通过扫描二维码得到的内容
                                    this.stopScan(); //关闭扫码功能
                                    getPointRecordByCode({
                                        taskId: this.id,
                                        pointCode: decodeText
                                    }).then(ress => {
                                        if (ress.data) {
                                            uni.navigateTo({
                                                url: '/pages/polling/point?id=' + ress.data.id
                                            })
                                        } else {
                                            this.showToast('未匹配到巡检点,请重新扫描')
                                        }
                                    })
                                }
                            },
                            (err) => {
                                // console.log(err);  //错误信息
                            }
                        );
                    }
                });
            },
 
            stopScan() {
                console.log('停止扫码')
                this.isScaning = false;
                if (this.html5Qrcode) {
                    this.html5Qrcode.stop();
                }
            },
            itemClick(item) {
                if (!this.flag) return
                uni.navigateTo({
                    url: '/pages/polling/point?id=' + item.id
                })
            },
            getDetail() {
                const {
                    id
                } = this
                ywPatrolDetail(id).then(res => {
                    this.info = res.data
                    let time = new Date(res.data.startDate).getTime()
                    console.log('res.data.startDate', new Date().getTime());
                    this.flag = new Date().getTime() > time && (this.info.status == 0 || this.info.status == 1)
                })
                ywPatrolTaskRecord({
                    capacity: 999,
                    page: 1,
                    model: {
                        taskId: id
                    }
                }).then(res => {
                    this.list = res.data.records
                })
            },
            async startScan() {
                try {
                    const video = document.getElementById('video');
                    const stream = await navigator.mediaDevices.getUserMedia({
                        video: {
                            facingMode: "environment"
                        }
                    });
                    video.srcObject = stream;
 
                    // 使用 QrScanner 解析
                    const qrScanner = new QrScanner(video, result => {
                        alert(`扫描结果: ${result}`);
                        qrScanner.stop(); // 停止扫码
                    });
                    qrScanner.start();
                } catch (err) {
                    console.error('打开摄像头失败:', err);
                }
            }
        }
    }
</script>
 
<style lang="scss">
    page {
        background: #F7F7F7;
    }
 
    .main_app {
        padding: 30rpx;
 
        .head_bg {
            // background: linear-gradient(180deg, #008BFF 0%, rgba(247, 247, 247, 0) 100%);
            height: 240rpx;
            width: 750rpx;
            position: absolute;
            top: 0;
            left: 0;
        }
 
        .info {
            width: 690rpx;
            box-shadow: 0rpx 4rpx 16rpx 0rpx #E5E5E5;
            border-radius: 20rpx;
            opacity: 0.95;
            padding: 30rpx 30rpx 10rpx;
            margin-bottom: 40rpx;
            background: linear-gradient(#FFFFFF 0%, #FFFFFF 48%, #F0F5FF 100%);
            position: relative;
 
            .icon {
                position: absolute;
                right: 30rpx;
                bottom: 30rpx;
                width: 160rpx;
                height: 122rpx;
            }
 
            .head {
                display: flex;
                justify-content: space-between;
                margin-bottom: 30rpx;
 
                .name {
                    font-weight: 600;
                    font-size: 34rpx;
                }
 
                .status {
                    color: $primaryColor;
                }
 
                .gray {
                    color: gray;
                }
            }
 
        }
 
        .title {
            font-weight: 600;
            font-size: 32rpx;
            color: #222222;
            margin-bottom: 30rpx;
        }
 
        .line {
            display: flex;
            margin-bottom: 20rpx;
 
            .la {
                color: #666666;
                
            }
        }
 
        .list {
            height: calc(100vh - 490rpx);
            overflow: auto;
            padding-bottom: 160rpx;
            .item {
                width: 690rpx;
                height: 188rpx;
                background: linear-gradient(#FFFFFF 0%, #FFFFFF 48%, #F0F5FF 100%);
                box-shadow: 0rpx 4rpx 12rpx 0rpx #E5E5E5;
                border-radius: 12rpx;
                opacity: 0.95;
                display: flex;
                padding: 20rpx 30rpx 0 16rpx;
                margin-bottom: 20rpx;
 
                .line {
                    margin-bottom: 10rpx;
                    width: 100%;
                    .val{
                        display: flex;
                        justify-content: space-between;
                        align-items: center;
                        flex: 1;
                        .detail{
                            color: $primaryColor;
                            font-size: 26rpx;
                        }
                    }
                }
 
                .icon {
                    width: 10rpx;
                    height: 148rpx;
                    background: $primaryColor;
                    border-radius: 6rpx;
                    margin-right: 24rpx;
                }
 
                .content {
                    flex: 1;
 
                    .head {
                        display: flex;
                        align-items: center;
                        justify-content: space-between;
                        font-weight: 500;
                        font-size: 32rpx;
                        margin-bottom: 16rpx;
 
                        .status {
                            font-size: 28rpx;
                            color: $primaryColor;
                            font-weight: 400;
                            display: flex;
                            align-items: center;
                            .icon{
                                width: 40rpx;
                                height: 40rpx;
                                // border-radius: 50%;
                                // overflow: hidden;
                                background: none;
                            }
                            
                        }
 
                        .gray {
                            color: #999999;
                        }
                    }
 
                    .desc {
                        font-size: 26rpx;
                        color: #666666;
                        display: -webkit-box;
                        -webkit-line-clamp: 2;
                        -webkit-box-orient: vertical;
                        overflow: hidden;
                        text-overflow: ellipsis;
                        width: 100%;
                    }
                }
            }
        }
 
        .footer {
            position: fixed;
            bottom: 0rpx;
            left: 0rpx;
            width: 750rpx;
            height: 172rpx;
            background-color: #fff;
            padding: 20rpx 40rpx;
 
            .sub_btn {
 
                width: 670rpx;
                height: 88rpx;
                background: $primaryColor;
                box-shadow: 0rpx 8rpx 20rpx 0rpx rgba(0, 104, 255, 0.3);
                border-radius: 44rpx;
                display: flex;
                align-items: center;
                justify-content: center;
                font-weight: 500;
                font-size: 32rpx;
                color: #FFFFFF;
            }
        }
 
    }
 
    .reader-box {
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
        background-color: rgba(0, 0, 0, 0.5);
    }
    
    .reader {
        width: 100%;
        // width: 540rpx;
        // height: 540rpx;
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
    }
</style>