2025-06-03 02:55:51 +08:00
|
|
|
|
<template>
|
|
|
|
|
<view class="app status-bar-gap">
|
|
|
|
|
<view class="page">
|
|
|
|
|
<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">
|
|
|
|
|
<template #prefix>
|
|
|
|
|
<view class="item-title" style="margin-right: 16rpx;">{{ t('index.dyj') }}</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" />
|
|
|
|
|
</view>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
|
|
import { reactive, nextTick, onMounted, ref, computed, watch } from 'vue';
|
|
|
|
|
import { onLoad, onShow, onReachBottom, } from '@dcloudio/uni-app'
|
|
|
|
|
import tkiQrcode from '@/components/tki-qrcode/tki-qrcode.vue'
|
|
|
|
|
import { PRD_MOEnterIntoPro, PRD_MORPTGetPrintData, UHIK_BD_BarCodeMainFileSave } from '../../common/request/api/api';
|
|
|
|
|
import { timeFormat } from '@/uni_modules/uview-plus';
|
|
|
|
|
import bluetoothList from './bluetoothList.vue'
|
|
|
|
|
import { useI18n } from 'vue-i18n'
|
|
|
|
|
const getI18n = useI18n()
|
|
|
|
|
const { t, locale } = getI18n
|
|
|
|
|
const bluetoothListRef = ref()
|
|
|
|
|
// #ifdef APP-PLUS
|
|
|
|
|
const blueModule = uni.requireNativePlugin("gp-bluetooth")
|
|
|
|
|
import * as tsc from '../../components/gprint/tsc.js'
|
|
|
|
|
// #endif
|
|
|
|
|
|
|
|
|
|
const state = reactive({
|
|
|
|
|
id: '',
|
|
|
|
|
FBillNo: '',
|
|
|
|
|
pageData: {},
|
|
|
|
|
printingMachine: {
|
|
|
|
|
name: '',
|
|
|
|
|
address: ''
|
|
|
|
|
},
|
|
|
|
|
bluetoothList: [],
|
|
|
|
|
sendData: undefined,
|
|
|
|
|
prontList: [],
|
|
|
|
|
timer: null,
|
|
|
|
|
printState: '0'
|
|
|
|
|
})
|
|
|
|
|
onLoad((pageData : any) => {
|
|
|
|
|
state.pageData = JSON.parse(pageData.data)
|
|
|
|
|
console.log(state.pageData);
|
|
|
|
|
})
|
|
|
|
|
onShow(() => {
|
|
|
|
|
uni.getLocation({
|
|
|
|
|
type: 'wgs84',
|
|
|
|
|
success(res) {
|
|
|
|
|
console.log('开启定位权限', res)
|
|
|
|
|
},
|
|
|
|
|
fail: (err:any) => { }
|
|
|
|
|
});
|
|
|
|
|
// #ifdef APP-PLUS
|
|
|
|
|
hasPermission()
|
|
|
|
|
// #endif
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
//获取蓝牙权限并打开蓝牙
|
|
|
|
|
const hasPermission = () => {
|
|
|
|
|
console.log(uni.getStorageSync('printInfo'));
|
|
|
|
|
blueModule.checkConnect({
|
|
|
|
|
mac: uni.getStorageSync('printInfo').address,
|
|
|
|
|
uuid: '00001101-0000-1000-8000-00805f9b34fb'
|
|
|
|
|
}, (ret : any) => {
|
|
|
|
|
console.log(ret);
|
|
|
|
|
if (!ret.success) {
|
|
|
|
|
uni.setStorageSync('printInfo', {})
|
|
|
|
|
state.printingMachine = {
|
|
|
|
|
name: '',
|
|
|
|
|
address: ''
|
|
|
|
|
}
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
uni.showToast({
|
|
|
|
|
icon: 'none',
|
|
|
|
|
mask: true,
|
|
|
|
|
title: t('index.ljydk'),
|
|
|
|
|
})
|
|
|
|
|
}, 500)
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
blueModule.hasPermission((res : any) => {
|
|
|
|
|
if (res.success) {
|
|
|
|
|
blueModule.isOpen((isOpenRes : any) => {
|
|
|
|
|
console.log(isOpenRes)
|
|
|
|
|
if (isOpenRes.success) {
|
|
|
|
|
state.printingMachine.name = uni.getStorageSync('printInfo').name
|
|
|
|
|
state.printingMachine.address = uni.getStorageSync('printInfo').address
|
|
|
|
|
} else {
|
|
|
|
|
uni.setStorageSync('printInfo', {})
|
|
|
|
|
state.printingMachine.name = ''
|
|
|
|
|
state.printingMachine.address = ''
|
|
|
|
|
blueModule.openBT((openBTRes : any) => {
|
|
|
|
|
console.log(openBTRes)
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
uni.$u.toast(t('index.'))
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
//读取附近蓝牙设备
|
|
|
|
|
const ReadTheAttachedBluetoothDevice = () => {
|
|
|
|
|
state.bluetoothList = []
|
|
|
|
|
blueModule.searchBT((res : any) => {
|
|
|
|
|
if (res.success) {
|
|
|
|
|
console.log(res);
|
|
|
|
|
if (res.data?.name) {
|
|
|
|
|
bluetoothListRef.value.getList(res.data)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
const printingMachineSelectFun = () => {
|
|
|
|
|
ReadTheAttachedBluetoothDevice()
|
|
|
|
|
bluetoothListRef.value.open()
|
|
|
|
|
}
|
|
|
|
|
const getAddressFun = (row : any) => {
|
|
|
|
|
blueModule.connect({
|
|
|
|
|
MACAddress: row.address,
|
|
|
|
|
uuid: '00001101-0000-1000-8000-00805f9b34fb',
|
|
|
|
|
sleepTime: 50
|
|
|
|
|
}, (result : any) => {
|
|
|
|
|
if (result.success) {
|
|
|
|
|
uni.$u.toast(t('index.ljcg'))
|
|
|
|
|
state.printingMachine.name = row.name
|
|
|
|
|
state.printingMachine.address = row.address
|
|
|
|
|
bluetoothListRef.value.close()
|
|
|
|
|
uni.setStorageSync('printInfo', { name: row.name, address: row.address })
|
|
|
|
|
} else {
|
|
|
|
|
uni.$u.toast(t('index.ljsb'))
|
|
|
|
|
}
|
|
|
|
|
}, (data : any) => { })
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const createLabel = (item : any) => {
|
|
|
|
|
var command = tsc.default.createNew()
|
|
|
|
|
command.setSize(100, 50)
|
|
|
|
|
command.setGap(2)
|
|
|
|
|
command.setCls()
|
2025-06-03 04:01:22 +08:00
|
|
|
|
command.setQR(30, 100, "L", 7, "A", item.FBarCode)
|
|
|
|
|
command.setText(280, 40, "TSS24.BF2", 1, 1, `Supplier Name:${item.FSupplierId}`)
|
|
|
|
|
command.setText(280, 80, "TSS24.BF2", 1, 1, `P/N:${item.FMaterialId}`)
|
|
|
|
|
command.setText(280, 120, "TSS24.BF2", 1, 1, `Qty:${item.FQty}`)
|
|
|
|
|
command.setText(280, 160, "TSS24.BF2", 1, 1, `Batch No:${item.FLot}`)
|
|
|
|
|
command.setText(280, 200, "TSS24.BF2", 1, 1, `Supplier Lot No:${item.FSupplierLot}`)
|
|
|
|
|
command.setText(280, 240, "TSS24.BF2", 1, 1, `PO:${state.pageData.PO}`)
|
|
|
|
|
command.setText(280, 280, "TSS24.BF2", 1, 1, `Delivery Date:${state.pageData.Date}`)
|
|
|
|
|
command.setText(280, 320, "TSS24.BF2", 1, 1, `GRN #:${state.pageData.FBillCode}`)
|
2025-06-03 02:55:51 +08:00
|
|
|
|
command.setPagePrint()
|
|
|
|
|
state.sendData = command.getData();
|
|
|
|
|
}
|
|
|
|
|
const sendHexStr = () => {
|
|
|
|
|
let arr = []
|
|
|
|
|
let data1 = {
|
2025-06-03 04:01:22 +08:00
|
|
|
|
FBarCodeRule: "01",
|
2025-06-03 02:55:51 +08:00
|
|
|
|
FBarCode: `${state.pageData.FBillCode}*${state.pageData.FMaterialId}*${state.pageData.FLotText}*${Number(state.pageData.FQty) - Number(state.pageData.splitQty)}`,
|
|
|
|
|
FBillCode:state.pageData.FBillCode,
|
|
|
|
|
FMaterialId: state.pageData.FMaterialId,
|
2025-06-03 04:01:22 +08:00
|
|
|
|
FSupplierLot: state.pageData.FSupplierLot,
|
|
|
|
|
FLot: state.pageData.FLotText,
|
|
|
|
|
FQty: (Number(state.pageData.FQty) - Number(state.pageData.splitQty)) + ''
|
2025-06-03 02:55:51 +08:00
|
|
|
|
}
|
|
|
|
|
let data2 = {
|
2025-06-03 04:01:22 +08:00
|
|
|
|
FBarCodeRule: "01",
|
2025-06-03 02:55:51 +08:00
|
|
|
|
FBarCode: `${state.pageData.FBillCode}*${state.pageData.FMaterialId}*${state.pageData.FLotText}*${Number(state.pageData.splitQty)}`,
|
|
|
|
|
FBillCode:state.pageData.FBillCode,
|
|
|
|
|
FMaterialId: state.pageData.FMaterialId,
|
2025-06-03 04:01:22 +08:00
|
|
|
|
FSupplierLot: state.pageData.FSupplierLot,
|
|
|
|
|
FLot: state.pageData.FLotText,
|
|
|
|
|
FQty: Number(state.pageData.splitQty) + ''
|
2025-06-03 02:55:51 +08:00
|
|
|
|
}
|
|
|
|
|
arr = [data1,data2]
|
|
|
|
|
UHIK_BD_BarCodeMainFileSave({
|
|
|
|
|
Key: 'qwe123!@#',
|
|
|
|
|
Items: arr
|
|
|
|
|
},true).then((res : any) => {
|
|
|
|
|
console.log(res);
|
2025-06-03 04:01:22 +08:00
|
|
|
|
if (res.code == 200) {
|
|
|
|
|
|
|
|
|
|
setTimeout(()=>{
|
|
|
|
|
createLabel(arr[0])
|
|
|
|
|
initPrint()
|
|
|
|
|
},2000)
|
|
|
|
|
setTimeout(()=>{
|
|
|
|
|
createLabel(arr[1])
|
|
|
|
|
initPrint()
|
|
|
|
|
},4000)
|
|
|
|
|
} else {
|
|
|
|
|
uni.$u.toast(res.msg)
|
|
|
|
|
}
|
2025-06-03 02:55:51 +08:00
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
const initPrint = () => {
|
|
|
|
|
if (state.sendData == null) {
|
|
|
|
|
// uni.$u.toast('请先生成指令')
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
state.printState = '1';
|
|
|
|
|
let hexStr = ''
|
|
|
|
|
var data = Array.from(state.sendData)
|
|
|
|
|
for (var i = 0; i < data.length; i++) {
|
|
|
|
|
var str = Number(data[i]).toString(16)
|
|
|
|
|
str = str.length == 1 ? "0" + str : str
|
|
|
|
|
hexStr += str
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function splitString(str, length) {
|
|
|
|
|
var strLen = str.length
|
|
|
|
|
var resArr = []
|
|
|
|
|
for (var i = 0; i < strLen; i += length) {
|
|
|
|
|
resArr.push(str.substring(i, i + length))
|
|
|
|
|
}
|
|
|
|
|
return resArr
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var sendloop = splitString(hexStr, 250);
|
|
|
|
|
console.log(sendloop.length)
|
|
|
|
|
function realWriteData(sendloop, i) {
|
|
|
|
|
var data = sendloop[i]
|
|
|
|
|
if (typeof (data) == "undefined") {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
console.log("第【" + i + "】次写数据" + data)
|
|
|
|
|
var ret = blueModule.sendHexStr(data, (result) => {
|
|
|
|
|
//结果
|
|
|
|
|
console.log('发送结果')
|
|
|
|
|
console.log(result)
|
|
|
|
|
if (!result.success) {
|
|
|
|
|
uni.$u.toast(t('index.ljydk'))
|
|
|
|
|
uni.setStorageSync('printInfo', {})
|
|
|
|
|
state.printingMachine = {
|
|
|
|
|
name: '',
|
|
|
|
|
address: ''
|
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if (result.success) {
|
|
|
|
|
realWriteData(sendloop, i + 1);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
var i = 0;
|
|
|
|
|
realWriteData(sendloop, i);
|
|
|
|
|
state.printState = '0';
|
|
|
|
|
}
|
|
|
|
|
const formatLangTextValue = (val : any) => {
|
|
|
|
|
let lang_Id = uni.getStorageSync('locale')
|
|
|
|
|
let item = val.find(p => p.Key == (lang_Id == 'cn' ? 2052 : 1033));
|
|
|
|
|
if (item != null) {
|
|
|
|
|
return item.Value;
|
|
|
|
|
}
|
|
|
|
|
return val[0].Value;
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
|
:deep(.uni-date__x-input) {
|
|
|
|
|
color: black !important;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
:deep(.u-input) {
|
|
|
|
|
background-color: #ffffff !important;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.app {
|
|
|
|
|
background-color: #F5F5F5;
|
|
|
|
|
|
|
|
|
|
.page {
|
|
|
|
|
padding: 18px 32rpx;
|
|
|
|
|
display: flex;
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
height: 100%;
|
|
|
|
|
flex: 1;
|
|
|
|
|
|
|
|
|
|
.input-box {
|
|
|
|
|
background-color: white;
|
|
|
|
|
box-sizing: border-box;
|
|
|
|
|
padding: 0 16rpx;
|
|
|
|
|
border-radius: 16rpx;
|
|
|
|
|
margin: 16rpx 0;
|
|
|
|
|
|
|
|
|
|
.u-textarea {
|
|
|
|
|
padding: 0 !important;
|
|
|
|
|
font-size: 24rpx !important;
|
|
|
|
|
color: #999999 !important;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.input-item {
|
|
|
|
|
box-sizing: border-box;
|
|
|
|
|
padding: 16rpx 0;
|
|
|
|
|
color: #222222;
|
|
|
|
|
font-size: 28rpx;
|
|
|
|
|
font-weight: 400;
|
|
|
|
|
|
|
|
|
|
.item-title {
|
|
|
|
|
//font-weight: 500;
|
|
|
|
|
font-size: 28rpx;
|
|
|
|
|
color: #333333;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.item-text {
|
|
|
|
|
font-weight: 400;
|
|
|
|
|
font-size: 27rpx;
|
|
|
|
|
color: #999999;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.data-item {
|
|
|
|
|
border: 1px solid #efeaea;
|
|
|
|
|
border-radius: 20rpx;
|
|
|
|
|
padding: 20rpx 22rpx;
|
|
|
|
|
background-color: #ffffff;
|
|
|
|
|
display: flex;
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
|
|
|
|
|
.btnList {
|
|
|
|
|
display: flex;
|
|
|
|
|
margin-bottom: 32rpx;
|
|
|
|
|
|
|
|
|
|
.btnItem {
|
|
|
|
|
width: 40%;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.timebox {
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
margin-top: 32rpx;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.itemBox {
|
|
|
|
|
line-height: 50rpx;
|
|
|
|
|
display: flex;
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
align-items: center;
|
|
|
|
|
margin-bottom: 8rpx;
|
|
|
|
|
|
|
|
|
|
.zongjian {
|
|
|
|
|
height: 1px;
|
|
|
|
|
flex: 1;
|
|
|
|
|
background-color: #f0f0f0;
|
|
|
|
|
margin: 0 16rpx;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</style>
|