chenhaozhe
2025-12-02 29d87fa5b43cc75fc33ccfb3c014527de6062560
Merge branch 'Dev' of http://101.37.171.70:10101/r/~jhz/STUWMS into Dev
1个文件已修改
267 ■■■■ 已修改文件
pages/tiaomachaima/tiaomachaima2.vue 267 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pages/tiaomachaima/tiaomachaima2.vue
@@ -4,8 +4,8 @@
            <view class="item">
                <view class="left">条码编号:</view>
                <view class="right">
                    <input name="HBarCode" v-model="barCodeInfoMeta.barCodeNo" placeholder="请扫描条码"
                        @blur="searchbarCodeInfo" />
                    <input :focus="HBarCodeFocus" v-model="barCodeInfoMeta.barCodeNo" placeholder="请扫描条码"
                        @blur="searchbarCodeInfo" @confirm="getCode(barCodeInfoMeta.barCodeNo)" />
                </view>
                <view>
                    <uni-icons type="scan"
@@ -23,15 +23,16 @@
                <view class="left">制单人:</view>
                <view class="right">
                    <input type="text" disabled name="HMaker" v-model="barCodeInfoMeta.billMaker"
                        placeholder="请输入制单人" />
                        style="background-color: #e4e4e4;" placeholder="请输入制单人" />
                </view>
            </view>
            <view class="operation-zone">
                <button class="btn-c" @click="searchbarCodeInfoMeta">拆码</button>
                <button type="default" :class="cantGenerate?'':'btn-c'" @click="SaveBarCodeCreate"
                    :disabled="cantGenerate = false">生成</button>
                <button type="default" :class="cantPrint?'':'btn-c'" @click="PrintHBarCode"
                    :disabled="cantPrint = false">打印</button>
                <button :class="cantSplit ? 'btn-disabled' : 'btn-c'" @click="searchbarCodeInfoMeta"
                    :disabled="cantSplit">拆码</button>
                <button type="default" :class="cantGenerate ? 'btn-disabled' : 'btn-c'" @click="SaveBarCodeCreate"
                    :disabled="cantGenerate">生成</button>
                <button type="default" :class="cantPrint ? 'btn-disabled' : 'btn-c'" @click="PrintHBarCode"
                    :disabled="cantPrint">打印</button>
            </view>
        </view>
        <view class="divide"></view>
@@ -153,8 +154,10 @@
                barCodeSplitInfo: [],
                dialogVal: 0,
                itemCache: {},
                cantGenerate: true,
                cantPrint: true,
                cantGenerate: true, // 生成按钮初始禁用
                cantPrint: true, // 打印按钮初始禁用
                cantSplit: false, // 拆码按钮初始可用
                HBarCodeFocus: false,
                printInfo: "" //打印
            };
        },
