wangyi
2026-03-13 15bd4962b44577d0eb9e8fc52f7b9a1eadff42db
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
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
<template>
    <view class="content">
        <view class="form">
            <view class="form-item">
                <view class="title">{{ HBillTypeName }}单号:</view>
                <view class="righton">
                    <input v-model="baseInfo.HBillNo" disabled />
                </view>
            </view>
            <!-- <view class="form-item"> -->
            <!-- <view class="title">采购单号:</view> -->
            <!-- <view class="righton"> -->
            <!-- <input v-model="baseInfo.HInnerBillNo" disabled /> -->
            <!-- </view> -->
            <!-- </view> -->
            <view class="form-item">
                <view class="title">物料编码:</view>
                <view class="righton">
                    <input v-model="baseInfo.HMaterNumber" disabled />
                </view>
            </view>
            <view class="form-item">
                <view class="title">物料名称:</view>
                <view class="righton">
                    <input v-model="baseInfo.HMaterName" disabled />
                </view>
            </view>
            <view class="form-item">
                <view class="title">规格型号:</view>
                <view class="righton">
                    <input v-model="baseInfo.HMaterModel" disabled />
                </view>
            </view>
            <view class="form-item">
                <view class="title">收料数量:</view>
                <view class="righton">
                    <input v-model="baseInfo.HQty" disabled />
                </view>
            </view>
            <view class="form-item">
                <view class="title">每箱数量:</view>
                <view class="right">
                    <input v-model="baseInfo.HMinQty" type="number" placeholder="请输入数量" @confirm="getNum()"
                        @blur="getNum()" />
                </view>
            </view>
            <view class="form-item">
                <view class="title">箱数:</view>
                <view class="right">
                    <input v-model="baseInfo.HBQty" @blur="getHMinQtyByBQty()" />
                </view>
            </view>
            <view class="buttons">
                <button class="btn-b" size="mini" type="default" @tap="getList()">条码生成</button>
                <!-- <button class="btn-c" size="mini" type="default" @tap="searchLabelPrinter()">搜索打印机</button> -->
                <!-- :disabled="codeGenComplete == false" -->
                <button :class="codeGenComplete == false? 'btn-a': 'btn-c'" size="mini" type="default"
                    :disabled="codeGenComplete == false" @tap="search">打印</button>
            </view>
        </view>
 
        <view style="width: 100%;height: 16rpx;background-color: #e5e5e5;"></view>
 
        <view class="list" v-for="(item,index) in listData" :key="index">
            <uni-card :title="item['物料代码']|| item.HMaterNumber" :extra="'No. ' + Number(index+1)" style="margin: 10px;">
                <view class="card-detail">
                    <view class="detail">
                        <text>物料名称:</text>{{item.HMaterName || item['物料名称']}}
                    </view>
                    <view class="detail">
                        <text>规格型号:</text>{{item.HMaterModel|| item['规格型号']}}
                    </view>
                    <view class="detail">
                        <text>数量:</text>{{item.HQty || item['数量']}}
                    </view>
                    <view class="detail" style="width: 100%;">
                        <text>条码编号:</text>{{item.HBarCodeNo || item['条码编号']}}
                    </view>
                </view>
                <!--                 <view class="detail" style="text-align: right;" @tap.stop="labelPrint(item)"><text
                        style="color: orange;">点击打印条码</text></view> -->
            </uni-card>
        </view>
 
        <view class="over" v-if="listData.length == 0">暂无数据</view>
        <view class="over" v-if="listData.length != 0">已到底</view>
 
        <labelPrinterComponentVue ref="labelPrinter" :printInfo="printInfo" :printMode="'cpcl'">
        </labelPrinterComponentVue>
 
        <!-- 打印机选择列表 -->
        <view v-if="maskShow" class="uni-mask" @tap="maskShow = false">
            <scroll-view class="uni-scroll_box" scroll-y>
                <view class="uni-list-box" v-for="(device, index) in discoveredDevices" :key="index"
                    @tap="connectBT(device)">
                    <view class="uni-list_name">名称:{{ device.name }}</view>
                    <view class="uni-list_item">{{ connectedDeviceId === device.address?'已连接':'未连接' }}</view>
                </view>
            </scroll-view>
        </view>
    </view>
