loulijun2021
2024-05-08 15cbc2f370b61e4e0cd472c8030fb8cb6d89b82a
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
<template>
    <view>
        <page-nav title="日常点检"></page-nav>
 
        <!-- <u-notify ref="uNotify"></u-notify> -->
 
        <view v-show="topContent.length===0">
            <div class="sacnBody">
                <div class="scanImg" @click="topScanClick"></div>
                <div class="scanText">扫描点检工位</div>
            </div>
        </view>
 
 
        <view v-show="topContent.length!==0">
            <view class="mainContent">
                <view>
                    <u-gap height="10" bgColor="#eff0f1"></u-gap>
                    <view class="head">
                        <view class="head_block">
                            <view class="head_left">
                                <view class="head_bar"></view>
                                <view class="head_title">
                                    扫描点检工位
                                </view>
                            </view>
 
                            <view class="marginRight20">
                                <u-icon name="scan" @click="topScanClick" color="red" size="28"></u-icon>
                            </view>
 
                        </view>
 
                        <view class="marginLeft20 marginRight20" style="max-height: 180rpx;overflow:auto;">
                            <u-radio-group v-model="radioValue" class="flex_column">
                                <view class="marginBottom20 flex_between" @click="groupChange(item.code)"
                                    v-for="item in topContent" :key="item.code">
                                    <view style="display: flex;">
                                        <view class="flex_column titleFont">
                                            <view>工位编码:</view>
                                            <view>工位名称:</view>
                                            <view>生产车间:</view>
                                        </view>
                                        <view class="flex_column contentFont">
                                            <view>{{item.code}}</view>
                                            <view>{{item.name}}</view>
                                            <view>{{item.wksp_name}}</view>
                                        </view>
                                    </view>
                                    <u-radio style="line-height: 44rpx;" size='40' :key="item.code" :name="item.code"
                                        @change="groupChange(item.code)" activeColor="red"></u-radio>
                                </view>
                            </u-radio-group>
                        </view>
 
                    </view>
 
                    <u-gap height="12" bgColor="#eff0f1"></u-gap>
                    <view class="head" style="height:82rpx;">
                        <view class="head_block">
                            <view class="head_left">
                                <view class="head_bar"></view>
                                <view class="head_title">
                                    点检标准
                                </view>
                            </view>
 
                            <view class="marginRight20 marginTop10" style="width: 200rpx;">
                                <!-- <u-icon name="scan" @click="topScanClick" color="red" size="56"></u-icon> -->
                                <uni-data-select v-model="selectValueBZ" :clear="false" :localdata="selectRangeBZ"
                                    @change="selectChangeBZ">
                                </uni-data-select>
                            </view>
 
                        </view>
                    </view>
 
                    <u-gap height="12" bgColor="#eff0f1"></u-gap>
                    <view class="head" style="">
                        <view class="head_block">
                            <view class="head_left">
                                <view class="head_bar"></view>
                                <view class="head_title">
                                    点检项目内容
                                </view>
                            </view>
                        </view>
 
                        <!-- <view :style="{maxHeight:(($DeviceInformation.screenHeight-530)*3)+'rpx',overflow: 'scroll'}"> -->
                        <view :style="{maxHeight:'1000rpx',overflow: 'scroll'}">
 
                            <view class="center_border flex_column" style="margin: 10rpx;" v-for="item in centerContent"
                                :key="item.code">
 
                                <view class="flex_between marginBottom10">
                                    <view class="center_title">{{item.name}}</view>
                                    <view class="marginRight20" v-if="item.isscan==='Y'">
                                        <u-icon name="scan" @click="centerScanClick(item.code)" color="red" size="56">
                                        </u-icon>
                                    </view>
                                </view>
                                <view class="flex_between marginBottom10">
                                    <view class='inputClass marginTop10'>
                                        <u--input :disabled='item.isDisabled' placeholder="请输入" border="surround"
                                            v-model="item.inputValue"></u--input>
                                    </view>
 
 
                                    <view class="flex_center">
                                        <u-button type="primary" :plain="item.isOK!=='OK'" :disabled="item.isDisabled"
                                            text="正常" @click="bwClick(item,'OK')">
                                        </u-button>
                                        <u-button type="warning" :plain="item.isOK!=='NG'" :disabled="item.isDisabled"
                                            text="异常" @click="bwClick(item,'NG')">
                                        </u-button>
                                    </view>
                                </view>
                                <view class="titleFont">
                                    {{item.chkdesc}}
                                </view>
                            </view>
                        </view>
 
 
                    </view>
                </view>
            </view>
 
 
            <view class="footer">
                <view class="head_block" style="align-items: center;padding: 0 23rpx;">
                    <view class="head_left">
                        <view class="head_bar"></view>
                        <view class="head_title">
                            点检结果
                        </view>
                    </view>
                    <view class="flex_center">
                        <u-button type="primary" :plain="resultValue!=='OK'"
                            :disabled="centerContent.some(item=>item.isDisabled===true)||centerContent.length===0"
                            text="正常" @click="resultClick('OK')"></u-button>
                        <u-button type="warning" :plain="resultValue!=='NG'"
                            :disabled="centerContent.some(item=>item.isDisabled===true)||centerContent.length===0"
                            text="异常" @click="resultClick('NG')"></u-button>
                    </view>
                </view>
            </view>
            <u-button size="large" :loading="isDisabledSubmitButton" loadingText="正在提交,请稍等..." type="primary"
                @click="submit" :disabled="resultValue===''" text="确认提交">
            </u-button>
 
        </view>
 
        <scan-code></scan-code>
 
    </view>
