From 5dc72639b4fa560c778660bd3bbbb1e38a4f550a Mon Sep 17 00:00:00 2001
From: zrg <z1873@LAPTOP-EAVL132E>
Date: 星期二, 02 十二月 2025 15:18:09 +0800
Subject: [PATCH] 优化条码拆码2 调整凯贝条码打印模板

---
 pages/tiaomachaima/tiaomachaima2.vue | 1097 ++++++++++++++++++++++++++++++++-------------------------
 1 files changed, 622 insertions(+), 475 deletions(-)

diff --git a/pages/tiaomachaima/tiaomachaima2.vue b/pages/tiaomachaima/tiaomachaima2.vue
index 8c401ad..8bccf81 100644
--- a/pages/tiaomachaima/tiaomachaima2.vue
+++ b/pages/tiaomachaima/tiaomachaima2.vue
@@ -1,510 +1,657 @@
 <template>
-    <view class="container">
-        <view class="header">
-            <view class="item">
-                <view class="left">鏉$爜缂栧彿锛�</view>
-                <view class="right">
-                    <input name="HBarCode" v-model="barCodeInfoMeta.barCodeNo" placeholder="璇锋壂鎻忔潯鐮�"
-                        @blur="searchbarCodeInfo" />
-                </view>
-                <view>
-                    <uni-icons type="scan"
-                        style="background-color: #3A78FF;padding: 6rpx;color: #fff;border-radius: 100%;font-weight: 500;"
-                        size="20" @click="toScanCode"></uni-icons>
-                </view>
-            </view>
-            <view class="item">
-                <view class="left">鎷嗙爜鏁伴噺锛�</view>
-                <view class="right">
-                    <input type="number" name="HSplitNum" v-model="barCodeInfoMeta.splitNum" placeholder="璇疯緭鍏ユ媶鐮佹暟閲�" />
-                </view>
-            </view>
-            <view class="item">
-                <view class="left">鍒跺崟浜猴細</view>
-                <view class="right">
-                    <input type="text" disabled name="HMaker" v-model="barCodeInfoMeta.billMaker"
-                        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>
-            </view>
-        </view>
-        <view class="divide"></view>
-        <view class="content">
-            <view class="barcode-detail" v-show="CommonUtils.isEmpty(Object.assign(barCodeInfo, {})) === false">
-                <view class="title">鏉$爜淇℃伅</view>
-                <uni-card>
-                    <view class="detail" style="display: none;">
-                        <text>鏉$爜ID锛�</text>{{barCodeInfo['HItemID'] || '0'}}
-                    </view>
-                    <view class="detail">
-                        <text>鏉$爜缂栧彿锛�</text>{{barCodeInfo['鏉$爜缂栧彿'] || ''}}
-                    </view>
-                    <view class="detail">
-                        <text>鏉$爜鍘熸暟閲忥細</text>{{barCodeInfo['鏁伴噺'] || '0'}}
-                    </view>
-                    <view class="detail">
-                        <text>鍓╀綑鏁伴噺锛�</text>{{barCodeInfo['鍓╀綑鏁伴噺'] || '0'}}
-                    </view>
-                    <view class="dWetail">
-                        <text>鐗╂枡缂栫爜锛�</text>{{barCodeInfo['鐗╂枡浠g爜'] || ''}}
-                    </view>
-                    <view class="detail">
-                        <text>鐗╂枡鍚嶇О锛�</text>{{barCodeInfo['鐗╂枡鍚嶇О'] || ''}}
-                    </view>
-                    <view class="detail">
-                        <text>瑙勬牸鍨嬪彿锛�</text>{{barCodeInfo['瑙勬牸鍨嬪彿'] || ''}}
-                    </view>
-                    <view class="detail">
-                        <text>璁¢噺鍗曚綅锛�</text>{{barCodeInfo['璁¢噺鍗曚綅'] || ''}}
-                    </view>
-                </uni-card>
-            </view>
-            <view class="divide"></view>
-            <view class="barcode-split" v-show="barCodeSplitInfo.length>0">
-                <view class="title">鏉$爜鎷嗙爜</view>
-                <view class="barcode-split-list" v-for="(item,index) in barCodeSplitInfo" :key="index">
-                    <uni-card @tap="ModityHQty(item)">
-                        <view class="detail">
-                            <text>鏉$爜缂栧彿锛�</text>{{item['HBarCode'] || ''}}
-                        </view>
-                        <view class="detail split-num">
-                            <text>鎷嗗垎鏁伴噺锛�</text>{{item['HSplitNum'] || '0'}}
-                        </view>
-                        <view class="detail">
-                            <text>鐗╂枡浠g爜锛�</text>{{item['HNumber'] || ''}}
-                        </view>
-                        <view class="detail">
-                            <text>鐗╂枡鍚嶇О锛�</text>{{item['HName'] || ''}}
-                        </view>
-                        <view class="detail">
-                            <text>瑙勬牸鍨嬪彿锛�</text>{{item['HModel'] || ''}}
-                        </view>
-                        <view class="detail">
-                            <text>璁¢噺鍗曚綅锛�</text>{{barCodeInfo['璁¢噺鍗曚綅'] || ''}}
-                        </view>
-                    </uni-card>
-                </view>
-            </view>
-        </view>
-        <view class="over" v-if="barCodeSplitInfo.length == 0">鏆傛棤鏁版嵁</view>
-        <view class="over" v-if="barCodeSplitInfo.length != 0">宸插埌搴�</view>
-        <view>
-            <!-- 杈撳叆妗嗙ず渚� -->
-            <uni-popup ref="inputDialog" type="dialog">
-                <uni-popup-dialog ref="inputClose" mode="input" title="璇疯緭鍏ユ媶鐮佹暟閲�" :value="dialogVal" placeholder="璇疯緭鍏ユ媶鐮佹暟閲�"
-                    @confirm="dialogInputConfirm"></uni-popup-dialog>
-            </uni-popup>
-        </view>
-        <labelPrinterComponentVue ref="labelPrinter" :printInfo="printInfo" :printMode="'cpcl'">
-        </labelPrinterComponentVue>
-    </view>
+	<view class="container">
+		<view class="header">
+			<view class="item">
+				<view class="left">鏉$爜缂栧彿锛�</view>
+				<view class="right">
+					<input :focus="HBarCodeFocus" v-model="barCodeInfoMeta.barCodeNo" placeholder="璇锋壂鎻忔潯鐮�"
+						@blur="searchbarCodeInfo" @confirm="getCode(barCodeInfoMeta.barCodeNo)" />
+				</view>
+				<view>
+					<uni-icons type="scan"
+						style="background-color: #3A78FF;padding: 6rpx;color: #fff;border-radius: 100%;font-weight: 500;"
+						size="20" @click="toScanCode"></uni-icons>
+				</view>
+			</view>
+			<view class="item">
+				<view class="left">鎷嗙爜鏁伴噺锛�</view>
+				<view class="right">
+					<input type="number" name="HSplitNum" v-model="barCodeInfoMeta.splitNum" placeholder="璇疯緭鍏ユ媶鐮佹暟閲�" />
+				</view>
+			</view>
+			<view class="item">
+				<view class="left">鍒跺崟浜猴細</view>
+				<view class="right">
+					<input type="text" disabled name="HMaker" v-model="barCodeInfoMeta.billMaker"
+						style="background-color: #e4e4e4;" placeholder="璇疯緭鍏ュ埗鍗曚汉" />
+				</view>
+			</view>
+			<view class="operation-zone">
+				<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>
+		<view class="content">
+			<view class="barcode-detail" v-show="CommonUtils.isEmpty(Object.assign(barCodeInfo, {})) === false">
+				<view class="title">鏉$爜淇℃伅</view>
+				<uni-card>
+					<view class="detail" style="display: none;">
+						<text>鏉$爜ID锛�</text>{{barCodeInfo['HItemID'] || '0'}}
+					</view>
+					<view class="detail">
+						<text>鏉$爜缂栧彿锛�</text>{{barCodeInfo['鏉$爜缂栧彿'] || ''}}
+					</view>
+					<view class="detail">
+						<text>鏉$爜鍘熸暟閲忥細</text>{{barCodeInfo['鏁伴噺'] || '0'}}
+					</view>
+					<view class="detail">
+						<text>鍓╀綑鏁伴噺锛�</text>{{barCodeInfo['鍓╀綑鏁伴噺'] || '0'}}
+					</view>
+					<view class="dWetail">
+						<text>鐗╂枡缂栫爜锛�</text>{{barCodeInfo['鐗╂枡浠g爜'] || ''}}
+					</view>
+					<view class="detail">
+						<text>鐗╂枡鍚嶇О锛�</text>{{barCodeInfo['鐗╂枡鍚嶇О'] || ''}}
+					</view>
+					<view class="detail">
+						<text>瑙勬牸鍨嬪彿锛�</text>{{barCodeInfo['瑙勬牸鍨嬪彿'] || ''}}
+					</view>
+					<view class="detail">
+						<text>璁¢噺鍗曚綅锛�</text>{{barCodeInfo['璁¢噺鍗曚綅'] || ''}}
+					</view>
+				</uni-card>
+			</view>
+			<view class="divide"></view>
+			<view class="barcode-split" v-show="barCodeSplitInfo.length>0">
+				<view class="title">鏉$爜鎷嗙爜</view>
+				<view class="barcode-split-list" v-for="(item,index) in barCodeSplitInfo" :key="index">
+					<uni-card @tap="ModityHQty(item)">
+						<view class="detail">
+							<text>鏉$爜缂栧彿锛�</text>{{item['HBarCode'] || ''}}
+						</view>
+						<view class="detail split-num">
+							<text>鎷嗗垎鏁伴噺锛�</text>{{item['HSplitNum'] || '0'}}
+						</view>
+						<view class="detail">
+							<text>鐗╂枡浠g爜锛�</text>{{item['HNumber'] || ''}}
+						</view>
+						<view class="detail">
+							<text>鐗╂枡鍚嶇О锛�</text>{{item['HName'] || ''}}
+						</view>
+						<view class="detail">
+							<text>瑙勬牸鍨嬪彿锛�</text>{{item['HModel'] || ''}}
+						</view>
+						<view class="detail">
+							<text>璁¢噺鍗曚綅锛�</text>{{barCodeInfo['璁¢噺鍗曚綅'] || ''}}
+						</view>
+					</uni-card>
+				</view>
+			</view>
+		</view>
+		<view class="over" v-if="barCodeSplitInfo.length == 0">鏆傛棤鏁版嵁</view>
+		<view class="over" v-if="barCodeSplitInfo.length != 0">宸插埌搴�</view>
+		<view>
+			<!-- 杈撳叆妗嗙ず渚� -->
+			<uni-popup ref="inputDialog" type="dialog">
+				<uni-popup-dialog ref="inputClose" mode="input" title="璇疯緭鍏ユ媶鐮佹暟閲�" :value="dialogVal" placeholder="璇疯緭鍏ユ媶鐮佹暟閲�"
+					@confirm="dialogInputConfirm"></uni-popup-dialog>
+			</uni-popup>
+		</view>
+		<labelPrinterComponentVue ref="labelPrinter" :printInfo="printInfo" :printMode="'cpcl'">
+		</labelPrinterComponentVue>
+	</view>
 </template>
 
 <script>
