<template>
|
<view>
|
<view class="itemstyle">
|
<uni-forms label-width="180">
|
<uni-forms-item label="托盘条码:">
|
<uni-easyinput type="text" placeholder="请扫描托盘条码" ref='midInput' :focus="!focus" v-model="palletCode"
|
@input="barcodeInput" @confirm="handleScanConfirm" />
|
</uni-forms-item>
|
<uni-forms-item>
|
<button @click="AGVTasks" type="primary" size="default" style="margin-top: 2%;">确认完成</button>
|
</uni-forms-item>
|
</uni-forms>
|
|
<!-- 库存明细展示区域 -->
|
<view v-if="stockDetails.length > 0" class="stock-details-container">
|
<uni-list>
|
<uni-list-item v-for="(detail, index) in stockDetails" :key="index" :title="`明细 ${index + 1}`"
|
:showArrow="false">
|
<template v-slot:body>
|
<view class="detail-content">
|
<view class="detail-row">
|
<text class="detail-label">物料编码:</text>
|
<text class="detail-value">{{ detail.materielCode || '无' }}</text>
|
</view>
|
<view class="detail-row">
|
<text class="detail-label">批次号:</text>
|
<text class="detail-value">{{ detail.batchNo || '无' }}</text>
|
</view>
|
<view class="detail-row">
|
<text class="detail-label">数量:</text>
|
<view class="quantity-container">
|
<input type="number" :value="detail.stockQuantity || detail.quantity || 0"
|
@input="handleQuantityChange($event, index)" placeholder="请输入数量"
|
class="quantity-input" />
|
<text class="quantity-unit">{{ detail.unit || '' }}</text>
|
</view>
|
</view>
|
</view>
|
</template>
|
</uni-list-item>
|
</uni-list>
|
|
<view class="summary-info">
|
<text class="summary-label" style="margin-left: 20rpx;">明细总数:</text>
|
<text class="summary-value">{{ stockDetails.length }} 条</text>
|
</view>
|
</view>
|
|
<!-- 无数据提示 -->
|
<view v-else-if="palletCode && !loading" class="no-data">
|
<uni-icons type="info" size="24" color="#999"></uni-icons>
|
<text class="no-data-text">未找到该托盘的库存明细</text>
|
</view>
|
|
<!-- 加载中 -->
|
<view v-if="loading" class="loading">
|
<uni-load-more status="loading" content="正在查询库存明细..."></uni-load-more>
|
</view>
|
</view>
|
<u-toast ref="uToast" />
|
</view>
|
</template>
|
|
<script>
|
const innerAudioContext = uni.createInnerAudioContext();
|
export default {
|
data() {
|
return {
|
focus: false,
|
palletCode: "",
|
warehouseId: "",
|
stockDetails: [], // 库存明细列表
|
loading: false,
|
timer: null,
|
}
|
},
|
onShow() {},
|
onLoad(res) {
|
this.focus = false;
|
this.warehouseId = res.warehouseId;
|
},
|
methods: {
|
barcodeInput() {
|
this.$nextTick(function(x) {
|
if (this.barcode.length > 0) {
|
this.focus = true;
|
}
|
})
|
|
// 防抖处理,扫描完成后自动查询
|
clearTimeout(this.timer);
|
this.timer = setTimeout(() => {
|
if (this.palletCode.length > 0) {
|
this.queryStockDetails();
|
}
|
}, 500);
|
},
|
|
handleScanConfirm() {
|
// 扫码枪回车确认
|
if (this.palletCode.length > 0) {
|
this.queryStockDetails();
|
}
|
},
|
|
// 处理数量变化
|
handleQuantityChange(event, index) {
|
const value = event.detail ? event.detail.value : event.target.value;
|
// 确保 value 是数字
|
const numValue = parseFloat(value) || 0;
|
|
// 更新对应明细的数量
|
this.stockDetails[index].stockQuantity = numValue;
|
|
// 触发更新,确保数据响应式
|
this.$set(this.stockDetails, index, {
|
...this.stockDetails[index]
|
});
|
},
|
|
// 查询库存明细
|
queryStockDetails() {
|
if (!this.palletCode.trim()) {
|
return;
|
}
|
|
this.loading = true;
|
this.stockDetails = [];
|
|
var postDate = {
|
MainData: {
|
palletCode: this.palletCode,
|
warehouseId: this.warehouseId,
|
}
|
}
|
|
this.$u.post('/api/StockInfo/GetStockDetails', postDate).then(res => {
|
console.log("接口返回数据:", res.data); // 调试用
|
|
if (res && res.status) {
|
// 后端返回的是 stockInfo.Details 数组,在 res.data 中
|
this.stockDetails = res.data;
|
|
// 如果 data 不是数组,尝试从对象中提取数组
|
if (!Array.isArray(this.stockDetails) && res.data) {
|
console.warn("返回的数据不是数组:", res.data);
|
// 尝试从对象中提取数组
|
if (Array.isArray(res.data.Details)) {
|
this.stockDetails = res.data.Details;
|
} else if (Array.isArray(res.data.data)) {
|
this.stockDetails = res.data.data;
|
} else {
|
this.stockDetails = [];
|
}
|
}
|
|
// 确保 stockDetails 是数组
|
if (!Array.isArray(this.stockDetails)) {
|
this.stockDetails = [];
|
}
|
|
// 初始化 stockQuantity 字段(如果不存在)
|
this.stockDetails.forEach(item => {
|
if (!item.hasOwnProperty('stockQuantity')) {
|
// 如果原始数据有 quantity 字段,复制到 stockQuantity
|
item.stockQuantity = item.quantity || 0;
|
}
|
});
|
|
if (this.stockDetails.length === 0) {
|
this.$refs.uToast.show({
|
title: "该托盘无库存明细记录",
|
type: 'warning'
|
})
|
} else {
|
this.$refs.uToast.show({
|
title: `找到 ${this.stockDetails.length} 条明细记录`,
|
type: 'success',
|
duration: 1500
|
})
|
}
|
} else {
|
this.$refs.uToast.show({
|
title: res?.message || "查询失败",
|
type: "error"
|
})
|
}
|
}).catch(error => {
|
console.error("查询库存明细失败:", error);
|
this.$refs.uToast.show({
|
title: "查询失败,请稍后重试",
|
type: "error"
|
})
|
}).finally(() => {
|
this.loading = false;
|
});
|
},
|
|
AGVTasks() {
|
if (!this.palletCode) {
|
this.$refs.uToast.show({
|
title: "请扫描托盘条码",
|
type: 'error'
|
})
|
return;
|
}
|
|
if (this.stockDetails.length === 0) {
|
this.$refs.uToast.show({
|
title: "请先查询库存明细",
|
type: 'error'
|
})
|
return;
|
}
|
|
// 准备提交的数据
|
const detailsToSubmit = this.stockDetails.map(detail => ({
|
materielCode: detail.materielCode || '',
|
batchNo: detail.batchNo || '',
|
stockQuantity: detail.stockQuantity || detail.quantity || 0,
|
unit: detail.unit || ''
|
}));
|
|
// 过滤掉无效数据
|
const validDetails = detailsToSubmit.filter(item =>
|
item.materielCode && item.batchNo && item.stockQuantity > 0
|
);
|
|
if (validDetails.length === 0) {
|
this.$refs.uToast.show({
|
title: "请填写有效的物料信息",
|
type: 'error'
|
})
|
return;
|
}
|
|
// 构造提交数据
|
var postDates = {
|
MainData: {
|
palletCode: this.palletCode,
|
warehouseId: this.warehouseId,
|
details: validDetails // 传递所有有效的明细数据
|
}
|
}
|
|
console.log("提交的数据:", postDates);
|
|
this.$u.post('/api/StockInfo/UpdateGetStockDetails', postDates).then(
|
res => {
|
if (res.status) {
|
this.$refs.uToast.show({
|
title: "任务创建成功",
|
type: "success"
|
})
|
// 清空数据
|
this.palletCode = "";
|
this.stockDetails = [];
|
this.focus = false;
|
} else {
|
this.$refs.uToast.show({
|
title: res.message || "任务创建失败",
|
type: "error"
|
})
|
}
|
}).catch(error => {
|
console.error("提交任务失败:", error);
|
this.$refs.uToast.show({
|
title: "网络错误,请重试",
|
type: "error"
|
})
|
})
|
}
|
}
|
}
|
</script>
|
|
<style lang="scss">
|
@import '@/common/uni-ui.scss';
|
|
.content {
|
display: flex;
|
height: 150px;
|
}
|
|
.content-text {
|
font-size: 14px;
|
color: #666;
|
}
|
|
.itemstyle {
|
margin-top: 30px;
|
margin-left: 5%;
|
}
|
|
.headerstyle {
|
width: 90%;
|
}
|
|
/* 库存明细容器 */
|
.stock-details-container {
|
margin-top: 30rpx;
|
}
|
|
/* 明细内容样式 */
|
.detail-content {
|
padding: 20rpx 0;
|
}
|
|
.detail-row {
|
display: flex;
|
flex-direction: row;
|
margin-bottom: 12rpx;
|
padding: 8rpx 0;
|
border-bottom: 1rpx solid #f0f0f0;
|
|
&:last-child {
|
border-bottom: none;
|
}
|
|
.detail-label {
|
width: 140rpx;
|
color: #666;
|
font-size: 26rpx;
|
font-weight: bold;
|
flex-shrink: 0;
|
}
|
|
.detail-value {
|
flex: 1;
|
color: #333;
|
font-size: 26rpx;
|
word-break: break-all;
|
padding-left: 20rpx;
|
}
|
}
|
|
/* 数量输入框样式 */
|
.quantity-container {
|
display: flex;
|
align-items: center;
|
flex: 1;
|
}
|
|
.quantity-input {
|
flex: 1;
|
padding: 8rpx 16rpx;
|
border: 1rpx solid #e0e0e0;
|
border-radius: 6rpx;
|
font-size: 26rpx;
|
color: #333;
|
background-color: #fff;
|
margin-right: 10rpx;
|
width: 250rpx;
|
height: 30px;
|
|
&:focus {
|
border-color: #409EFF;
|
outline: none;
|
}
|
}
|
|
.quantity-unit {
|
color: #333;
|
font-size: 26rpx;
|
width: 300rpx;
|
flex-shrink: 0;
|
padding-left: 10rpx;
|
}
|
|
/* 合计信息 */
|
.summary-info {
|
margin-top: 30rpx;
|
padding: 20rpx;
|
background-color: #f5f7fa;
|
border-radius: 8rpx;
|
display: flex;
|
justify-content: center;
|
align-items: center;
|
flex-wrap: wrap;
|
|
.summary-label {
|
color: #333;
|
font-size: 28rpx;
|
font-weight: bold;
|
margin-right: 10rpx;
|
}
|
|
.summary-value {
|
color: #409EFF;
|
font-size: 28rpx;
|
font-weight: bold;
|
margin-right: 30rpx;
|
}
|
}
|
|
/* 无数据样式 */
|
.no-data {
|
margin-top: 60rpx;
|
display: flex;
|
flex-direction: column;
|
align-items: center;
|
justify-content: center;
|
padding: 60rpx 40rpx;
|
background-color: #f9f9f9;
|
border-radius: 12rpx;
|
|
.no-data-text {
|
margin-top: 20rpx;
|
color: #999;
|
font-size: 28rpx;
|
}
|
}
|
|
/* 加载中样式 */
|
.loading {
|
margin-top: 60rpx;
|
text-align: center;
|
padding: 40rpx;
|
}
|
</style>
|