</template>
 
<script>
    import {
        getUserInfo
    } from "@/utils/auth.js";
    import labelPrinterComponentVue from "@/components/labelPrinterComponent/labelPrinterComponent.vue"
    import {
        CommonUtils
    } from "../../utils/common";
    // import bluetoothTool from '@/plugins/BluetoothTool.js'
    // import permission from '@/plugins/permission.js'
    // import {
    //     InputImage
    // } from '@psdk/frame-imageb';
    // import {
    //     ConnectedDevice,
    //     Lifecycle,
    //     Raw,
    //     FakeConnectedDevice,
    //     WriteOptions,
    // } from '@psdk/frame-father';
    // import {
    //     CBar,
    //     CBox,
    //     CForm,
    //     CImage,
    //     CLine,
    //     CCodeRotation,
    //     CCodeType,
    //     CPage,
    //     CText,
    //     CFont,
    //     CBold,
    //     CRotation,
    //     CInverse,
    //     CMag,
    //     CQRCode,
    //     CCorrectLevel,
    //     CSN,
    //     CStatus,
    // } from "@psdk/cpcl";
    // import {
    //     EImage
    // } from "@psdk/esc";
    export default {
        components: {
            labelPrinterComponentVue
        },
        data() {
            return {
                codeGenComplete: false,
                userInfo: getUserInfo(),
                serverUrl: uni.getStorageSync('serverUrl') || 'http://47.96.97.237/API',
                OperationType: 1, //数据类型  1添加 保存  2复制  3 编辑
                linterid: '',
                HEntryID: '',
                baseInfo: {
                    HMainID: '',
                    HSubID: '',
                    HSourceBillSEQ: null,
                    HSourceBillNo: '',
                    HBillType: '',
                    HMaterID: '',
                    HMaterNumber: '',
                    HMaterName: '',
                    HMaterModel: '',
                    HBillNo: '',
                    "HModel": null,
                    "HPinfan": null,
                    "HPinfanBarCode": null,
                    "HAuxPropID": null,
                    "HAuxPropNumber": null,
                    "HAuxPropName": null,
                    HUnitID: '',
                    "HUnitNumber": "",
                    "HUnitName": "",
                    HQty: '',
                    HMinQty: '',
                    HSupID: '',
                    SHdate: '',
                    HMTONo: '',
                    HBatchNo: '',
                    HBQty: '',
                    HSupID: '',
                    HSupNumber: '',
                    HSupName: '',
                    HPcsName: '',
                    HSupNameShort: '',
                    HMTONo: '',
                    HDate: '',
                    HMaker: getUserInfo()["Czymc"],
                    HCoilNO: '',
                    HFurnaceNO: '',
                    HFactory: '',
                    HSupMaterNumber: '',
                    HInterID: '',
                },
                sWhere: '',
                listData: [],
                printItem: '',
 
                printInfo: "",
                maskShow: false,
                discoveredDevices: [], // 查询到的设备
                connectedDeviceId: ""
            }
        },
        onLoad(e) {
            this.OperationType = e.OperationType
            this.linterid = e.linterid
            this.HEntryID = e.hsubid
            this.HBillType = e.HBillType
            this.getData()
 
            // //#ifdef APP-PLUS
            // // 蓝牙
            // bluetoothTool.init({
            //     listenBTStatusCallback: (state) => {
            //         if (state == 'STATE_ON') {
            //             console.log(state);
            //         }
            //     },
            //     discoveryDeviceCallback: this.onDevice,
            //     discoveryFinishedCallback: function() {
            //         console.log("搜索完成");
            //     },
            //     readDataCallback: function(dataByteArr) {
            //         /* if(that.receiveDataArr.length >= 200) {
            //             that.receiveDataArr = [];
            //         }
            //         that.receiveDataArr.push.apply(that.receiveDataArr, dataByteArr); */
            //         console.log("读取完成" + dataByteArr);
            //     },
            //     connExceptionCallback: function(e) {
            //         console.log(e);
            //     }
            // });
            // //#endif
        },
        computed: {
            HBillTypeName: {
                get() {
                    if (this.HBillType == '1102') {
                        return '采购'
                    }
                    if (this.HBillType == '1103') {
                        return '收料'
                    }
                }
            },
            QtyDisabledMode: {
                get() {
                    let compName = this.getCampanyName()
                    // 禁用数量选择 启用箱数选择
                    if (/小卫电器/.test(compName)) {
                        return 1
                    }
                    // 启用数量选择 禁用箱数选择
                    if (/兴达/.test(compName)) {
                        return 2
                    }
                    // 禁用箱数选择和数量选择
                    return 0
                }
            }
        },
        methods: {
            getData() {
                // 通过单据类型,单据内码和子内码获取对应单据信息
                // '/Cg_POInStockBill/loadCg_POInStockBill_Push'
                uni.request({
                    url: this.serverUrl + '/Web/GetBillInfo_GenerateBillCode',
                    data: {
                        HInterID: this.linterid,
                        HEntryID: this.HEntryID,
                        HBillType: this.HBillType
                    },
                    success: (res) => {
                        if (res.data.count == 1) {
                            var data = res.data.data
                            this.baseInfo = Object.assign(this.baseInfo, {
                                HMainID: data[0].hmainid,
                                HSubID: data[0].hsubid,
                                HBillNo: data[0].单据号,
                                HBillType: data[0]['HBillType'],
                                HSourceBillNo: data[0].单据号,
                                HInnerBillNo: data[0].采购订单号,
                                HMaterID: data[0].HMaterID,
                                HMaterNumber: data[0].物料代码,
                                HMaterName: data[0].物料名称,
                                HMaterModel: data[0].规格型号.replace(/;/g, ';'),
                                HQty: data[0].数量,
                                HMinQty: data[0].数量,
                                HSupID: data[0].HSupID,
                                SHdate: data[0].审核日期,
                                HBatchNo: data[0]['批号'],
                                HSupID: data[0]['HSupID'],
                                HSupNumber: data[0]['供应商代码'],
                                HSupName: data[0]['供应商'],
                                HSupMaterNumber: data[0]['供应商物料编码'],
                                HUnitID: data[0]['HUnitID'],
                                HPcsName: data[0]['计量单位'],
                                HSupNameShort: data[0]['供应商简称'],
                                HMTONo: data[0]['计划跟踪号'].trim(),
                                HDate: data[0]['日期'],
                                HCoilNO: data[0]['款号'],
                                HFurnaceNO: data[0]['分组'],
                                HFactory: data[0]['客户编号'],
                                "HAuxPropID": data[0]['HAuxPropID'],
                                "HAuxPropNumber": data[0]['辅助属性代码'],
                                "HAuxPropName": data[0]['辅助属性名称'],
                            })
 
                            this.baseInfo.HBQty = Math.ceil(this.baseInfo.HQty / this.baseInfo.HMinQty)
 
                            this.listData = data
 
                        } else {
                            uni.showToast({
                                title: res.data.Message,
                                icon: 'none'
                            })
                        }
                    },
                    fail: (res) => {
                        console.log(res);
                        uni.showToast({
                            title: '接口请求失败',
                            icon: 'none'
                        })
                    },
                });
            },
            getNum(e) {
                if (this.baseInfo.HMinQty && this.baseInfo.HMinQty > 0) {
                    var a = Number(this.baseInfo.HQty) / Number(this.baseInfo.HMinQty)
                    this.baseInfo.HBQty = Math.ceil(Number(this.baseInfo.HQty) / Number(this.baseInfo.HMinQty))
                    this.$forceUpdate()
                } else {
                    uni.showToast({
                        title: '请输入大于0的合理数量',
                        icon: "none"
                    })
                }
            },
            getHMinQtyByBQty() {
                if (this.baseInfo.HBQty && this.baseInfo.HBQty > 0) {
                    let minQty = Math.ceil(this.baseInfo.HQty / this.baseInfo.HBQty)
 
 
                    this.baseInfo.HMinQty = minQty
                    this.$forceUpdate()
                } else {
                    uni.showToast({
                        title: '请输入大于0的合理数量',
                        icon: "none"
                    })
                }
            },
            getCampanyName() {
                let organ = uni.getStorageSync('Organization')
                // 应用 小卫电器 条码规则
                if (/小卫|智云/.test(organ)) {
                    return "小卫电器"
                }
                // 应用 余姚兴达起动器 条码规则
                if (/兴达|条码测试/.test(organ)) {
                    return "余姚兴达起动器"
                }
                return 'xxx'
            },
            async getList() {
                let HBarCodeNoStrs = []
                var sMain = []
                // sMain = this.baseInfo
                // var sMainStr = JSON.stringify(sMain);
                //获取选择的组织
                var HOrgType = uni.getStorageSync('Organization');
                //获取选择的工厂代码
                // var CampanyName = uni.getStorageSync('Organization');
                var CampanyName = this.getCampanyName();
                //获取选择的源单类型
                var HSourceBillType = "收料通知单";
                //获取选择的条码类型
                var HSelectBarCodeType = "唯一条码";
 
                if (uni.getStorageSync('Organization').includes('海诚')) {
                    HSelectBarCodeType = "品种条码";
                }
                //获取当前登录人员
                var UserName = uni.getStorageSync('HUserName');
                // let listDataTemp = []
                // let i = 0
                // let barCodeTemplate = await this.getBarCodeTemplate()
                // for (let receiveQty = this.baseInfo.HQty; receiveQty > 0; receiveQty -= this.baseInfo.HMinQty) {
                //     i++
                //     let baseInfoClone = JSON.parse(JSON.stringify(this.baseInfo))
                //     let barCodeNo = ''
                //     if (receiveQty - this.baseInfo.HMinQty >= 0) {
                //         listDataTemp.push(Object.assign(baseInfoClone, {
                //             HQty: this.baseInfo.HMinQty,
                //             HInterID: receiveQty + 1,
                //             HBatchNo: this.baseInfo.HBatchNo,
                //             HMTONo: this.baseInfo.HMTONo,
                //         }))
                //     } else {
                //         listDataTemp.push(Object.assign(baseInfoClone, {
                //             HQty: receiveQty % this.baseInfo.HMinQty,
                //             HInterID: receiveQty + 1,
                //             HBatchNo: '',
                //             HMTONo: '',
                //         }))
                //     }
 
                //     barCodeNo = CommonUtils.replaceWithFunction(barCodeTemplate.Format, (key) => {
                //       // 自定义处理逻辑
                //       let date = new Date()
                //       if (key === 'FlowNumber'){
                //           // 流水号 设置不同的流水号生成逻辑 TODO 通过后端获取流水号
                //           return `${date.getFullYear().toString()}${(date.getMonth() + 1).toString()}${date.getDate().toString()}${i.toString().padStart(3, '0')}`
                //       } 
                //       else {
                //           return baseInfoClone[key]
                //       }
 
                //     });     
 
                //     listDataTemp[listDataTemp.length - 1]['HBarCodeNo'] = barCodeNo
                //     HBarCodeNoStrs.push(
                //         barCodeNo
                //     )
 
                // }
                // console.log('listDataTemp: ',listDataTemp);
                // this.listData = listDataTemp
                // console.log(listDataTemp)
                // HBarCodeNoStrs = JSON.stringify(HBarCodeNoStrs)
                // sMain = listDataTemp
                let sMainStr = JSON.stringify([this.baseInfo])
                let sMainSub = `${sMainStr};${HOrgType};${HSourceBillType};${HSelectBarCodeType};${CampanyName};${UserName};${HBarCodeNoStrs};${this.baseInfo.HFactory || ''};${this
                    .baseInfo.HCoilNO || ''}; ${this.baseInfo.HFurnaceNO || ''}`
                console.log('sMainSub: ', sMainSub);
                uni.showLoading()
                uni.request({
                    url: this.serverUrl + '/Sc_BarCode/Sub_SaveBill',
                    method: 'POST',
                    data: {
                        msg: sMainSub,
                    },
                    success: (res) => {
                        if (res.data.count == 1) {
                            this.listData = res.data.data
                            this.codeGenComplete = true
                            uni.showToast({
                                title: res.data.Message,
                                icon: 'none'
                            })
 
                        } else {
                            uni.showToast({
                                title: res.data.Message,
                                icon: 'none'
                            })
                        }
                    },
                    fail: (res) => {
                        console.log(res);
                        uni.showToast({
                            title: '接口请求失败',
                            icon: 'none'
                        })
                    },
                    complete() {
                        uni.hideLoading()
                    }
                });
            },
            // #region 已废弃
            // async getBarCodeTemplate() {
            //     return new Promise((resolve, reject) => {
            //         CommonUtils.doRequest2({
            //             url: "/Sc_BarCode/Get_BarCodeGenTemplate",
            //             data: {
            //                 HOrginationName: uni.getStorageSync("Organization"),
            //                 HBillSubType: this.HBillType
            //             },
            //             resFunction: (res) => {
            //                 let {
            //                     data,
            //                     count,
            //                     Message
            //                 } = res.data
            //                 if (count == 1) {
            //                     resolve(JSON.parse(data))
            //                 } else {
            //                     uni.showToast({
            //                         icon: 'none',
            //                         title: Message
            //                     })
            //                     reject()
            //                 }
            //             },
            //             errFunction: () => {
            //                 reject()
            //             }
            //         })
            //     })
            // },
            // #endregion
            async checkPermission() { // 授权
                try {
                    let checkResult = await permission.androidPermissionCheck("bluetooth");
                    console.log("检测信息:", checkResult);
                    if (checkResult.code == 1) {
                        let result = checkResult.data;
                        if (result == 1) {
                            console.log("授权成功!");
                        }
                        if (result == 0) {
                            console.log("授权已拒绝!");
                        }
                        if (result == -1) {
                            console.log("您已永久拒绝权限,请在应用设置中手动打开!");
                        }
                    }
                } catch (err) {
                    console.log("授权失败:", err);
                }
            },
            async search() {
                // #ifndef APP-PLUS
                uni.showModal({
                    content: "不支持蓝牙打印功能,请切换移动设备...",
                })
                return
                // #endif
                if (this.$printer.isConnected() === false) {
                    this.$refs.labelPrinter.openPopup()
                } else {
                    let printContent = []
                    let printInfoBuffer = []
                    let count = 0
                    uni.showLoading()
                    console.log('this.listData: ', this.listData);
                    for (let listOne of this.listData) {
                        let Message = await this.getPrintTemplate(listOne.HInterID, listOne.HItemID)
                        printContent.push(Message)
                        count++;
                        if (count == 10) {
                            printInfoBuffer.push(printContent.join("\r\n"))
                            count = 0
                            printContent = []
                        }
                    }
                    uni.hideLoading()
                    printInfoBuffer.push(printContent.join("\r\n"))
                    this.printInfo = JSON.stringify(printInfoBuffer)
                    printInfoBuffer = []
 
                    await this.$nextTick(() => {
                        this.$refs.labelPrinter.execPrint()
                    })
                }
            },
            async getPrintTemplate(HInterID, HItemID) {
                console.log('data: ', {
                    HOrginationName: uni.getStorageSync("Organization"),
                    HBillSubType: this.HBillType,
                    HInterID: HInterID,
                    HItemID: HItemID,
                })
                return new Promise((resolve, reject) => {
                    CommonUtils.doRequest2({
                        url: "/Sc_BarCode/Get_BarCodePrintCode_CPCL",
                        data: {
                            HOrginationName: uni.getStorageSync("Organization"),
                            HBillSubType: this.HBillType,
                            HInterID: HInterID,
                            HItemID: HItemID,
                        },
                        resFunction: (res) => {
                            let {
                                Message,
                                count
                            } = res.data
                            if (count == 1) {
                                console.log('Message: ', Message);
                                resolve(Message)
                            } else {
                                uni.showToast({
                                    icon: 'none',
                                    title: Message
                                })
                                reject();
                            }
                        },
                        errFunction: (err) => {
                            reject();
                        },
 
                    })
                })
            },
            async searchLabelPrinter() {
                // 查找打印机
                var that = this
                // 使用openBluetoothAdapter 接口,免去主动申请权限的麻烦
                uni.openBluetoothAdapter({
                    success: async (res) => {
                        await this.checkPermission();
                        console.log('start discovery devices');
                        this.discoveredDevices = [];
                        console.log(res)
                        bluetoothTool.discoveryNewDevice();
                        this.maskShow = true
                    },
                    fail: async (e) => {
                        console.error(e)
                        switch (e.code) {
                            case "10009":
                                this.showToast("此设备不支持设备搜索功能!");
                                break;
                            default:
                                console.error(e);
                        }
                    }
                })
 
            },
            onDevice(device) {
                console.log("监听寻找到新设备的事件---------------")
                console.log(device)
                if (typeof device === 'undefined') return;
                if (typeof device.name === 'undefined') return;
                console.log(device.name);
                if (device.name === '') return;
                if (device.name === null) return;
                if (device.name.toUpperCase().endsWith('_BLE') ||
                    device.name.toUpperCase().endsWith('-LE') ||
                    device.name.toUpperCase().endsWith('-BLE')) return;
                const isDuplicate = this.discoveredDevices.find(item => item.address === device.address);
                if (isDuplicate) return;
                this.discoveredDevices.push(device);
            },
            connectBT(device) {
                const vm = this;
                uni.showLoading({
                    title: '连接中'
                });
                bluetoothTool.connDevice(device.address, (result) => {
                    console.log(result)
                    uni.hideLoading()
                    if (result) {
                        //     // console.log(result);
                        bluetoothTool.cancelDiscovery();
                        // console.log(vm.$printer)
                        vm.$printer.init(new FakeConnectedDevice());
                        vm.connectedDeviceId = device.address;
                        uni.showToast({
                            icon: 'none',
                            title: '连接成功'
                        })
                        this.maskShow = false
                    } else {
                        uni.showToast({
                            icon: 'none',
                            title: '连接失败'
                        })
                    }
                });
            },
            stopSearchBT() {
                console.log("停止搜寻附近的蓝牙外围设备---------------")
                bluetoothTool.cancelDiscovery();
            },
            closeBluetooth() {
                console.log("停止蓝牙连接")
                const vm = this;
                if (vm.connectedDeviceId != '') {
                    bluetoothTool.closeBtSocket();
                    vm.connectedDeviceId = "";
                }
            },
            async labelPrint(item) {
                // 打印
                this.printItem = item
                if (this.$printer.isConnected() === false) {
                    this.$refs.labelPrinter.openPopup()
                } else {
                    this.printInfo = `! 0 200 200 300 1
                                        PAGE-WIDTH 608
                                        SETQRVER 3
                                        B QR 450 30 M 2 U 5
                                        LA,` + this.printItem.条码编号 + `
                                        ENDQR
                                        T 24 0 24 40 审核日期:` + this.baseInfo.SHdate + `
                                        T 24 0 24 80 物料编码:` + this.printItem.物料代码 + `
                                        T 24 0 24 120 物料名称:` + this.printItem.物料名称 + `
                                        T 24 0 24 160 规格型号:` + this.printItem.规格型号 + `
                                        T 24 0 24 200 物料数量:` + this.baseInfo.HQty + `
                                        T 24 0 24 240 条码数量:` + this.printItem.数量 + `
                                        FORM
                                        PRINT`
                    await this.$nextTick(() => {
                        this.$refs.labelPrinter.execPrint()
                    })
                }
 
                // // 检查蓝牙连接
                // let btStatus = bluetoothTool.getBluetoothStatus()
                // if(btStatus != true) {
                //     this.showToast("蓝牙连接异常!")
                //     return
                // }
 
                // // 检查是否连接设备
                // let pairedDevices = bluetoothTool.getPairedDevices()
                // if(pairedDevices.length < 1) {
                //     this.showToast("无设备连接!")
                //     return
                // }
 
                // // 检查表单项是否有空值
                // for (var key in this.hform) {
                //     if (this.hform[key] == "") {
                //         // todo 提示表单项不能为空
                //         this.showToast("表单不能有空值!")
                //         return
                //     }
                // }
                // this.printWrite()
            },
            // showToast(msg, status = "none") {
            //     uni.showToast({
            //         title: msg,
            //         icon: status,
            //         duration: 2000
            //     });
            // },
            // ///转成安卓有符号的
            // uint8ArrayToSignedArray(uint8Array) {
            //     let signedArray = new Array(uint8Array.length);
            //     for (let i = 0; i < uint8Array.length; i++) {
            //         if (uint8Array[i] >= 128) {
            //             signedArray[i] = uint8Array[i] - 256;
            //         } else {
            //             signedArray[i] = uint8Array[i];
            //         }
            //     }
            //     return signedArray;
            // },
            // async printWrite(type = "cpcl") {
            //     const vm = this;
            //     console.log("开始打印------------------")
            //     switch (type) {
            //         case "cpcl":
            //             await vm.writeCpclModel();
            //             break;
            //     }
            // },
            // async writeCpclModel() {
            //     const vm = this;
            //     try {
            //         const cpcl = await vm.$printer.cpcl().clear()
            //             .page(new CPage({
            //                 width: 608,
            //                 height: 300
            //             }))
            //             .qrcode(new CQRCode({
            //                 x: 450,
            //                 y: 30,
            //                 width: 5,
            //                 content: vm.printItem.条码编号,
            //                 codeRotation: CCodeRotation.ROTATION_0,
            //                 level: CCorrectLevel.L
            //             }))
            //             .text(new CText({
            //                 x: 24,
            //                 y: 40,
            //                 content: vm.baseInfo.SHdate?"审核日期: " + vm.baseInfo.SHdate : "审核日期: ",
            //                 font: CFont.TSS24
            //             }))
            //             .text(new CText({
            //                 x: 24,
            //                 y: 80,
            //                 content: "物料编码: " + vm.printItem.物料代码,
            //                 font: CFont.TSS24
            //             }))
            //             .text(new CText({
            //                 x: 24,
            //                 y: 120,
            //                 content: "物料名称: " + vm.printItem.物料名称,
            //                 font: CFont.TSS24
            //             }))
            //             .text(new CText({
            //                 x: 24,
            //                 y: 160,
            //                 content: "规格型号: " + vm.printItem.规格型号,
            //                 font: CFont.TSS24
            //             }))
            //             .text(new CText({
            //                 x: 24,
            //                 y: 200,
            //                 content: "物料数量: " + vm.baseInfo.HQty,
            //                 font: CFont.TSS24
            //             }))
            //             .text(new CText({
            //                 x: 24,
            //                 y: 240,
            //                 content: "条码数量: " + vm.printItem.数量,
            //                 font: CFont.TSS24
            //             }))
 
            //             .form(new CForm()) //标签纸需要加定位指令
            //             .print();
            //         console.log(cpcl.command().string());
            //         var binary = cpcl.command().binary();
            //         await this.sendMessage(Array.from(this.uint8ArrayToSignedArray(binary)));
            //     } catch (e) {
            //         console.error(e);
            //         uni.showToast({
            //             title: '失败',
            //         });
            //     }
            // },
            // async sendMessage(cmd) {
            //     console.log(cmd);
            //     const result = bluetoothTool.sendByteData(cmd);
            //     uni.showToast({
            //         icon: 'none',
            //         title: result ? '发送成功!' : '发送失败...'
            //     })
            // },
        }
    }
