Files
2025-12-03 16:09:29 +08:00

728 lines
18 KiB
Vue

<template>
<view class="container">
<view class="input-group">
<text class="input-label">{{ $t('inbound.bindMsg.trayCode') }}</text>
<uni-easyinput
v-model="trayCode"
:placeholder="$t('inbound.bindMsg.trayCodePlaceholder')"
:clearable="true"
@input="handleInput"
@clear="handleClear"
ref="trayCodeInput"
>
<template #right>
<text class="scan-icon" @click="handleScan">📷</text>
</template>
</uni-easyinput>
</view>
<view class="input-group">
<text class="input-label">{{ $t('inbound.bindMsg.subOrder') }}</text>
<uni-easyinput
v-model="stockinDetailId"
:placeholder="$t('inbound.bindMsg.subOrderPlaceholder')"
:clearable="true"
@input="handleSubOrderInput"
@clear="handleSubOrderClear"
ref="subOrderInput"
>
</uni-easyinput>
</view>
<!-- 子单据数据弹窗 -->
<uni-popup ref="subOrderPopup" type="center">
<view class="popup-content">
<view class="popup-title">{{ $t('inbound.bindMsg.subOrderInfo') }}</view>
<view class="popup-body">
<view v-if="subOrderInfo" class="info-item">
<view class="info-row">
<text class="info-label">{{ $t('inbound.bindMsg.warehouse') }}</text>
<text class="info-value">{{ subOrderInfo.warehouseName }}</text>
</view>
<view class="info-row">
<text class="info-label">{{ $t('inbound.bindMsg.orderNumber') }}</text>
<text class="info-value">{{ subOrderInfo.stockinId }}</text>
</view>
<view class="info-row">
<text class="info-label">{{ $t('inbound.bindMsg.materialCode') }}</text>
<text class="info-value">{{ subOrderInfo.productId }}</text>
</view>
<view class="info-row">
<text class="info-label">{{ $t('inbound.bindMsg.materialName') }}</text>
<text class="info-value">{{ subOrderInfo.extraField.materialDesc }}</text>
</view>
<view class="info-row quantity-row">
<text class="info-label">{{ $t('inbound.bindMsg.quantity') }}</text>
<uni-easyinput
v-model="inQuantity"
type="number"
:maxlength="String(subOrderInfo.quantity).length"
:placeholder="$t('inbound.bindMsg.maxQuantity') + subOrderInfo.quantity"
@input="handleQuantityInput"
class="quantity-input"
/>
</view>
</view>
<view v-else class="no-data">{{ $t('inbound.bindMsg.noData') }}</view>
</view>
<view class="popup-buttons">
<button class="popup-btn confirm-btn" @click="handleBindSubOrder" :disabled="!subOrderInfo || subOrderInfo.quantity <= 0" :class="{'disabled-btn': !subOrderInfo || subOrderInfo.quantity <= 0}">{{ $t('inbound.bindMsg.bind') }}</button>
<button class="popup-btn cancel-btn" @click="handleCancelSubOrder">{{ $t('inbound.bindMsg.cancel') }}</button>
</view>
</view>
</uni-popup>
<view class="table-container" v-if="materialList.length > 0">
<uni-table border stripe :emptyText="$t('inbound.bindMsg.noData')">
<uni-tr>
<uni-th align="center">{{ $t('inbound.bindMsg.warehouseColumn') }}</uni-th>
<uni-th align="center">{{ $t('inbound.bindMsg.materialNameColumn') }}</uni-th>
<uni-th align="center">{{ $t('inbound.bindMsg.quantityColumn') }}</uni-th>
<uni-th align="center">{{ $t('inbound.bindMsg.operationColumn') }}</uni-th>
</uni-tr>
<uni-tr v-for="(item, index) in materialList" :key="index">
<uni-td align="center">{{ item.warehouseName }}</uni-td>
<uni-td align="center">{{ item.productName }}</uni-td>
<uni-td align="center">{{ item.quantity }}</uni-td>
<uni-td align="center">
<button class="unbind-btn" @click="handleUnbind(item.stockinDetailId)">{{ $t('inbound.bindMsg.unbind') }}</button>
</uni-td>
</uni-tr>
</uni-table>
</view>
<view class="button-group" v-if="materialList.length > 0">
<button class="confirm-button" @click="handleConfirm">{{ $t('inbound.bindMsg.confirmInbound') }}</button>
</view>
<!-- 货位选择弹出框 -->
<uni-popup ref="cargoSpacePopup" type="center">
<view class="popup-content">
<view class="popup-title">{{ $t('inbound.bindMsg.selectCargoSpace') }}</view>
<view class="popup-body">
<view class="input-group cargo-space-input">
<text class="input-label">{{ $t('inbound.bindMsg.cargoSpace') }}</text>
<uni-easyinput
v-model="cargoSpaceName"
:placeholder="$t('inbound.bindMsg.cargoSpacePlaceholder')"
:clearable="true"
@input="handleCargoSpaceInput"
>
<template #right>
<button class="recommend-btn" @click="handleRecommendCargoSpace">{{ $t('inbound.bindMsg.recommendCargoSpace') }}</button>
</template>
</uni-easyinput>
</view>
<view v-if="cargoSpaceHeight" class="cargo-space-height">
<text>{{ $t('inbound.bindMsg.cargoSpaceHeight') }} {{ cargoSpaceHeight }}{{ $t('inbound.bindMsg.meter') }}</text>
</view>
</view>
<view class="popup-buttons">
<button class="popup-btn confirm-btn" @click="handleConfirmCargoSpace">{{ $t('inbound.bindMsg.confirm') }}</button>
<button class="popup-btn cancel-btn" @click="handleCancelCargoSpace">{{ $t('inbound.bindMsg.cancel') }}</button>
</view>
</view>
</uni-popup>
</view>
</template>
<script>
import { getTrayInfo,addInJob,getOrderGoods ,bindTray, unbindTray} from '@/api/in/order.js'
import { getBasWarehouList, getCargoSpaceList } from '@/api/bas/bas.js'
export default {
data() {
return {
trayCode: '',
stockinDetailId: '',
subOrderInfo: null,
inQuantity:'',
materialList: [],
// currentWarehouseType: '',
cargoSpaceId: '',
cargoSpaceName: '',
cargoSpaceList: [],
cargoSpaceHeight: null,
}
},
onReady() {
setTimeout(() => {
this.$nextTick(() => {
this.$refs.trayCodeInput.onFocus()
})
}, 100)
},
methods: {
// 处理货位选择
async handleRecommendCargoSpace() {
// try {
const response = await getCargoSpaceList({ warehouseId: this.materialList[0].warehouseId, status: 1 })
if (response.code === 200 && response.rows.length > 0) {
// 获取第一个推荐货位
this.cargoSpaceId = response.rows[0].cargoSpaceId
this.cargoSpaceName = response.rows[0].cargoSpaceName
// 手动触发handleCargoSpaceInput方法获取货位高度信息
await this.handleCargoSpaceInput(response.rows[0].cargoSpaceName)
} else {
uni.showToast({
title: this.$t('inbound.bindMsg.noAvailableCargoSpace'),
icon: 'none'
})
}
// } catch (error) {
// uni.showToast({
// title: '获取推荐货位失败',
// icon: 'none'
// })
// }
},
// 处理货位选择
async handleCargoSpaceInput(value) {
if (value) {
try {
const response = await getCargoSpaceList({ cargoSpaceName: value, warehouseId: this.materialList[0].warehouseId })
if (response.code === 200 && response.rows.length > 0) {
this.cargoSpaceId = response.rows[0].cargoSpaceId
this.cargoSpaceHeight = response.rows[0].cargoHight
} else {
uni.showToast({
title: this.$t('inbound.bindMsg.getCargoSpaceInfoFailed'),
icon: 'none'
})
this.cargoSpaceId = ''
this.cargoSpaceHeight = null
}
} catch (error) {
uni.showToast({
title: this.$t('inbound.bindMsg.getCargoSpaceInfoFailed'),
icon: 'none'
})
this.cargoSpaceId = ''
this.cargoSpaceHeight = null
}
} else {
this.cargoSpaceId = ''
this.cargoSpaceHeight = null
}
},
// 带货位信息提交入库
async submitWithCargoSpace() {
if (!this.cargoSpaceId) {
uni.showToast({
title: this.$t('inbound.bindMsg.selectCargoSpace'),
icon: 'none'
})
return
}
try {
const response = await addInJob({
cargoSpaceId: this.cargoSpaceId,
trayCode: this.trayCode,
warehouseId: this.materialList[0].warehouseId
})
if (response.code === 200) {
uni.showToast({
title: this.$t('inbound.bindMsg.inboundSuccess'),
icon: 'success'
})
// 清空数据
this.trayCode = ''
this.materialList = []
this.cargoSpaceId = ''
this.cargoSpaceName = ''
this.cargoSpaceHeight=''
// this.currentWarehouseType = ''
} else {
uni.showToast({
title: response.msg || this.$t('inbound.bindMsg.inboundFailed'),
icon: 'none'
})
}
} catch (error) {
uni.showToast({
title: this.$t('inbound.bindMsg.inboundFailed'),
icon: 'none'
})
}
},
// 处理输入事件
handleInput(value) {
if (value) {
this.fetchTrayInfo(value)
}
},
// 处理清除事件
handleClear() {
this.materialList = []
},
// 处理扫码事件
handleScan() {
uni.scanCode({
success: (res) => {
this.trayCode = res.result
this.fetchTrayInfo(res.result)
}
})
},
// 获取托盘信息
async fetchTrayInfo(trayCode) {
try {
const response = await getTrayInfo(trayCode)
if (response.code===200) {
if(response.data.length>0){
this.materialList = response.data
}else{
this.materialList=[]
}
} else {
uni.showToast({
title: response.msg || this.$t('inbound.bindMsg.getTrayInfoFailed'),
icon: 'none'
})
}
} catch (error) {
uni.showToast({
title: this.$t('inbound.bindMsg.getTrayInfoFailed'),
icon: 'none'
})
}
},
// 处理确认入库事件
async handleConfirm() {
if (!this.trayCode || this.materialList.length === 0) {
uni.showToast({
title: this.$t('inbound.bindMsg.scanTrayFirst'),
icon: 'none'
})
return
}
const warehouseType = this.materialList[0].warehouseType
if (warehouseType === '1') {
// 显示货位选择弹出框
this.$refs.cargoSpacePopup.open()
} else {
// 非货位类型仓库,直接调用入库接口
try {
const response = await addInJob({
trayCode: this.trayCode,
warehouseId: this.materialList[0].warehouseId
})
if (response.code === 200) {
uni.showToast({
title: this.$t('inbound.bindMsg.inboundSuccess'),
icon: 'success'
})
// 清空数据
this.trayCode = ''
this.materialList = []
this.stockinDetailId=''
// this.cargoSpaceId = ''
} else {
uni.showToast({
title: response.msg || this.$t('inbound.bindMsg.inboundFailed'),
icon: 'none'
})
}
} catch (error) {
uni.showToast({
title: this.$t('inbound.bindMsg.inboundFailed'),
icon: 'none'
})
}
}
},
// 处理货位选择
handleConfirmCargoSpace() {
if (!this.cargoSpaceId) {
uni.showToast({
title: this.$t('inbound.bindMsg.selectCargoSpaceOrScan'),
icon: 'none'
})
return
}
this.$refs.cargoSpacePopup.close()
this.submitWithCargoSpace()
},
// 处理取消货位选择
handleCancelCargoSpace() {
this.$refs.cargoSpacePopup.close()
this.cargoSpaceId = ''
this.cargoSpaceName = ''
this.cargoSpaceHeight=''
},
// 处理子单据输入事件
async handleSubOrderInput(value) {
if (value) {
// 调用获取子单据信息
const goodsResponse = await getOrderGoods({stockinDetailId:value})
if (goodsResponse.length===0) {
uni.showToast({
title: this.$t('inbound.bindMsg.materialNotExistOrNoPermission'),
icon: 'none'
})
return
}
this.subOrderInfo= goodsResponse
console.log(this.subOrderInfo)
if (this.subOrderInfo) {
this.$refs.subOrderPopup.open()
}
}
},
// 处理子单据清除事件
handleSubOrderClear() {
// this.stockinDetailId = ''
this.subOrderInfo = null
},
handleQuantityInput(value) {
const numValue = Number(value)
if (numValue <= 0) {
this.inQuantity = ''
uni.showToast({
title: this.$t('inbound.bindMsg.quantityGreaterThanZero'),
icon: 'none'
})
return
}
if (numValue > this.subOrderInfo.quantity) {
this.inQuantity = String(this.subOrderInfo.quantity)
uni.showToast({
title: this.$t('inbound.bindMsg.notExceedMaxQuantity'),
icon: 'none'
})
return
}
this.inQuantity = String(numValue)
},
handleQuantityInput(value) {
const numValue = Number(value)
if (numValue <= 0) {
this.inQuantity = ''
uni.showToast({
title: this.$t('inbound.bindMsg.quantityGreaterThanZero'),
icon: 'none'
})
return
}
if (numValue > this.subOrderInfo.quantity) {
this.inQuantity = String(this.subOrderInfo.quantity)
uni.showToast({
title: this.$t('inbound.bindMsg.notExceedMaxQuantity'),
icon: 'none'
})
return
}
this.inQuantity = String(numValue)
},
// 处理绑定子单据事件
async handleBindSubOrder() {
// 验证必填信息
if (!this.trayCode) {
uni.showToast({
title: this.$t('inbound.bindMsg.enterTrayCode'),
icon: 'none'
})
return
}
if (!this.inQuantity || Number(this.inQuantity) <= 0) {
uni.showToast({
title: this.$t('inbound.bindMsg.enterValidQuantity'),
icon: 'none'
})
return
}
// 确保提交的数量不超过最大可用数量
const submitQuantity = Number(this.inQuantity)
if (submitQuantity > this.subOrderInfo.quantity && this.subOrderInfo.quantity > 0) {
this.inQuantity = String(this.subOrderInfo.quantity)
uni.showToast({
title: this.$t('inbound.bindMsg.autoAdjustMaxQuantity'),
icon: 'none'
})
}
const response = await bindTray({
trayCode: this.trayCode,
stockinDetailId: this.stockinDetailId,
inQuantity:this.inQuantity
})
if (response.code === 200) {
uni.showToast({
title: this.$t('inbound.bindMsg.bindSuccess'),
icon: 'success'
})
this.$refs.subOrderPopup.close()
this.stockinDetailId = ''
this.subOrderInfo = null
this.inQuantity=''
this.fetchTrayInfo(this.trayCode)
} else {
uni.showToast({
title: response.msg || this.$t('inbound.bindMsg.bindFailed'),
icon: 'none'
})
}
},
// 处理取消子单据事件
handleCancelSubOrder() {
if (this.$refs.subOrderPopup) {
this.$refs.subOrderPopup.close()
}
this.stockinDetailId = ''
this.subOrderInfo = null
this.inQuantity = ''
},
// 处理解绑事件
async handleUnbind(stockinDetailId) {
try {
const response = await unbindTray({
trayCode: this.trayCode,
stockinDetailId: stockinDetailId
})
if (response.code === 200) {
uni.showToast({
title: this.$t('inbound.bindMsg.unbindSuccess'),
icon: 'success'
})
// 刷新托盘信息
this.fetchTrayInfo(this.trayCode)
} else {
uni.showToast({
title: response.msg || this.$t('inbound.bindMsg.unbindFailed'),
icon: 'none'
})
}
} catch (error) {
uni.showToast({
title: this.$t('inbound.bindMsg.unbindFailed'),
icon: 'none'
})
}
}
}
}
</script>
<style>
.unbind-btn {
background-color: #ff4d4f;
color: #ffffff;
border: none;
border-radius: 4rpx;
padding: 10rpx 20rpx;
font-size: 24rpx;
cursor: pointer;
}
.unbind-btn:active {
background-color: #cf1322;
}
.container {
padding: 20rpx;
}
.input-group {
margin-bottom: 30rpx;
}
.input-label {
display: block;
margin-bottom: 10rpx;
font-size: 28rpx;
color: #333;
}
.scan-icon {
font-size: 40rpx;
padding: 0 20rpx;
}
.table-container {
background-color: #ffffff;
border-radius: 8rpx;
box-shadow: 0 2rpx 4rpx rgba(0, 0, 0, 0.1);
}
.cargo-space-container {
margin-bottom: 30rpx;
}
.cargo-space-input {
display: flex;
align-items: center;
}
.recommend-btn {
background-color: #409eff;
color: #ffffff;
border-radius: 4rpx;
padding: 0 20rpx;
height: 60rpx;
line-height: 60rpx;
font-size: 28rpx;
margin-left: 20rpx;
}
.button-group {
margin-top: 30rpx;
padding: 0 20rpx;
}
.confirm-button {
background-color: #409eff;
color: #ffffff;
border-radius: 8rpx;
padding: 20rpx 0;
font-size: 32rpx;
}
.popup-content {
background-color: #fff;
border-radius: 10rpx;
padding: 40rpx;
width: 85%;
box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.15);
max-height: 80vh;
overflow-y: auto;
}
.popup-title {
font-size: 36rpx;
font-weight: bold;
text-align: center;
margin-bottom: 40rpx;
color: #333;
border-bottom: 1px solid #eee;
padding-bottom: 20rpx;
}
.popup-body {
padding: 20rpx 10rpx;
max-height: 60vh;
overflow-y: auto;
}
.popup-buttons {
display: flex;
justify-content: space-around;
margin-top: 40rpx;
padding-top: 20rpx;
border-top: 1px solid #eee;
}
.popup-btn {
padding: 20rpx 50rpx;
border-radius: 8rpx;
font-size: 28rpx;
transition: all 0.3s;
}
.confirm-btn {
background-color: #007aff;
color: #fff;
font-weight: 500;
}
.confirm-btn:active {
background-color: #0062cc;
transform: scale(0.98);
}
.cancel-btn {
background-color: #f2f2f2;
color: #666;
border: 1px solid #ddd;
}
.cancel-btn:active {
background-color: #e6e6e6;
transform: scale(0.98);
}
.disabled-btn {
background-color: #ccc;
color: #fff;
cursor: not-allowed;
}
.cargo-space-height {
margin-top: 10rpx;
padding: 10rpx;
color: #666;
font-size: 24rpx;
background-color: #f8f8f8;
border-radius: 6rpx;
text-align: center;
}
.info-item {
padding: 15rpx;
background-color: #f9f9f9;
border-radius: 8rpx;
}
.info-row {
margin-bottom: 15rpx;
display: flex;
align-items: center;
}
.info-label {
width: 180rpx;
font-size: 28rpx;
color: #666;
font-weight: 500;
}
.info-value {
flex: 1;
font-size: 28rpx;
color: #333;
word-break: break-all;
}
.quantity-row {
align-items: flex-start;
}
.quantity-input {
width: 200rpx;
display: inline-block;
background-color: #fff;
border-radius: 4rpx;
}
.no-data {
text-align: center;
padding: 30rpx;
color: #999;
font-size: 28rpx;
}
</style>