Files
FT541-WMS/RuoYi-App-master/pages/pandian/pkconfirm.vue

401 lines
8.8 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<view class="container">
<view class="warehouse-select">
<uni-data-select
v-model="selectedWarehouse"
:localdata="warehouseList"
:clear="false"
placeholder="请选择仓库"
@change="handleWarehouseChange"
/>
</view>
<view class="add-button-container" v-if="selectedWarehouse!=''">
<button class="add-button" @click="showAddMaterialPopup">新增物料</button>
</view>
<view class="inventory-list" v-if="inventoryList.length > 0">
<view v-for="(item, index) in inventoryList" :key="index" class="inventory-card">
<uni-card>
<view class="card-content">
<view class="info-row">
<text class="label">物料编码:</text>
<text class="value">{{ item.extraField.productId }}</text>
</view>
<view class="info-row">
<text class="label">物料名称:</text>
<text class="value">{{ item.extraField.materialDesc }}</text>
</view>
<view class="info-row">
<text class="label">库存数量:</text>
<text class="value">{{ item.quantity }}</text>
</view>
<view class="info-row">
<text class="label">盘点数量:</text>
<view class="value">
<uni-easyinput
v-model.number="item.newQuantity"
type="number"
:min="0"
@input="handleQuantityInput($event, item)"
style="width: 280rpx; display: inline-block;"
/>
</view>
</view>
<view class="button-row">
<button class="confirm-button" @click="handleConfirm(item)">盘点</button>
</view>
</view>
</uni-card>
</view>
</view>
<view class="empty-state" v-else>
<text>暂无盘点数据</text>
</view>
<!-- 新增物料弹窗 -->
<uni-popup ref="addMaterialPopup" type="center">
<view class="popup-content">
<view class="popup-title">新增物料</view>
<view class="popup-form">
<view class="form-item">
<text class="form-label">物料编码</text>
<uni-easyinput v-model="newMaterial.productId" placeholder="请输入物料编码" />
</view>
<view class="form-item">
<text class="form-label">数量</text>
<uni-easyinput v-model="newMaterial.newQuantity" type="number" placeholder="请输入数量" />
</view>
</view>
<view class="popup-buttons">
<button class="cancel-btn" @click="hideAddMaterialPopup">取消</button>
<button class="submit-btn" @click="handleAddMaterial">确定</button>
</view>
</view>
</uni-popup>
</view>
</template>
<script>
import { getBasWarehouList } from '@/api/bas/bas.js'
import { getInventoryList, confirmInventory } from '@/api/pandian/confirm.js'
export default {
data() {
return {
selectedWarehouse: '',
warehouseList: [],
inventoryList: [],
// 新增物料表单数据
newMaterial: {
productId: '',
newQuantity: ''
}
}
},
onReady() {
// 获取仓库列表
this.getWarehouseList()
},
methods: {
// 获取仓库列表
async getWarehouseList() {
try {
const response = await getBasWarehouList({
pageNum: 1,
pageSize: 100,
typeData:["3"]
})
if (response.code === 200) {
this.warehouseList = response.rows.map(item => ({
value: item.warehouseId,
text: item.warehouseName
}))
// 如果有仓库,默认选择第一个并加载库存数据
if (this.warehouseList.length > 0) {
this.selectedWarehouse = this.warehouseList[0].value
this.getInventoryList()
}
}
} catch (error) {
console.error('获取仓库列表失败:', error)
uni.showToast({
title: '获取仓库列表失败',
icon: 'none'
})
}
},
// 获取库存列表
async getInventoryList() {
try {
const response = await getInventoryList({
warehouseId: this.selectedWarehouse,
pageNum: 1,
pageSize: 100000000,
productStatus:'1'
})
this.inventoryList = (response.rows || []).map(item => ({
...item,
newQuantity: item.quantity // 初始化盘点数量为库存数量
}))
} catch (error) {
console.error('获取库存列表失败:', error)
uni.showToast({
title: '获取库存列表失败',
icon: 'none'
})
}
},
// 处理仓库选择变化
handleWarehouseChange(warehouseId) {
this.getInventoryList()
},
// 处理盘点确认
async handleConfirm(item) {
if (!item.newQuantity || item.newQuantity < 0) {
uni.showToast({
title: '请输入有效的盘点数量',
icon: 'none'
})
return
}
if(item.newQuantity==item.quantity){
uni.showToast({
title: '库存数量与盘点数量一致,无需盘点',
icon: 'none'
})
}
try {
const response = await confirmInventory({
stockId: item.stockId,
productId: item.extraField.productId,
newQuantity: item.newQuantity,
recordType: item.newQuantity === 0 ? 3 : 1
})
if (response.code === 200) {
uni.showToast({
title: '盘点成功',
icon: 'success'
})
// 刷新库存列表
this.getInventoryList()
} else {
uni.showToast({
title: response.msg || '盘点失败',
icon: 'none'
})
}
} catch (error) {
console.error('盘点失败:', error)
uni.showToast({
title: '盘点失败',
icon: 'none'
})
}
},
// 处理数量输入
handleQuantityInput(value, item) {
// 确保输入的是有效数字
const numValue = Number(value)
if (!isNaN(numValue)) {
item.newQuantity = numValue
}
},
// 显示新增物料弹窗
showAddMaterialPopup() {
if(!this.selectedWarehouse)
return uni.showToast({
title: '请选择仓库',
icon: 'none'
})
this.$refs.addMaterialPopup.open()
},
// 隐藏新增物料弹窗
hideAddMaterialPopup() {
this.$refs.addMaterialPopup.close()
// 重置表单数据
this.newMaterial = {
productId: '',
newQuantity: ''
}
},
// 处理新增物料
async handleAddMaterial() {
if (!this.newMaterial.productId || !this.newMaterial.newQuantity || this.newMaterial.newQuantity < 0) {
uni.showToast({
title: '请输入有效的物料信息',
icon: 'none'
})
return
}
// try {
const response = await confirmInventory({
productId: this.newMaterial.productId,
newQuantity: Number(this.newMaterial.newQuantity),
warehouseId: this.selectedWarehouse,
recordType: 2
})
if (response.code === 200) {
uni.showToast({
title: '新增成功',
icon: 'success'
})
// 关闭弹窗并刷新列表
this.hideAddMaterialPopup()
this.getInventoryList()
} else {
uni.showToast({
title: response.msg || '新增失败',
icon: 'none'
})
}
// } catch (error) {
// console.error('新增物料失败:', error)
// uni.showToast({
// title: '新增物料失败',
// icon: 'none'
// })
// }
},
}
}
</script>
<style>
.container {
padding: 20rpx;
}
.warehouse-select {
margin-bottom: 20rpx;
}
.inventory-list {
margin-top: 20rpx;
}
.inventory-card {
margin-bottom: 20rpx;
}
.card-content {
padding: 10rpx;
}
.info-row {
display: flex;
margin-bottom: 10rpx;
align-items: center;
}
.label {
color: #666;
width: 160rpx;
}
.value {
color: #333;
flex: 1;
}
.button-row {
display: flex;
justify-content: flex-end;
margin-top: 20rpx;
}
.confirm-button {
background-color: #007AFF;
color: #fff;
font-size: 28rpx;
padding: 10rpx 30rpx;
border-radius: 8rpx;
}
.empty-state {
text-align: center;
padding: 40rpx;
color: #999;
}
.add-button-container {
margin: 20rpx 0;
display: flex;
justify-content: center;
}
.add-button {
background-color: #007AFF;
color: #fff;
font-size: 28rpx;
padding: 10rpx 30rpx;
border-radius: 8rpx;
}
.popup-content {
background-color: #fff;
border-radius: 16rpx;
padding: 30rpx;
width: 600rpx;
}
.popup-title {
font-size: 32rpx;
font-weight: bold;
text-align: center;
margin-bottom: 30rpx;
}
.popup-form {
margin-bottom: 30rpx;
}
.form-item {
margin-bottom: 20rpx;
}
.form-label {
display: block;
margin-bottom: 10rpx;
color: #333;
}
.popup-buttons {
display: flex;
justify-content: space-between;
margin-top: 40rpx;
}
.cancel-btn,
.submit-btn {
width: 45%;
padding: 16rpx 0;
border-radius: 8rpx;
font-size: 28rpx;
text-align: center;
}
.cancel-btn {
background-color: #f5f5f5;
color: #666;
}
.submit-btn {
background-color: #007AFF;
color: #fff;
}
</style>