</script>
 
<style lang="scss" scoped>
    .form {
        width: 640rpx;
        margin: 20rpx auto;
    }
 
    .form-item {
        display: flex;
        align-items: center;
        font-size: 28rpx;
        padding: 6rpx 0;
 
        .title {
            width: 180rpx;
 
            text {
                color: red;
                font-weight: bold;
            }
        }
 
        .right {
            width: 450rpx;
            border-radius: 22rpx;
            border: 1px solid #acacac;
        }
 
        .righton {
            width: 450rpx;
            border-radius: 22rpx;
            border: 1px solid #e4e4e4;
            background-color: #e4e4e4;
        }
 
        input {
            width: 100%;
            padding: 8rpx 20rpx;
            font-size: 30rpx;
        }
    }
 
    .buttons {
        width: 100%;
        display: flex;
        justify-content: center;
        margin-top: 20rpx;
 
        button {
            border-radius: 50rpx;
            width: 220rpx;
            height: 66rpx;
            line-height: 66rpx;
            font-size: 28rpx;
        }
 
        .btn-a {
            background-color: #acacac;
            color: #fff;
        }
 
        .btn-b {
            background-color: #41a863;
            color: #fff;
        }
 
        .btn-c {
            background-color: #3a78ff;
            color: #fff;
        }
    }
 
    .list {
        width: 100%;
 
        .card-detail {
            width: 100%;
            display: flex;
            flex-wrap: wrap;
            justify-content: space-between;
            line-height: 120%;
 
            .detail {
                // width: 50%;
                font-size: 26rpx;
                margin-bottom: 12rpx;
                color: #555;
                margin-right: 20rpx;
                word-break: break-all;
 
                text {
                    color: #999;
                    font-size: 26rpx;
 
                }
            }
        }
 
        .more {
            color: #888;
            font-size: 24rpx;
            display: flex;
            border-top: 1px solid #eee;
            padding-top: 20rpx;
 
            .part {
                width: 50%;
                text-align: center;
            }
        }
    }
 
    .uni-mask {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        z-index: 9999;
        display: flex;
        align-items: center;
        width: 100%;
        background: rgba(0, 0, 0, 0.6);
        padding: 0 30rpx;
        box-sizing: border-box;
    }
 
    .uni-scroll_box {
        height: 60%;
        background: #fff;
        border-radius: 20rpx;
    }
 
    .uni-list-box {
        margin: 0 20rpx;
        padding: 15rpx 0;
        border-bottom: 1px #f5f5f5 solid;
        box-sizing: border-box;
    }
 
    .uni-list:last-child {
        border: none;
    }
 
    .uni-list_name {
        font-size: 30rpx;
        color: #333;
    }
 
    .uni-list_item {
        font-size: 24rpx;
        color: #555;
        line-height: 1.5;
    }
 
    .operation-zone {
        display: flex;
        justify-content: space-around;
        margin-top: 10rpx;
 
        .op1 {
            border: 1px solid #41a863;
            color: #41a863;
        }
 
        .op4 {
            border: 1px solid #da0000;
            color: #da0000;
        }
 
    }
</style>