剩余模块:生产退料

This commit is contained in:
2025-06-10 18:59:21 +08:00
parent 8fb1a6d4fd
commit 4b64b119c8
23 changed files with 1628 additions and 1085 deletions

View File

@@ -4,8 +4,8 @@
<l-header :title="t('index.zbdy')" sticky></l-header>
<view class="input-box" @click="printingMachineSelectFun">
<view class="input-item">
<up-input :placeholder="t('index.qxzdyj')" border="none" clearable inputAlign="left" v-model="state.printingMachine.name"
confirmType="next" :disabled="true">
<up-input :placeholder="t('index.qxzdyj')" border="none" clearable inputAlign="left"
v-model="state.printingMachine.name" confirmType="next" :disabled="true">
<template #prefix>
<view class="item-title" style="margin-right: 16rpx;">{{ t('index.dyj') }}</view>
</template>
@@ -15,11 +15,29 @@
</up-input>
</view>
</view>
<view class="input-box" @click="()=>{state.pickerShow = true}">
<view class="input-item">
<up-input :placeholder="t('index.qxztd')" border="none" clearable inputAlign="left" v-model="state.centerText"
confirmType="next" :disabled="true">
<template #prefix>
<view class="item-title" style="margin-right: 16rpx;">{{ t('index.td') }}</view>
</template>
<template #suffix>
<up-icon name="search" color="#6c6c6c" size="24"></up-icon>
</template>
</up-input>
</view>
</view>
<view class="btnList" style="margin-top: 32rpx;">
<up-button class="btnItem" type="primary" shape="circle" :text="t('index.dyj')" @click="sendHexStr"></up-button>
</view>
</view>
<bluetoothList ref="bluetoothListRef" :dataList="state.bluetoothList" @getAddress="getAddressFun" />
<up-picker :show="state.pickerShow" keyName="title" :columns="state.pickerList"
@close="() => {state.pickerShow = false}" @cancel="() => {state.pickerShow = false}"
@confirm="pickerConfirmFun"></up-picker>
</view>
</template>
@@ -40,6 +58,13 @@
// #endif
const state = reactive({
centerText: '',
centerObj: {},
pickerShow: false,
pickerList: [[
{ title: computed(() => t('index.bzwlbq')), index: '1' },
{ title: computed(() => t('index.jskcbq')), index: '2' },
]],
id: '',
FBillNo: '',
pageData: {},
@@ -58,18 +83,24 @@
console.log(state.pageData);
})
onShow(() => {
state.centerText = state.pickerList[0][0].title
state.centerObj = state.pickerList[0][0]
uni.getLocation({
type: 'wgs84',
success(res) {
console.log('开启定位权限', res)
},
fail: (err:any) => { }
fail: (err : any) => { }
});
// #ifdef APP-PLUS
hasPermission()
// #endif
})
const pickerConfirmFun = (val : any) => {
state.centerObj = val.value[0]
state.centerText = val.value[0].title
state.pickerShow = false
}
//获取蓝牙权限并打开蓝牙
const hasPermission = () => {
console.log(uni.getStorageSync('printInfo'));
@@ -151,7 +182,6 @@
const createLabel = (item : any) => {
var command = tsc.default.createNew()
command.setSize(100, 50)
command.setGap(2)
command.setCls()
command.setQR(30, 100, "L", 7, "A", item.FBarCode)
@@ -166,59 +196,61 @@
command.setPagePrint()
state.sendData = command.getData();
}
const createLabe2 = (item : any) => {
var command = tsc.default.createNew()
command.setSize(89, 28)
command.setGap(2)
command.setCls()
command.setQR(50, 20, "L", 4, "A", item.FBarCode)
command.setText(180, 20, "TSS24.BF2", 1, 1, `P/N${item.FMaterialId}`)
command.setText(180, 60, "TSS24.BF2", 1, 1, `Qty${item.FQty}`)
command.setText(180, 100, "TSS24.BF2", 1, 1, `Batch No${item.FLot}`)
command.setPagePrint()
state.sendData = command.getData();
}
const sendHexStr = async () => {
try {
// 1. 提取通用数据创建逻辑
const createItem = (qty:any) => ({
FBarCodeRule: "01",
FBarCode: `${state.pageData.FBillCode}*${state.pageData.FMaterialId}*${state.pageData.FLotText}*${qty}`,
FBillCode: state.pageData.FBillCode,
FMaterialId: state.pageData.FMaterialId,
FSupplierLot: state.pageData.FSupplierLot,
FLot: state.pageData.FLotText,
FQty: String(qty)
});
// 2. 数值计算只执行一次
const originalQty = Number(state.pageData.FQty);
const splitQty = Number(state.pageData.splitQty);
const remainingQty = originalQty - splitQty;
// 3. 创建数据项数组
const items = [
createItem(remainingQty),
createItem(splitQty)
];
// 4. 密钥应该从安全配置获取,避免硬编码
const API_KEY = process.env.BARCODE_API_KEY || 'qwe123!@#';
// 5. 使用async/await处理异步
const res = await UHIK_BD_BarCodeMainFileSave({
Key: API_KEY,
Items: items
}, true);
if (res.code !== 200) {
uni.$u.toast(res.msg);
return;
}
// 6. 顺序打印(避免使用固定延迟)
for (const [index, item] of items.entries()) {
// 第一个立即执行,后续延迟执行
if (index > 0) {
await new Promise(resolve => setTimeout(resolve, 1000));
}
createLabel(item);
initPrint();
}
} catch (error) {
console.error('标签打印失败:', error);
uni.$u.toast('操作失败,请重试');
}
try {
// 1. 提取通用数据创建逻辑
const createItem = (qty : any) => ({
FBarCodeRule: "01",
FBarCode: `${state.pageData.FBillCode}*${state.pageData.FMaterialId}*${state.pageData.FLotText}*${qty}`,
FBillCode: state.pageData.FBillCode,
FMaterialId: state.pageData.FMaterialId,
FSupplierLot: state.pageData.FSupplierLot,
FLot: state.pageData.FLotText,
FQty: String(qty)
});
const originalQty = Number(state.pageData.FQty);
const splitQty = Number(state.pageData.splitQty);
const remainingQty = originalQty - splitQty;
const items = [
createItem(remainingQty),
createItem(splitQty)
];
const API_KEY = process.env.BARCODE_API_KEY || 'qwe123!@#';
const res = await UHIK_BD_BarCodeMainFileSave({
Key: API_KEY,
Items: items
}, true);
if (res.code !== 200) {
uni.$u.toast(res.msg);
return;
}
for (const [index, item] of items.entries()) {
if (index > 0) {
await new Promise(resolve => setTimeout(resolve, 1000));
}
if (state.centerObj.index === '1') createLabel(item);
if (state.centerObj.index === '2') createLabe2(item);
initPrint();
}
} catch (error) {
console.error('标签打印失败:', error);
uni.$u.toast('操作失败,请重试');
}
}
const initPrint = () => {
if (state.sendData == null) {