-    import labelPrinterComponentVue from '../../components/labelPrinterComponent/labelPrinterComponent.vue';
-    import {
-        CBar,
-        CBox,
-        CForm,
-        CImage,
-        CLine,
-        CCodeRotation,
-        CCodeType,
-        CPage,
-        CText,
-        CFont,
-        CBold,
-        CRotation,
-        CInverse,
-        CMag,
-        CQRCode,
-        CCorrectLevel,
-        CSN,
-        CStatus,
-        CPCL,
-    } from "@psdk/cpcl";
-    import {
-        getUserInfo
-    } from "@/utils/auth.js";
-    import {
-        CommonUtils
-    } from "@/utils/common.js"
-    export default {
-        data() {
-            return {
-                CommonUtils,
-                userInfo: getUserInfo(),
-                serverUrl: uni.getStorageSync('serverUrl') || 'http://47.96.97.237/API',
-                barCodeInfoMeta: {
-                    barCodeNo: "",
-                    splitNum: "",
-                    billMaker: getUserInfo().HEmpName,
-                    billMakerID: getUserInfo().HEmpID
-                },
-                barCodeInfo: {
+	import labelPrinterComponentVue from '../../components/labelPrinterComponent/labelPrinterComponent.vue';
+	import {
+		CBar,
+		CBox,
+		CForm,
+		CImage,
+		CLine,
+		CCodeRotation,
+		CCodeType,
+		CPage,
+		CText,
+		CFont,
+		CBold,
+		CRotation,
+		CInverse,
+		CMag,
+		CQRCode,
+		CCorrectLevel,
+		CSN,
+		CStatus,
+		CPCL,
+	} from "@psdk/cpcl";
+	import {
+		getUserInfo
+	} from "@/utils/auth.js";
+	import {
+		CommonUtils
+	} from "@/utils/common.js"
+	export default {
+		data() {
+			return {
+				CommonUtils,
+				userInfo: getUserInfo(),
+				serverUrl: uni.getStorageSync('serverUrl') || 'http://47.96.97.237/API',
+				barCodeInfoMeta: {
+					barCodeNo: "",
+					splitNum: "",
+					billMaker: getUserInfo().HEmpName,
+					billMakerID: getUserInfo().HEmpID
+				},
+				barCodeInfo: {
 
-                },
-                barCodeSplitInfo: [],
-                dialogVal: 0,
-                itemCache: {},
-                cantGenerate: true,
-                cantPrint: true,
-                printInfo: "" //鎵撳嵃
-            };
-        },
-        components: {
-            labelPrinterComponentVue
-        },
-        methods: {
-            doRequest(url, data, resFunction, errFunction, method) {
-                uni.showLoading({
-                    title: '鍔犺浇涓�...'
-                })
-                uni.request({
-                    method: method || "GET",
-                    url: this.serverUrl + url,
-                    data: data || "",
-                    success: (res) => {
-                        if (typeof resFunction === 'function') {
-                            resFunction.call(this, res)
-                        } else if (typeof errFunction === 'undefined') {
-                            return
-                        } else {
-                            throw new TypeError("璁块棶鎴愬姛鍥炶皟鍑芥暟绫诲瀷寮傚父!")
-                        }
-                    },
-                    fail: (err) => {
-                        uni.showToast({
-                            icon: "error",
-                            title: "鎺ュ彛璁块棶寮傚父!",
-                            duration: 2000
-                        })
-                        if (typeof errFunction === 'function') {
-                            errFunction.call(this, err)
-                        } else if (typeof errFunction === 'undefined') {
-                            return
-                        } else {
-                            throw new TypeError("璁块棶澶辫触鍥炶皟鍑芥暟绫诲瀷寮傚父!")
-                        }
-                    }
-                })
-                uni.hideLoading()
-            },
-            //鎽勫儚澶磋皟鐢�
-            async searchbarCodeInfo() {
-                await this.$nextTick()
-                let urlEncode =
-                    `/Gy_BarCodeBillList/page?sWhere= and 鏉$爜缂栧彿=\'\'${this.barCodeInfoMeta.barCodeNo}\'\'&user=${this.userInfo.HEmpName}&page=1&size=1`
-                    .toString()
-                if (CommonUtils.isEmpty(this.barCodeInfoMeta.barCodeNo) == true) {
-                    return uni.showToast({
-                        icon: "fail",
-                        title: "鏉$爜缂栧彿涓嶈兘涓虹┖!"
-                    })
-                }
-                this.doRequest(
-                    urlEncode, {},
-                    (res) => {
-                        console.log(res)
-                        let res1 = res.data
-                        let {
-                            data,
-                            count
-                        } = res1
-                        if (count > 0) {
-                            this.barCodeInfo = data[0]
-                            this.barCodeSplitInfo = []
-                        }
-                    },
-                    (err) => {
-                        console.err(err)
-                    }
-                )
-            },
-            dialogInputConfirm(val) {
-                this.itemCache["HSplitNum"] = val
+				},
+				barCodeSplitInfo: [],
+				dialogVal: 0,
+				itemCache: {},
+				cantGenerate: true, // 鐢熸垚鎸夐挳鍒濆绂佺敤
+				cantPrint: true, // 鎵撳嵃鎸夐挳鍒濆绂佺敤
+				cantSplit: false, // 鎷嗙爜鎸夐挳鍒濆鍙敤
+				HBarCodeFocus: false,
+				printInfo: "" //鎵撳嵃
+			};
+		},
+		components: {
+			labelPrinterComponentVue
+		},
+		methods: {
+			doRequest(url, data, resFunction, errFunction, method) {
+				uni.showLoading({
+					title: '鍔犺浇涓�...'
+				})
+				uni.request({
+					method: method || "GET",
+					url: this.serverUrl + url,
+					data: data || "",
+					success: (res) => {
+						if (typeof resFunction === 'function') {
+							resFunction.call(this, res)
+						} else if (typeof errFunction === 'undefined') {
+							return
+						} else {
+							throw new TypeError("璁块棶鎴愬姛鍥炶皟鍑芥暟绫诲瀷寮傚父!")
+						}
+					},
+					fail: (err) => {
+						uni.showToast({
+							icon: "error",
+							title: "鎺ュ彛璁块棶寮傚父!",
+							duration: 2000
+						})
+						if (typeof errFunction === 'function') {
+							errFunction.call(this, err)
+						} else if (typeof errFunction === 'undefined') {
+							return
+						} else {
+							throw new TypeError("璁块棶澶辫触鍥炶皟鍑芥暟绫诲瀷寮傚父!")
+						}
+					}
+				})
+				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()
+				let urlEncode =
+					`/Gy_BarCodeBillList/page?sWhere= and 鏉$爜缂栧彿=\'\'${this.barCodeInfoMeta.barCodeNo}\'\'&user=${this.userInfo.HEmpName}&page=1&size=1`
+					.toString()
+				if (CommonUtils.isEmpty(this.barCodeInfoMeta.barCodeNo) == true) {
+					return uni.showToast({
+						icon: "fail",
+						title: "鏉$爜缂栧彿涓嶈兘涓虹┖!"
+					})
+				}
+				this.doRequest(
+					urlEncode, {},
+					(res) => {
+						console.log(res)
+						let res1 = res.data
+						let {
+							data,
+							count
+						} = res1
+						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
 
-                // 鍏抽棴绐楀彛鍚庯紝鎭㈠榛樿鍐呭
-                this.$refs.inputDialog.close()
+				// 鍏抽棴绐楀彛鍚庯紝鎭㈠榛樿鍐呭
+				this.$refs.inputDialog.close()
 
-            },
-            //鎷嗙爜鎸夐挳璋冪敤
-            async searchbarCodeInfoMeta() {
-                this.cantGenerate = true
-                this.cantPrint = true
-                if (CommonUtils.isEmpty(this.barCodeInfoMeta.barCodeNo) === true) {
-                    return uni.showToast({
-                        icon: 'none',
-                        title: '鏉$爜缂栧彿涓嶅緱涓虹┖!'
-                    });
-                }
-                if (CommonUtils.isEmpty(this.barCodeInfoMeta.splitNum, true) === true) {
-                    return uni.showToast({
-                        icon: 'none',
-                        title: '鎷嗗垎鏁伴噺涓嶅緱涓虹┖!'
-                    });
-                }
-                if (CommonUtils.isEmpty(this.barCodeInfoMeta.splitNum, true) === true) {
-                    return uni.showToast({
-                        icon: 'none',
-                        title: '鎷嗗垎鏁伴噺涓嶅緱涓虹┖!'
-                    });
-                }
-                if (parseFloat(this.barCodeInfoMeta.splitNum) > parseFloat(this.barCodeInfo['鏁伴噺'])) {
-                    return uni.showToast({
-                        icon: 'none',
-                        title: '鎷嗗垎鏁伴噺涓嶈兘澶т簬鏉$爜鍘熸暟閲�!'
-                    });
-                }
-                this.doRequest(
-                    "/Sc_BarCode/SplitBarCode_Sub", 
-                    {
-                        HBarCodeNo: this.barCodeInfoMeta.barCodeNo,
-                    },
-                    (res) => {
-                        this.barCodeSplitInfo = []
-                        if (res.data.count > 0) {
+			},
+			//鎷嗙爜鎸夐挳璋冪敤
+			async searchbarCodeInfoMeta() {
+				this.cantGenerate = true
+				this.cantPrint = true
+				this.cantSplit = false // 鎷嗙爜鍓嶇‘淇濇媶鐮佹寜閽彲鐢�
+				if (CommonUtils.isEmpty(this.barCodeInfoMeta.barCodeNo) === true) {
+					return uni.showToast({
+						icon: 'none',
+						title: '鏉$爜缂栧彿涓嶅緱涓虹┖!'
+					});
+				}
+				if (CommonUtils.isEmpty(this.barCodeInfoMeta.splitNum, true) === true) {
+					return uni.showToast({
+						icon: 'none',
+						title: '鎷嗗垎鏁伴噺涓嶅緱涓虹┖!'
+					});
+				}
+				if (CommonUtils.isEmpty(this.barCodeInfoMeta.splitNum, true) === true) {
+					return uni.showToast({
+						icon: 'none',
+						title: '鎷嗗垎鏁伴噺涓嶅緱涓虹┖!'
+					});
+				}
+				if (parseFloat(this.barCodeInfoMeta.splitNum) > parseFloat(this.barCodeInfo['鏁伴噺'])) {
+					return uni.showToast({
+						icon: 'none',
+						title: '鎷嗗垎鏁伴噺涓嶈兘澶т簬鏉$爜鍘熸暟閲�!'
+					});
+				}
+				this.doRequest(
+					"/Sc_BarCode/SplitBarCode_Sub", {
+						HBarCodeNo: this.barCodeInfoMeta.barCodeNo,
+					},
+					(res) => {
+						this.barCodeSplitInfo = []
+						if (res.data.count > 0) {
 
-                            if (res.data.data.length < 1) {
-                                return uni.showToast({
-                                    icon: 'none',
-                                    title: Message
-                                });
-                            }
+							if (res.data.data.length < 1) {
+								return uni.showToast({
+									icon: 'none',
+									title: Message
+								});
+							}
 
-                            //鎷嗗垎鏉$爜锛氭暟閲忎负 splitNum
-                            let barCodeItem1 = JSON.parse(JSON.stringify(res.data.data.SubBarCodes[0]));
-                            let HSplitNum = this.barCodeInfoMeta.splitNum;
-                            this.barCodeSplitInfo.push({
-                                HSplitNum: this.barCodeInfoMeta.splitNum,
-                                HBarCode: res.data.data.NextBarCode,
+							//鎷嗗垎鏉$爜锛氭暟閲忎负 splitNum
+							let barCodeItem1 = JSON.parse(JSON.stringify(res.data.data.SubBarCodes[0]));
+							let HSplitNum = this.barCodeInfoMeta.splitNum;
+							this.barCodeSplitInfo.push({
+								HSplitNum: this.barCodeInfoMeta.splitNum,
+								HBarCode: res.data.data.NextBarCode,
 								HNumber: barCodeItem1.HNumber,
 								HName: barCodeItem1.HName,
 								HModel: barCodeItem1.HModel
-                            });
+							});
 
-                            //鏇存柊鍘熷厛鏉$爜鏁伴噺
-                            this.barCodeInfo['鍓╀綑鏁伴噺'] = this.barCodeInfo['鏁伴噺'] - this.barCodeInfoMeta.splitNum;
+							//鏇存柊鍘熷厛鏉$爜鏁伴噺
+							this.barCodeInfo['鍓╀綑鏁伴噺'] = this.barCodeInfo['鏁伴噺'] - this.barCodeInfoMeta.splitNum;
 
-                            this.cantGenerate = false;
-                        } else {
-                            uni.showToast({
-                                icon: 'none',
-                                title: '娌℃湁鎵惧埌瀵瑰簲鐨勫崟鎹�'
-                            });
-                        }
-                    },
-                    (err) => {
-                        console.error(err)
-                    }
-                )
-            },
-            //淇濆瓨鏂规硶
-            SaveBarCodeCreate() {
-                // 鏍¢獙鎷嗙爜鏁伴噺
-                let sum = this.barCodeSplitInfo.reduce((acc, obj) => {
-                    return acc + obj["HSplitNum"]
-                }, 0)
+							// 鎷嗙爜鎴愬姛锛岀鐢ㄦ媶鐮佹寜閽紝鏀惧紑鐢熸垚鎸夐挳
+							this.cantSplit = true;
+							this.cantGenerate = false;
+							this.cantPrint = true;
+						} else {
+							uni.showToast({
+								icon: 'none',
+								title: '娌℃湁鎵惧埌瀵瑰簲鐨勫崟鎹�'
+							});
+						}
+					},
+					(err) => {
+						console.error(err)
+					}
+				)
+			},
+			//淇濆瓨鏂规硶
+			SaveBarCodeCreate() {
+				// 鏍¢獙鎷嗙爜鏁伴噺
+				let sum = this.barCodeSplitInfo.reduce((acc, obj) => {
+					return acc + obj["HSplitNum"]
+				}, 0)
 
-                if (sum > this.barCodeInfo["HQty"]) {
-                    return uni.showToast({
-                        icon: 'none',
-                        title: '鎷嗙爜鏁伴噺鍜屼笉寰楀ぇ浜庢潯鐮佹暟閲�'
-                    });
-                }
-                let msg =
-                	`${this.barCodeInfoMeta["barCodeNo"]};${this.barCodeInfoMeta["splitNum"]};${JSON.stringify(this.barCodeSplitInfo)};${this.userInfo["HEmpName"]}`
-                this.doRequest(
-                    "/Sc_BarCode/SplitBarCode_Save", {
-                        msg: msg
-                    },
-                    (res) => {
-                        if (res.data.code == 1) {
-                            this.cantGenerate = true
-                            this.cantPrint = false
-                            uni.showToast({
-                                title: '鐢熸垚鎴愬姛!'
-                            });
-                        } else {
-                            this.cantGenerate = false
-                            uni.showToast({
-                                title: res.data.Message
-                            });
-                        }
+				if (sum > this.barCodeInfo["HQty"]) {
+					return uni.showToast({
+						icon: 'none',
+						title: '鎷嗙爜鏁伴噺鍜屼笉寰楀ぇ浜庢潯鐮佹暟閲�'
+					});
+				}
+				let msg =
+					`${this.barCodeInfoMeta["barCodeNo"]};${this.barCodeInfoMeta["splitNum"]};${JSON.stringify(this.barCodeSplitInfo)};${this.userInfo["HEmpName"]}`
+				this.doRequest(
+					"/Sc_BarCode/SplitBarCode_Save", {
+						msg: msg
+					},
+					(res) => {
+						if (res.data.code == 1) {
+							// 鐢熸垚鎴愬姛锛岀鐢ㄧ敓鎴愭寜閽紝鏀惧紑鎵撳嵃鎸夐挳
+							this.cantGenerate = true;
+							this.cantPrint = false;
+							this.cantSplit = true;
+							uni.showToast({
+								title: '鐢熸垚鎴愬姛!'
+							});
+						} else {
+							this.cantGenerate = false;
+							uni.showToast({
+								title: res.data.Message
+							});
+						}
 
-                    },
-                    (err) => {
-                        console.err(err)
-                    },
-                    "POST"
-                )
+					},
+					(err) => {
+						console.err(err)
+					},
+					"POST"
+				)
 
-            },
-            //鎵撳嵃鎸夐挳
-            async PrintHBarCode() {
-                if (this.$printer.isConnected() === false) {
-                    this.$refs.labelPrinter.openPopup()
-                } 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
-	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) 
-	FORM
-	PRINT`
-                console.log('printInfo: ',this.printInfo);
-                    await this.$nextTick(() => {
-                        this.$refs.labelPrinter.execPrint()
-                    })
-                }
-            },
-            toScanCode() {
-                var mpaasScanModule = uni.requireNativePlugin("Mpaas-Scan-Module")
-                mpaasScanModule.mpaasScan({
-                    'hideAlbum': true,
-                    'timeoutInterval': '10', //瓒呮椂鏃堕棿
-                    'timeoutText': '鏈瘑鍒埌浜岀淮鐮�' //瓒呮椂鎻愰啋            
-                }, (ret) => {
-                    console.log(ret.resp_result)
-                    if (this.CommonUtils.isEmpty(ret.resp_result) === false) {
-                        console.log('鏉$爜鍐呭锛�' + ret.resp_result);
-                        this.barCodeInfoMeta.barCodeNo = ret.resp_result
+			},
+			//鎵撳嵃鎸夐挳
+			// 鐖剁粍浠朵腑鐨勬墦鍗版柟娉�
+			async PrintHBarCode() {
+				if (this.$printer.isConnected() === false) {
+					this.$refs.labelPrinter.openPopup();
+					return;
+				}
 
-                        this.searchbarCodeInfo()
-                    }
-                })
-            }
-        },
-        onLoad() {}
-    }
+				// 闃叉閲嶅鐐瑰嚮
+				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 {
+									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 90 0 150 30 鏉窞鍑礉濂堢壒绉戞妧鏈夐檺鍏徃
+			      T 90 0 20 70 P/N: 
+			      T 50 0 80 70 ${item.鐗╂枡浠g爜 || ''}
+			      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`;
+
+					console.log('printInfo: ', this.printInfo);
+
+					// 绛夊緟鎵撳嵃缁勪欢鏇存柊
+					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() {
+				var mpaasScanModule = uni.requireNativePlugin("Mpaas-Scan-Module")
+				mpaasScanModule.mpaasScan({
+					'hideAlbum': true,
+					'timeoutInterval': '10', //瓒呮椂鏃堕棿
+					'timeoutText': '鏈瘑鍒埌浜岀淮鐮�' //瓒呮椂鎻愰啋            
+				}, (ret) => {
+					console.log(ret.resp_result)
+					if (this.CommonUtils.isEmpty(ret.resp_result) === false) {
+						console.log('鏉$爜鍐呭锛�' + ret.resp_result);
+						this.barCodeInfoMeta.barCodeNo = ret.resp_result
+
+						this.searchbarCodeInfo()
+					}
+				})
+			},
+			// 閲嶇疆鎸夐挳鐘舵�佹柟娉�
+			resetButtonState() {
+				this.cantSplit = false; // 鎷嗙爜鎸夐挳鍙敤
+				this.cantGenerate = true; // 鐢熸垚鎸夐挳绂佺敤
+				this.cantPrint = true; // 鎵撳嵃鎸夐挳绂佺敤
+			}
+		},
+		onLoad() {
+			this.HBarCodeFocus = true;
+			// 椤甸潰鍒濆鍖栨椂璁剧疆鎸夐挳鐘舵��
+			this.resetButtonState();
+		}
+	}
 </script>
 
 <style lang="scss">
-    * {
-        box-sizing: border-box;
-    }
+	* {
+		box-sizing: border-box;
+	}
 
-    input {
-        padding: 8rpx 20rpx;
-        font-size: 30rpx;
-        line-height: 30rpx;
-    }
+	input {
+		padding: 8rpx 20rpx;
+		font-size: 30rpx;
+		line-height: 30rpx;
+	}
 
-    button {
-        padding: 0;
-        width: 150rpx;
-        font-size: 25rpx;
-    }
+	button {
+		padding: 0;
+		width: 150rpx;
+		font-size: 25rpx;
+	}
 
-    .uni-card {
-        margin: 0 !important;
-    }
+	.uni-card {
+		margin: 0 !important;
+	}
 
-    .container {
-        .header {
-            padding: 20rpx 10rpx;
-            display: flex;
-            flex-direction: column;
-            gap: 20rpx;
+	.container {
+		.header {
+			padding: 20rpx 10rpx;
+			display: flex;
+			flex-direction: column;
+			gap: 20rpx;
 
-            .item {
-                display: flex;
-                flex-direction: row;
-                padding: 0 10rpx;
-                gap: 20rpx;
-                font-size: 30rpx;
-                // height: 1.5rem;
-                // justify-content: center;
-                align-items: center;
+			.item {
+				display: flex;
+				flex-direction: row;
+				padding: 0 10rpx;
+				gap: 20rpx;
+				font-size: 30rpx;
+				// height: 1.5rem;
+				// justify-content: center;
+				align-items: center;
 
-                .left {
-                    text-align: right;
-                    width: 5rem;
-                }
+				.left {
+					text-align: right;
+					width: 5rem;
+				}
 
-                .right {
-                    flex: 1;
-                    height: 100%;
-                    padding: 6rpx 0;
-                    border-radius: 22rpx;
-                    border: 1px solid #e4e4e4;
-                    background-color: #e4e4e4;
+				.right {
+					flex: 1;
+					height: 100%;
+					padding: 6rpx 0;
+					border-radius: 22rpx;
+					border: 1px solid #e4e4e4;
+					//background-color: #e4e4e4;
 
-                    >input {
-                        height: auto;
-                    }
-                }
-            }
+					>input {
+						height: auto;
+					}
+				}
+			}
 
-            .operation-zone {
-                display: flex;
-                flex-direction: row;
-                justify-content: space-evenly;
+			.operation-zone {
+				display: flex;
+				flex-direction: row;
+				justify-content: space-evenly;
 
-                .btn-c {
-                    background-color: #3a78ff;
-                    color: #fff;
-                }
-            }
-        }
+				.btn-c {
+					background-color: #3a78ff;
+					color: #fff;
+				}
+			}
+		}
 
-        .divide {
-            width: 100%;
-            height: 16rpx;
-            background-color: #e5e5e5;
-        }
+		.divide {
+			width: 100%;
+			height: 16rpx;
+			background-color: #e5e5e5;
+		}
 
-        .content {
-            flex: 1;
+		.content {
+			flex: 1;
 
-            .barcode-detail,
-            .barcode-split {
-                padding: 30rpx;
-                display: flex;
-                flex-direction: column;
-                gap: 30rpx;
-            }
-        }
-    }
+			.barcode-detail,
+			.barcode-split {
+				padding: 30rpx;
+				display: flex;
+				flex-direction: column;
+				gap: 30rpx;
+			}
+		}
+	}
 </style>
\ No newline at end of file

--
Gitblit v1.9.1