@@ -196,6 +199,24 @@
                })
                uni.hideLoading()
            },
            //声音
            playSound(e) {
                const innerAudioContext = uni.createInnerAudioContext();
                if (e == 1) {
                    innerAudioContext.src = '/static/success.wav';
                } else {
                    innerAudioContext.src = '/static/jingbao.wav';
                }
                innerAudioContext.play(); // 播放音频
            },
            //光标
            async refreshBarCodeState() {
                this.HBarCodeFocus = false
                await this.$nextTick(() => {
                    this.HBarCodeFocus = true
                    this.barCodeInfoMeta.barCodeNo = ""
                })
            },
            //摄像头调用
            async searchbarCodeInfo() {
                await this.$nextTick()
@@ -220,12 +241,61 @@
                        if (count > 0) {
                            this.barCodeInfo = data[0]
                            this.barCodeSplitInfo = []
                            // 扫描条码后重置按钮状态
                            this.resetButtonState();
                        }
                    },
                    (err) => {
                        console.err(err)
                    }
                )
            },
            //红外扫条码
            getCode(HBarCode) {
                if (!HBarCode) {
                    this.playSound(0)
                    this.refreshBarCodeState()
                    uni.showToast({
                        title: '条码不能为空',
                        icon: 'none'
                    })
                } else {
                    uni.request({
                        url: this.serverUrl + '/Gy_BarCodeBillList/page',
                        data: {
                            sWhere: ` and 条码编号=''${this.barCodeInfoMeta.barCodeNo}''`,
                            user: this.userInfo.HEmpName,
                            page: 1,
                            size: 1
                        },
                        success: (res) => {
                            console.log('扫码返回', res.data.data);
                            if (res.data.count == 1) {
                                this.playSound(1)
                                this.barCodeInfo = res.data.data[0]
                                this.barCodeSplitInfo = []
                                // 扫描条码后重置按钮状态
                                this.resetButtonState();
                            } 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'
                            })
                        },
                    });
                }
            },
            dialogInputConfirm(val) {
                this.itemCache["HSplitNum"] = val
@@ -238,6 +308,7 @@
            async searchbarCodeInfoMeta() {
                this.cantGenerate = true
                this.cantPrint = true
                this.cantSplit = false // 拆码前确保拆码按钮可用
                if (CommonUtils.isEmpty(this.barCodeInfoMeta.barCodeNo) === true) {
                    return uni.showToast({
                        icon: 'none',
@@ -263,8 +334,7 @@
                    });
                }
                this.doRequest(
                    "/Sc_BarCode/SplitBarCode_Sub",
                    {
                    "/Sc_BarCode/SplitBarCode_Sub", {
                        HBarCodeNo: this.barCodeInfoMeta.barCodeNo,
                    },
                    (res) => {
@@ -292,7 +362,10 @@
                            //更新原先条码数量
                            this.barCodeInfo['剩余数量'] = this.barCodeInfo['数量'] - this.barCodeInfoMeta.splitNum;
                            // 拆码成功,禁用拆码按钮,放开生成按钮
                            this.cantSplit = true;
                            this.cantGenerate = false;
                            this.cantPrint = true;
                        } else {
                            uni.showToast({
                                icon: 'none',
@@ -326,13 +399,15 @@
                    },
                    (res) => {
                        if (res.data.code == 1) {
                            this.cantGenerate = true
                            this.cantPrint = false
                            // 生成成功,禁用生成按钮,放开打印按钮
                            this.cantGenerate = true;
                            this.cantPrint = false;
                            this.cantSplit = true;
                            uni.showToast({
                                title: '生成成功!'
                            });
                        } else {
                            this.cantGenerate = false
                            this.cantGenerate = false;
                            uni.showToast({
                                title: res.data.Message
                            });
@@ -347,56 +422,118 @@
            },
            //打印按钮
            // 父组件中的打印方法
            async PrintHBarCode() {
                if (this.$printer.isConnected() === false) {
                    this.$refs.labelPrinter.openPopup()
                    this.$refs.labelPrinter.openPopup();
                    return;
                }
                // 防止重复点击
                if (this.isPrinting) {
                    uni.showToast({
                        title: '打印中,请稍候...',
                        icon: 'none'
                    });
                    return;
                }
                this.isPrinting = true;
                try {
                    let HBarCodeNoStr = `${this.barCodeSplitInfo[0]['HBarCode']}`;
                    console.log('获取数据', HBarCodeNoStr);
                    // 显示打印中状态
                    uni.showLoading({
                        title: '打印中...',
                        mask: true
                    });
                    // 获取打印数据
                    const printData = await new Promise((resolve, reject) => {
                        uni.request({
                            url: this.serverUrl + '/Sc_BarCode/GetSplitBarCode_SubList',
                            data: {
                                HBarCodeNo: HBarCodeNoStr
                            },
                            success: (res) => {
                                if (res.data.count == 1) {
                                    resolve(res.data.data[0]);
                } else {
                    let HBarCodeNoStr = `${this.barCodeSplitInfo[0]['HBarCode']}`
                    this.printInfo = `! 0 200 200 400 1
    PAGE-WIDTH 608
    SETQRVER 3
    B QR 475 15 Q 0 U 3
                                    reject(new Error(res.data.Message || '未找到打印数据'));
                                }
                            },
                            fail: (err) => {
                                reject(new Error('接口请求失败'));
                            }
                        });
                    });
                    const item = printData;
                    // 凯贝奈特打印模板
                    this.printInfo = `! 0 200 200 500 1
                  PAGE-WIDTH 800
                  SETQRVER 2
                  B QR 450 120 Q 0 U 4
    LA,${HBarCodeNoStr}
    ENDQR
    T 24 0 0 30 供应商:
    T 55 0 0 55 (Supplier)
    T 24 0 0 75 供应商料号:
    T 55 0 0 100 (Supplier Sku No.)
    T 24 0 0 120 物料名称:
    T 55 0 0 145 (Material Code)
    T 24 0 0 165 款号:
    T 55 0 0 190 (Style No.)
    T 24 0 300 165 客户编号:
    T 55 0 300 190 (Consumer No.)
    T 24 0 0 210 分组:
    T 55 0 0 235 (Group)
    T 24 0 300 210 规格:
    T 55 0 300 235 (SKU NO.)
    T 24 0 0 255 数量:
    T 55 0 0 280 (Quantity)
    T 24 0 300 255 日期:
    T 55 0 300 280 (Date)
    T 24 0 0 300 检验员:
    T 55 0 0 325 (QC)
    T 24 0 300 300 采购单号:
    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)
                  T 90 0 150 30 杭州凯贝奈特科技有限公司
                  T 90 0 20 70 P/N:
                  T 50 0 80 70 ${item.物料代码 || ''}
                  T 90 0 20 110 P/D:
                  T 50 0 80 110 ${item.物料名称 || ''}
                  T 90 0 20 150 D/C:
                  T 50 0 80 150 ${item.生产日期 || ''}
                  T 90 0 220 150 QTY:
                  T 50 0 290 150 ${item.数量 || ''}
                  T 90 0 360 150 ${item.计量单位 || ''}${item.内外标记 || ''}
                  T 90 0 20 190 P/O:
                  T 50 0 80 190 ${item.采购订单号 || ''}
                  T 90 0 20 230 V/C:
                  T 50 0 80 230 ${item.供应商 || ''}
                  T 90 0 20 270 Lot No:
                  T 50 0 100 270 ${item.供应商批次 || ''}
                  T 90 0 20 310 MPN:
                  T 50 0 80 310 ${item.供应商料号 || ''}
                  T 90 0 20 350 MSD:
                  T 50 0 80 350 MSD1
    FORM
    PRINT`
                  PRINT`;
                console.log('printInfo: ',this.printInfo);
                    await this.$nextTick(() => {
                        this.$refs.labelPrinter.execPrint()
                    })
                    // 等待打印组件更新
                    await this.$nextTick();
                    // 执行打印,并等待打印完成
                    const printResult = await this.$refs.labelPrinter.execPrint();
                    console.log('打印结果:', printResult);
                    // 打印成功后重置状态
                    uni.hideLoading();
                    this.isPrinting = false;
                    uni.showToast({
                        title: '打印完成',
                        icon: 'success',
                        duration: 2000
                    });
                    // 播放成功提示音
                    this.playSound(1);
                } catch (error) {
                    console.error('打印失败:', error);
                    uni.hideLoading();
                    this.isPrinting = false;
                    uni.showToast({
                        title: error.message || '打印失败',
                        icon: 'error',
                        duration: 2000
                    });
                    this.playSound(0);
                }
            },
            toScanCode() {
@@ -414,9 +551,19 @@
                        this.searchbarCodeInfo()
                    }
                })
            },
            // 重置按钮状态方法
            resetButtonState() {
                this.cantSplit = false; // 拆码按钮可用
                this.cantGenerate = true; // 生成按钮禁用
                this.cantPrint = true; // 打印按钮禁用
            }
        },
        onLoad() {}
        onLoad() {
            this.HBarCodeFocus = true;
            // 页面初始化时设置按钮状态
            this.resetButtonState();
        }
    }
</script>
@@ -469,7 +616,7 @@
                    padding: 6rpx 0;
                    border-radius: 22rpx;
                    border: 1px solid #e4e4e4;
                    background-color: #e4e4e4;
                    //background-color: #e4e4e4;
                    >input {
                        height: auto;