添加 条码扫码通用模块 根据递入参数的不同访问不同的视图
添加 条码扫码通用模块 条码生成模块 实现 条码批量转存条码主档 条码批量打印
2个文件已修改
2个文件已添加
1274 ■■■■■ 已修改文件
pages.json 66 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pages/index/index.vue 23 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pages/tiaomaguanli/table.vue 266 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pages/tiaomaguanli/table_son.vue 919 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pages.json
@@ -603,137 +603,131 @@
        },
        {
            "path" : "pages/shengchanlingliaoshengdan/table",
            "style" :
            {
            "style": {
                "navigationBarTitleText" : "生产领料",
                "enablePullDownRefresh": true
            }
        },
        {
            "path" : "pages/shengchanlingliaoshengdan/form",
            "style" :
            {
            "style": {
                "navigationBarTitleText" : "生产领料单"
            }
        },
        {
            "path" : "pages/weiwailingliao/table",
            "style" :
            {
            "style": {
                "navigationBarTitleText" : "委外领料",
                "enablePullDownRefresh": true
            }
        },
        {
            "path" : "pages/weiwailingliao/form",
            "style" :
            {
            "style": {
                "navigationBarTitleText" : "委外领料单"
            }
        },
        {
            "path" : "pages/shengchanrukushengdan/table",
            "style" :
            {
            "style": {
                "navigationBarTitleText" : "生产入库",
                "enablePullDownRefresh": true
            }
        },
        {
            "path" : "pages/shengchanrukushengdan/form",
            "style" :
            {
            "style": {
                "navigationBarTitleText" : "生产入库单"
            }
        },
        {
            "path" : "pages/shengchanbuliao/table",
            "style" :
            {
            "style": {
                "navigationBarTitleText" : "生产补料",
                "enablePullDownRefresh": true
            }
        },
        {
            "path" : "pages/shengchanbuliao/form",
            "style" :
            {
            "style": {
                "navigationBarTitleText" : "生产补料单"
            }
        },
        {
            "path" : "pages/qitaruku_v2/table",
            "style" :
            {
            "style": {
                "navigationBarTitleText" : "其他入库",
                "enablePullDownRefresh": true
            }
        },
        {
            "path" : "pages/qitaruku_v2/form",
            "style" :
            {
            "style": {
                "navigationBarTitleText" : "其他入库单"
            }
        },
        {
            "path" : "pages/qitachuku_v2/table",
            "style" :
            {
            "style": {
                "navigationBarTitleText" : "其他出库",
                "enablePullDownRefresh": true
            }
        },
        {
            "path" : "pages/qitachuku_v2/form",
            "style" :
            {
            "style": {
                "navigationBarTitleText" : "其他出库单"
            }
        },
        {
            "path" : "pages/zhijiediaobo/table",
            "style" :
            {
            "style": {
                "navigationBarTitleText" : "直接调拨",
                "enablePullDownRefresh": true
            }
        },
        {
            "path" : "pages/zhijiediaobo/form",
            "style" :
            {
            "style": {
                "navigationBarTitleText" : "直接调拨单"
            }
        },
        {
            "path" : "pages/xiugaimima/index",
            "style" :
            {
            "style": {
                "navigationBarTitleText" : "修改密码"
            }
        },
        {
            "path" : "pages/jishikucunchaxun/table",
            "style" :
            {
            "style": {
                "navigationBarTitleText" : "ERP及时库存查询"
                // "enablePullDownRefresh": true
            }
        },
        {
            "path" : "pages/weiwairuku/table",
            "style" :
            {
            "style": {
                "navigationBarTitleText" : "委外入库"
            }
        },
        {
            "path" : "pages/weiwairuku/form",
            "style" :
            {
            "style": {
                "navigationBarTitleText" : "委外入库单"
            }
        },
        {
            "path": "pages/tiaomaguanli/table",
            "style": {
                "navigationBarTitleText": "条码管理"
            }
        },
        {
            "path": "pages/tiaomaguanli/table_son",
            "style": {
                "navigationBarTitleText": "条码生成"
            }
        }
    ],
    "tabBar": {
pages/index/index.vue
@@ -6,7 +6,8 @@
            </view>
        </view>
        <view class="mains">
            <view v-if="!canEdit" :hidden="item.hidden" class="box" v-for="(item,index) in itemData" :key="index" @tap="toUrl(item)">
            <view v-if="!canEdit" :hidden="item.hidden" class="box" v-for="(item,index) in itemData" :key="index"
                @tap="toUrl(item)">
                    <image :src="item.img" mode=""></image>
                    <view class="texts">
                        {{item.text}}
@@ -28,9 +29,16 @@
<script>
    import vers from './vers.vue';
    import { setMenuList, getMenuList } from '../../utils/menuListApp';
    import { CommonUtils } from '../../utils/common';
    import { getUserInfo } from '../../utils/auth';
    import {
        setMenuList,
        getMenuList
    } from '../../utils/menuListApp';
    import {
        CommonUtils
    } from '../../utils/common';
    import {
        getUserInfo
    } from '../../utils/auth';
    export default {
        components: {
            vers,
@@ -42,6 +50,12 @@
                canEdit: false,
                serverUrl: uni.getStorageSync('serverUrl') || 'http://47.96.97.237/API',
                itemData: [{
                    img: '../../static/icon/icon8.png',
                    text: '条码管理-收料通知单',
                    url: '/pages/tiaomaguanli/table?HBillType=1103',
                    id: 1,
                    hidden: false,
                }, {
                    img: '../../static/icon/icon8.png',
                    text: '采购订单标签',
                    url: '/pages/caigoudingdan/caigoudingdan',
@@ -524,6 +538,7 @@
        view[enable-hidden] {
            opacity: .4 !important;
        }
        view[hidden] {
            display: none;
        }
pages/tiaomaguanli/table.vue
New file
@@ -0,0 +1,266 @@
<template>
    <view class="content">
        <view class="form">
            <view class="form-item">
                <view class="title"><text>*</text>条码:</view>
                <view class="right" style="width: 380rpx;">
                    <input :focus="HBarCodeFocus" v-model="HBarCode" placeholder="请扫描(或输入)条码" @confirm="getCode(HBarCode)"/>
                </view>
                <uni-icons type="scan" style="margin-left: 10rpx;background-color: #3A78FF;padding: 6rpx;color: #fff;border-radius: 100%;" size="20" @click="toScanCode"></uni-icons>
            </view>
            <view class="form-item">
                <view class="title">单据号:</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.HSupName" disabled/>
                </view>
            </view>
            <view class="form-item">
                <view class="title">部门:</view>
                <view class="righton">
                    <input v-model="baseInfo.HDeptName" disabled/>
                </view>
            </view>
        </view>
        <view style="width: 100%;height: 16rpx;background-color: #e5e5e5;"></view>
        <view class="list" v-for="(item,index) in listData" :key="index" @tap="toSon(item)">
            <uni-card :title="item.物料代码" :extra="'No. ' + Number(index+1)" style="margin: 10px;">
                <view class="card-detail">
                    <view class="detail">
                        <text>物料名称:</text>{{item.物料名称}}
                    </view>
                    <view class="detail">
                        <text>规格型号:</text>{{item.规格型号}}
                    </view>
                    <view class="detail">
                        <text>订单数量:</text>{{item.数量}}
                    </view>
                </view>
            </uni-card>
        </view>
        <view class="over" v-if="listData.length == 0">暂无数据</view>
        <view class="over" v-if="listData.length != 0">已到底</view>
    </view>
</template>
<script>
    import { CommonUtils } from "../../utils/common";
import { getUserInfo } from "@/utils/auth.js";
    export default {
        data() {
            return {
                HBarCodeFocus: false,
                userInfo:getUserInfo(),
                serverUrl: uni.getStorageSync('serverUrl')||'http://47.96.97.237/API',
                HBarCode:'',
                baseInfo:{
                    HBillNo:'',
                    HSupName:'',
                    HDeptName:'',
                    HInterID:'',
                    HBillType: 0,
                },
                sWhere:'',
                listData:[],
            }
        },
        onLoad(params) {
            this.HBarCodeFocus = true
            if(!CommonUtils.isEmpty(params.HBillType)) {
                this.baseInfo.HBillType = params.HBillType
            }
            console.log(this.baseInfo.HBillType)
        },
        methods: {
            async refreshBarCodeState() {
                this.HBarCodeFocus = false
                await this.$nextTick(() => {
                    this.HBarCodeFocus = true
                    this.HBarCode = ""
                })
            },
             playSound(e){
                const innerAudioContext = uni.createInnerAudioContext();
                if(e == 1){
                    innerAudioContext.src = '/static/success.wav';
                }else{
                    innerAudioContext.src = '/static/jingbao.wav';
                }
                innerAudioContext.play(); // 播放音频
            },
            //扫码
            toScanCode(){
                var mpaasScanModule = uni.requireNativePlugin("Mpaas-Scan-Module")
                mpaasScanModule.mpaasScan({
                    'hideAlbum': true,
                    'timeoutInterval':'10', //超时时间
                    'timeoutText':'未识别到二维码' //超时提醒
                },(ret) => {
                    console.log(ret.resp_result)
                    this.HBarCode = ret.resp_result
                    this.getCode(this.HBarCode)
                })
            },
            //扫条码处理
            getCode(HBarCode){
                if(!HBarCode){
                    this.playSound(0)
                    this.refreshBarCodeState()
                    uni.showToast({
                        title:'条码不能为空',
                        icon:'none'
                    })
                }else{
                    let [HBarCodeBillNo] = HBarCode.split("@") //第一个参数表示单据号
                    let HBillType = this.baseInfo.HBillType
                    uni.request({
                        url: this.serverUrl + '/Web/GetBillInfo',
                        data: { HBillno: HBarCodeBillNo, HBillType: HBillType , HStockOrgID: uni.getStorageSync("OrganizationID") },
                        success: (res) => {
                            console.log('扫码返回',res.data.data);
                            this.HBarCode = ''
                            if(res.data.count == 1){
                                this.playSound(1)
                                var data = res.data.data
                                this.baseInfo = {
                                    HBillNo:data[0].单据号,
                                    HSupName:data[0].供应商,
                                    HDeptName:data[0].部门,
                                    HInterID:data[0].hmainid,
                                    HBillType: this.baseInfo.HBillType
                                }
                                this.listData = data
                            }else{
                                this.playSound(0)
                                this.refreshBarCodeState()
                                uni.showToast({
                                    title:res.data.Message,
                                    icon:'none'
                                })
                            }
                        },
                        fail: (res) => {
                            this.playSound(0)
                            this.refreshBarCodeState()
                            console.log(res);
                            uni.showToast({
                                title:'接口请求失败',
                                icon:'none'
                            })
                        },
                    });
                }
            },
            toSon(item){
                uni.navigateTo({
                    url:'./table_son?OperationType=1&closeType=1&linterid=' + item.hmainid + '&hsubid=' + item.hsubid
                })
            }
        }
    }
</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: 180rpx;
            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;
                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;
            }
        }
    }
</style>
pages/tiaomaguanli/table_son.vue
New file
@@ -0,0 +1,919 @@
<template>
    <view class="content">
        <view class="form">
            <view class="form-item">
                <view class="title">收料单号:</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="righton">
                    <input v-model="baseInfo.HBQty" disabled />
                </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"
                    @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.物料代码" :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}}
                    </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: '',
                    HBillNo: '',
                    HMaterID: '',
                    HMaterNumber: '',
                    HMaterName: '',
                    HMaterModel: '',
                    HQty: '',
                    HMinQty: '',
                    HSupID: '',
                    SHdate: '',
                    HMTONo: '',
                    HBatchNo: '',
                    HBQty: '',
                    HSupID: '',
                    HSupNumber: '',
                    HSupName: '',
                    HUnitID: '',
                    HPcsName: '',
                    HSupNameShort: '',
                    HMTONo: '',
                    HDate: '',
                    HSourceBillNo: '',
                    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.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
        },
        methods: {
            getData() {
                uni.request({
                    url: this.serverUrl + '/Cg_POInStockBill/loadCg_POInStockBill_Push',
                    data: {
                        HInterID: this.linterid,
                        HSubID: this.HEntryID
                    },
                    success: (res) => {
                        if (res.data.count == 1) {
                            var data = res.data.data
                            this.baseInfo = Object.assign(this.baseInfo, {
                                HMainID: data[0].linterid,
                                HSubID: data[0].hsubid,
                                HBillNo: data[0].单据号,
                                HSourceBillNo: data[0].单据号,
                                HInnerBillNo: data[0].采购订单号,
                                HMaterID: data[0].HMaterID,
                                HMaterNumber: data[0].物料代码,
                                HMaterName: data[0].物料名称,
                                HMaterModel: data[0].规格型号,
                                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]['客户编号'],
                            })
                            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"
                    })
                }
            },
            getList() {
                let HBarCodeNoStrs = []
                var sMain = []
                // sMain = this.baseInfo
                // var sMainStr = JSON.stringify(sMain);
                //获取选择的组织
                var HOrgType = uni.getStorageSync('Organization');
                //获取选择的工厂代码
                var CampanyName = "xxx";
                //获取选择的源单类型
                var HSourceBillType = "收料通知单";
                //获取选择的条码类型
                var HSelectBarCodeType = "品种条码";
                //获取当前登录人员
                var UserName = uni.getStorageSync('HUserName');
                let listDataTemp = []
                for (let receiveQty = this.baseInfo.HQty; receiveQty > 0; receiveQty -= this.baseInfo.HMinQty) {
                    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: this.receiveQty,
                        }))
                    } else {
                        listDataTemp.push(Object.assign(baseInfoClone, {
                            HQty: receiveQty % this.baseInfo.HMinQty,
                            HInterID: this.receiveQty,
                        }))
                    }
                    barCodeNo =
                        `${baseInfoClone.HBillNo}@${baseInfoClone.HSubID}@${baseInfoClone.HMaterNumber || ''}@${baseInfoClone.HMTONo || ''}@${baseInfoClone.HQty || 0}`
                    listDataTemp[listDataTemp.length - 1]['HBarCodeNo'] = barCodeNo
                    HBarCodeNoStrs.push(
                        barCodeNo
                    )
                }
                this.listData = listDataTemp
                HBarCodeNoStrs = JSON.stringify(HBarCodeNoStrs)
                sMain = listDataTemp
                let sMainStr = JSON.stringify(listDataTemp)
                let sMainSub = sMainStr + ';' + HOrgType + ';' + HSourceBillType + ';' + HSelectBarCodeType + ';' +
                    CampanyName + ';' + UserName + ';' + HBarCodeNoStrs + ';' + this.baseInfo.HFactory + ';' + this
                    .baseInfo.HCoilNO + ';' + this.baseInfo.HFurnaceNO + '';
                uni.showLoading()
                uni.request({
                    url: this.serverUrl + '/Sc_BarCode/SaveBarCode_NoGenerate_Batch',
                    method: 'POST',
                    data: {
                        msg: sMainSub,
                        CampanyName: CampanyName
                    },
                    success: (res) => {
                        if (res.data.count == 1) {
                            this.codeGenComplete = true
                            console.log(this.listData)
                            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()
                    }
                });
            },
            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()
                    for (let listOne of this.listData) {
                        //                         let pcsInfo = this.baseInfo.HPcsName ? '(' + this.baseInfo.HPcsName + ')' : ''
                        //                         let HFurnaceNO = this.baseInfo.HFurnaceNO.split('.')
                        //                         printContent.push(`! 0 200 200 400 1
                        // PAGE-WIDTH 608
                        // SETQRVER 3
                        // B QR 475 15 Q 0 U 3
                        // LA,${listOne.HBarCodeNo}
                        // ENDQR
                        // T 24 0 0 30 供应商: ${listOne.HSupNameShort}
                        // T 55 0 0 55 (Supplier)
                        // T 24 0 200 30 客户编号: ${listOne.HFactory || ''}
                        // T 55 0 200 55 (Consumer No.)
                        // T 24 0 0 75 物料编码: ${listOne.HMaterNumber}
                        // T 55 0 0 100 (Material Number)
                        // T 24 0 0 120 物料名称: ${listOne.HMaterName}
                        // T 55 0 0 145 (Material Code)
                        // T 24 0 0 165 款号: ${listOne.HCoilNO || ''}
                        // T 55 0 0 190 (Style No.)
                        // T 24 0 300 165 供应商料号: ${listOne.HSupMaterNumber}
                        // T 55 0 300 190 (Supplier Sku No.)
                        // T 24 0 0 210 分组: ${HFurnaceNO[1] || HFurnaceNO[0] || ''}
                        // T 55 0 0 235 (Group)
                        // T 24 0 300 210 规格: ${listOne.HMaterModel}
                        // T 55 0 300 235 (SKU NO.)
                        // T 24 0 0 255 数量: ${ parseFloat(listOne.HQty || 0).toFixed(0) } ${pcsInfo}
                        // T 55 0 0 280 (Quantity)
                        // T 24 0 300 255 日期: ${listOne.HDate || ''}
                        // T 55 0 300 280 (Date)
                        // T 24 0 0 300 检验员:
                        // L 80 325 250 325 3
                        // T 55 0 0 325 (QC)
                        // T 24 0 300 300 采购单号: ${listOne.HInnerBillNo || ''}
                        // T 55 0 300 325 (Purchase Order No.)
                        // T 24 0 0 345 检验结果:
                        // T 55 0 0 370 (Inspection status)
                        // BOX 240 345 260 365 4
                        // T 24 0 270 345 合格
                        // T 55 0 250 370 (Pass)
                        // BOX 340 345 360 365 4
                        // T 24 0 370 345 不合格
                        // T 55 0 370 370 (Fail)
                        // BOX 460 345 480 365 4
                        // T 24 0 490 345 特采
                        // T 55 0 440 370 (Spec. accepted)
                        // FORM
                        // PRINT`)
                        let Message = await this.getPrintTemplate()
                        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() {
                return new Promise((resolve, reject) => {
                    CommonUtils.doRequest2({
                        url: "/Sc_BarCode/Get_BarCodePrintCode_CPCL",
                        data: {
                            HOrginationName: uni.getStorageSync("Organization"),
                            HBillInterID: this.linterid,
                            HBillEntryID: this.HEntryID,
                            HViewName: 'h_v_IF_POInStockBillList',
                            HBillSubType: '1203'
                        },
                        resFunction: (res) => {
                            let {
                                Message,
                                count
                            } = res.data
                            if (count == 1) {
                                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>