</template>
 
<script>
    import {
        // CheckScanDeviceQrCodeData,
        // SelectScanDeviceQrCodeItem,
        // CheckScanDeviceTemp,
        // AppDeviceCheckSave
    } from '../../config/api.js'
    import scanCode from '@/components/scan-code/scan-code.vue'
    export default {
        components: {
            scanCode
        },
        onLoad(option) {
 
            const _this = this
            uni.$off('scancodedate') // 每次进来先 移除全局自定义事件监听器
            uni.$on('scancodedate', function(content) {
                console.log("扫描到的内容为:", content)
                _this.getCheckScanDeviceQrCodeData(content)
            })
        },
        onPullDownRefresh() {
            setTimeout(() => {
                this.init(() => {
                    uni.stopPullDownRefresh();
                })
            }, 1000);
        },
        data() {
            return {
                isDisabledSubmitButton: false,
 
                selectValueBZ: '',
                selectRangeBZ: [],
 
                topContent: [], //扫描点检工位所带出来的内容
                centerContent: [], //点检项目内容
                scanContent: '', //扫描扫出来的值
                radioValue: '', //单选框的值
                resultValue: '', //点检结果值
 
            }
        },
        created() {
 
        },
        mounted() {
            this.init()
 
            // this.getCheckScanDeviceQrCodeData('SB001')
            // this.getCheckScanDeviceQrCodeData('SB002')
            // this.getCheckScanDeviceQrCodeData('SB003')
 
 
        },
        methods: {
            init() {
                uni.stopPullDownRefresh();
            },
            // 扫码点检工位  的扫码框点击
            topScanClick() {
                let that = this;
 
                uni.scanCode({
                    onlyFromCamera: true,
                    // scanType: ['barCode', 'qrCode'],
                    scanType: ['qrCode'],
                    success: function(res) {
                        console.log('条码类型:' + res.scanType);
                        console.log('条码内容:' + res.result);
                        that.scanContent = res.result;
                        let flag = false
                        that.topContent.forEach(item => {
                            if (item.code === res.result) {
                                flag = true
                            }
                        })
                        if (flag) {
                            that.$u.toast('此条码已扫描,已在列表中!')
                        } else {
                            //处理扫码事件
                            that.getCheckScanDeviceQrCodeData(that.scanContent);
                        }
                    },
                    complete: function(res) {
 
                    },
                    fail: function(res) {
                        console.log('条码类型:' + res.scanType);
                        console.log('条码内容:' + res.result);
                    }
 
                });
            },
 
            // 点检项目内容  的扫码框点击
            centerScanClick(val) {
                let that = this;
                uni.scanCode({
                    onlyFromCamera: true,
                    // scanType: ['barCode', 'qrCode'],
                    scanType: ['qrCode'],
                    success: function(res) {
                        console.log('条码类型:' + res.scanType);
                        console.log('条码内容:' + res.result);
                        // that.scanContent = res.result;
 
 
                        if (res.result === val) {
                            that.centerContent.find(item => item.code === val).isDisabled = false
                            that.centerContent.find(item => item.code === val).isOK = 'OK'
 
                            if (that.centerContent.every(r => r.isOK === 'OK')) {
                                that.resultValue = 'OK'
                            }
                            if (that.centerContent.some(r => r.isOK === 'NG')) {
                                that.resultValue = 'NG'
                            }
                            if (that.centerContent.some(r => r.isOK === '')) {
                                that.resultValue = ''
                            }
 
 
                            that.$forceUpdate()
                        } else {
                            uni.$u.toast('所扫条码与点检部位不符合!')
                        }
 
 
                        //处理扫码事件
                        // that.SearchBarcode();
                    },
                    complete: function(res) {},
                    fail: function(res) {}
 
                });
            },
 
            // 获取点检工位
            async getCheckScanDeviceQrCodeData(val) {
                const data = {
                    eqpcode: val
                }
                const res = await CheckScanDeviceQrCodeData(data)
 
                if (res.code === '200' && res.data[0].eqpchkmain_code !== null) { //表示绑定了标准
                    this.topContent.unshift(res.data[0])
                    // console.log(res.data[0],222);
                    this.getCheckScanDeviceTemp(res.data[0].code)
                } else if (res.code === '200' && res.data[0].eqpchkmain_code === null) {
                    uni.$u.toast('当前设备未设置点检标准绑定点检项目!')
                }
 
            },
            // 获取点检标准
            async getCheckScanDeviceTemp(eqpcode) {
                const res = await CheckScanDeviceTemp({
                    eqpcode
                })
                this.selectRangeBZ = res.data.map(({
                    code,
                    name
                }) => ({
                    text: name,
                    value: code
                }))
 
                this.selectValueBZ = this.selectRangeBZ[0].value
 
                this.getSelectScanDeviceQrCodeItem(eqpcode, this.selectValueBZ)
 
            },
            //点检标准下拉选择改变
            selectChangeBZ(val) {
                this.selectValueBZ = val
 
                this.getSelectScanDeviceQrCodeItem(this.radioValue, this.selectValueBZ)
            },
            // 获取点检项目内容
            async getSelectScanDeviceQrCodeItem(eqpcode, checktempcode) {
 
                const data = {
                    eqpcode,
                    checktempcode
                }
                const res = await SelectScanDeviceQrCodeItem(data)
 
                if (res.code === '200') {
                    this.centerContent = res.data
 
                    this.centerContent.forEach(item => {
                        item.inputValue = ''
                        item.isDisabled = item.isscan === 'Y'
                        item.isOK = item.isscan !== 'Y' ? 'OK' : ''
                    })
 
                    if (this.centerContent.every(r => r.isOK === 'OK')) {
                        this.resultValue = 'OK'
                    }
                    if (this.centerContent.some(r => r.isOK === 'NG')) {
                        this.resultValue = 'NG'
                    }
                    if (this.centerContent.some(r => r.isOK === '')) {
                        this.resultValue = ''
                    }
 
                    this.radioValue = eqpcode
                    this.$forceUpdate()
                }
 
 
            },
            // 单选按钮点击
            groupChange(val) {
                this.radioValue = val
                this.$forceUpdate()
                this.getCheckScanDeviceTemp(val)
            },
 
            // 部位正常 异常按钮点击
            bwClick(item, val) {
                item.isOK = val
                if (this.centerContent.every(item => item.isOK !== '')) {
                    if (this.centerContent.every(item => item.isOK === 'OK')) {
                        this.resultValue = 'OK'
                    } else {
                        this.resultValue = 'NG'
                    }
                }
                this.$forceUpdate() //强制视图更新
            },
            // 点检结果点击
            resultClick(val) {
                this.resultValue = val
                this.$forceUpdate() //强制视图更新
            },
            // 确认提交按钮
            async submit() {
                const children = []
                this.centerContent.forEach(item => {
                    children.push({
                        seq: item.seq,
                        itemcode: item.code,
                        cycle: item.cycle,
                        value: item.inputValue,
                        result: item.isOK
                    })
 
                })
                const data = {
                    code: this.topContent.find(item => item.code === this.radioValue).code,
                    name: this.topContent.find(item => item.code === this.radioValue).name,
                    // standcode: this.topContent.find(item => item.code === this.radioValue).eqpchkmain_code,
                    standcode: this.selectValueBZ,
                    result: this.resultValue,
                    children: children
                }
 
                // console.log(data, 8);
 
 
                this.isDisabledSubmitButton = true
                const res = await AppDeviceCheckSave(uni.getStorageSync("username"), data)
                if (res.code === '200') {
 
                    // this.$refs.uNotify.show({
                    //     top: 160,
                    //     type: 'primary',
                    //     color: '#fff',
                    //     bgColor: '#436df5',
                    //     message: '提交成功!',
                    //     duration: 1000 * 3,
                    //     fontSize: 30,
                    //     safeAreaInsetTop: false
                    // })
                    uni.$u.toast('提交成功!')
                    this.isDisabledSubmitButton = false
                    this.topContent.forEach((item, index) => {
                        if (item.code === this.radioValue) {
                            this.topContent.splice(index, 1)
                        }
                    })
                    this.radioValue = this.topContent[0].code
                    if (this.radioValue.toString().length > 0) {
                        // this.getSelectScanDeviceQrCodeItem(this.radioValue, this.topContent.find(i => i.code === this
                        //     .radioValue).eqpchkmain_code)
                        this.getCheckScanDeviceTemp(val)
                    }
 
                }
            },
        }
    }
</script>
 
<style lang="scss" scoped>
    @import url('@/style/global.css');
 
    ::v-deep .uicon-arrow-left>span {
        display: block;
    }
</style>