手持机代码初始化

This commit is contained in:
liuhanqing
2025-09-11 14:29:56 +08:00
parent 6dce93327a
commit 3a3d7af8c6
416 changed files with 67555 additions and 0 deletions

View File

@@ -0,0 +1,285 @@
<template>
<view class="container">
<view class="input-group">
<uni-easyinput
v-model="trayCode"
:placeholder="$t('outbound.exception.trayCodePlaceholder')"
:clearable="true"
@input="handleInput"
@clear="handleClear"
ref="trayCodeInput"
>
<template #right>
<text class="scan-icon" @click="handleScan">📷</text>
</template>
</uni-easyinput>
</view>
<view class="table-container" v-if="materialList.length > 0">
<uni-card v-for="(item, index) in materialList" :key="index" class="material-card">
<view class="card-content">
<view class="info-row">
<text class="label">{{ $t('outbound.exception.materialCode') }}:</text>
<text class="value">{{ item.productId }}</text>
</view>
<view class="info-row">
<text class="label">{{ $t('outbound.exception.materialName') }}:</text>
<text class="value">{{ item.extraField.materialDesc }}</text>
</view>
<view class="info-row">
<text class="label">{{ $t('outbound.exception.outQuantity') }}:</text>
<text class="value">{{ item.outQuantity }}</text>
</view>
<view class="info-row">
<text class="label">{{ $t('outbound.exception.pickQuantity') }}:</text>
<uni-easyinput v-model="item.pickQuantity" type="number" :placeholder="$t('outbound.exception.enterPickQuantity')" style="flex: 1;" @input="validatePickQuantity(item)"></uni-easyinput>
</view>
</view>
</uni-card>
</view>
<view class="button-group" v-if="materialList.length > 0">
<button class="submit-button" @click="handleSubmit">{{ $t('outbound.exception.submit') }}</button>
</view>
</view>
</template>
<script>
import { getTaskDetail,submitError} from '@/api/out/productOut.js'
export default {
onReady() {
setTimeout(() => {
this.$nextTick(() => {
this.$refs.trayCodeInput.onFocus()
})
}, 100)
},
data() {
return {
trayCode: '',
materialList: []
}
},
methods: {
// 处理输入事件
async handleInput(value) {
if (value) {
try {
const response = await getTaskDetail({trayCode: value,inOut:'2'})
if (response.code === 200) {
// 设置materialList并初始化pickQuantity为outQuantity的值
this.materialList = (response.data || []).map(item => {
return {
...item,
pickQuantity: item.outQuantity
}
})
} else {
uni.showToast({
title: response.msg || this.$t('common.noData'),
icon: 'none'
})
}
} catch (error) {
console.error(this.$t('outbound.exception.getTrayInfoFailed'), error)
uni.showToast({
title: this.$t('outbound.exception.getTrayInfoFailed'),
icon: 'none'
})
}
}
},
// 处理清除事件
handleClear() {
this.materialList = []
},
// 验证拣货数量不超过出库数量且不为负数
validatePickQuantity(item) {
// 转换为数字
let pickQty = Number(item.pickQuantity)
let outQty = Number(item.outQuantity)
// 检查是否为有效数字
if (isNaN(pickQty) || pickQty === '') {
item.pickQuantity = outQty
return
}
// 检查是否为负数
if (pickQty < 0) {
uni.showToast({
title: this.$t('outbound.exception.pickQuantityNegative'),
icon: 'none'
})
item.pickQuantity = 0
return
}
// 检查是否超过出库数量
if (pickQty > outQty) {
uni.showToast({
title: this.$t('outbound.exception.pickQuantityExceed'),
icon: 'none'
})
item.pickQuantity = outQty
}
},
// 处理扫码事件
handleScan() {
uni.scanCode({
success: (res) => {
this.trayCode = res.result
this.handleInput(res.result)
}
})
},
// 处理提交事件
async handleSubmit() {
if (!this.materialList.length) {
uni.showToast({
title: this.$t('outbound.exception.scanTrayFirst'),
icon: 'none'
})
return
}
// 提交前再次验证所有物料的pickQuantity
let isValid = true
this.materialList.forEach(item => {
// 转换为数字
let pickQty = Number(item.pickQuantity)
let outQty = Number(item.outQuantity)
// 检查是否为有效数字
if (isNaN(pickQty) || pickQty === '') {
isValid = false
uni.showToast({
title: this.$t('outbound.exception.invalidPickQuantity'),
icon: 'none'
})
item.pickQuantity = outQty
return
}
// 检查是否为负数
if (pickQty < 0) {
isValid = false
uni.showToast({
title: this.$t('outbound.exception.pickQuantityNegative'),
icon: 'none'
})
item.pickQuantity = 0
return
}
// 检查是否超过出库数量
if (pickQty > outQty) {
isValid = false
uni.showToast({
title: this.$t('outbound.exception.pickQuantityExceed'),
icon: 'none'
})
item.pickQuantity = outQty
}
})
if (!isValid) return
// 准备提交数据,包含所有物料编码和pickQuantity
const materialDetails = this.materialList.map(item => {
return {
jobDetailId: item.jobDetailId,
productId: item.productId,
pickQuantity: item.pickQuantity
}
})
try {
const response = await submitError({
trayCode: this.trayCode,
materialDetails: materialDetails
})
if (response.code === 200) {
uni.showToast({
title: this.$t('outbound.exception.submitSuccess'),
icon: 'success'
})
// 清空数据
this.trayCode = ''
this.materialList = []
} else {
uni.showToast({
title: response.msg || this.$t('outbound.exception.submitFailed'),
icon: 'none'
})
}
} catch (error) {
console.error(this.$t('outbound.exception.submitFailed'), error)
uni.showToast({
title: this.$t('outbound.exception.submitFailed'),
icon: 'none'
})
}
}
}
}
</script>
<style lang="scss">
.container {
padding: 20rpx;
}
.input-group {
margin-bottom: 20rpx;
}
.scan-icon {
font-size: 40rpx;
padding: 0 20rpx;
}
.table-container {
margin-top: 20rpx;
}
.material-card {
margin-bottom: 20rpx;
}
.card-content {
.info-row {
display: flex;
margin-bottom: 10rpx;
.label {
color: #666;
width: 160rpx;
}
.value {
color: #333;
flex: 1;
}
}
}
.button-group {
margin-top: 40rpx;
padding: 0 20rpx;
}
.submit-button {
background-color: #007aff;
color: #fff;
border-radius: 8rpx;
height: 80rpx;
line-height: 80rpx;
font-size: 32rpx;
}
.submit-button:active {
background-color: #0056b3;
}
</style>