401 lines
9.6 KiB
Vue
401 lines
9.6 KiB
Vue
<template>
|
||
<view class="container">
|
||
<view class="warehouse-select">
|
||
<uni-data-select
|
||
v-model="selectedWarehouse"
|
||
:localdata="warehouseList"
|
||
:clear="false"
|
||
:placeholder="$t('stocktaking.confirmPK.selectWarehouse')"
|
||
@change="handleWarehouseChange"
|
||
/>
|
||
</view>
|
||
|
||
<view class="add-button-container" v-if="selectedWarehouse!=''">
|
||
<button class="add-button" @click="showAddMaterialPopup">{{ $t('stocktaking.confirmPK.addMaterial') }}</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">{{ $t('stocktaking.confirmPK.materialCode') }}:</text>
|
||
<text class="value">{{ item.extraField.productId }}</text>
|
||
</view>
|
||
<view class="info-row">
|
||
<text class="label">{{ $t('stocktaking.confirmPK.materialName') }}:</text>
|
||
<text class="value">{{ item.extraField.materialDesc }}</text>
|
||
</view>
|
||
<view class="info-row">
|
||
<text class="label">{{ $t('stocktaking.confirmPK.inventoryQuantity') }}:</text>
|
||
<text class="value">{{ item.quantity }}</text>
|
||
</view>
|
||
<view class="info-row">
|
||
<text class="label">{{ $t('stocktaking.confirmPK.countQuantity') }}:</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)">{{ $t('stocktaking.confirmPK.countButton') }}</button>
|
||
</view>
|
||
</view>
|
||
</uni-card>
|
||
</view>
|
||
</view>
|
||
|
||
<view class="empty-state" v-else>
|
||
<text>{{ $t('stocktaking.confirmPK.noInventoryData') }}</text>
|
||
</view>
|
||
|
||
<!-- 新增物料弹窗 -->
|
||
<uni-popup ref="addMaterialPopup" type="center">
|
||
<view class="popup-content">
|
||
<view class="popup-title">{{ $t('stocktaking.confirmPK.addMaterialTitle') }}</view>
|
||
<view class="popup-form">
|
||
<view class="form-item">
|
||
<text class="form-label">{{ $t('stocktaking.confirmPK.materialCodeLabel') }}</text>
|
||
<uni-easyinput v-model="newMaterial.productId" :placeholder="$t('stocktaking.confirm.materialCodePlaceholder')" />
|
||
</view>
|
||
<view class="form-item">
|
||
<text class="form-label">{{ $t('stocktaking.confirmPK.quantityLabel') }}</text>
|
||
<uni-easyinput v-model="newMaterial.newQuantity" type="number" :placeholder="$t('stocktaking.confirm.quantityPlaceholder')" />
|
||
</view>
|
||
</view>
|
||
<view class="popup-buttons">
|
||
<button class="cancel-btn" @click="hideAddMaterialPopup">{{ $t('stocktaking.confirmPK.cancel') }}</button>
|
||
<button class="submit-btn" @click="handleAddMaterial">{{ $t('stocktaking.confirmPK.confirm') }}</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: this.$t('stocktaking.confirmPK.getWarehouseListFailed'),
|
||
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: this.$t('stocktaking.confirmPK.getInventoryListFailed'),
|
||
icon: 'none'
|
||
})
|
||
}
|
||
},
|
||
|
||
// 处理仓库选择变化
|
||
handleWarehouseChange(warehouseId) {
|
||
this.getInventoryList()
|
||
},
|
||
|
||
// 处理盘点确认
|
||
async handleConfirm(item) {
|
||
if (!item.newQuantity || item.newQuantity < 0) {
|
||
uni.showToast({
|
||
title: this.$t('stocktaking.confirmPK.enterValidCountQuantity'),
|
||
icon: 'none'
|
||
})
|
||
return
|
||
}
|
||
if(item.newQuantity==item.quantity){
|
||
uni.showToast({
|
||
title: this.$t('stocktaking.confirmPK.quantityMatch'),
|
||
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: this.$t('stocktaking.confirmPK.countSuccess'),
|
||
icon: 'success'
|
||
})
|
||
// 刷新库存列表
|
||
this.getInventoryList()
|
||
} else {
|
||
uni.showToast({
|
||
title: response.msg || this.$t('stocktaking.confirmPK.countFailed'),
|
||
icon: 'none'
|
||
})
|
||
}
|
||
} catch (error) {
|
||
console.error('盘点失败:', error)
|
||
uni.showToast({
|
||
title: this.$t('stocktaking.confirmPK.countFailed'),
|
||
icon: 'none'
|
||
})
|
||
}
|
||
},
|
||
// 处理数量输入
|
||
handleQuantityInput(value, item) {
|
||
// 确保输入的是有效数字
|
||
const numValue = Number(value)
|
||
if (!isNaN(numValue)) {
|
||
item.newQuantity = numValue
|
||
}
|
||
},
|
||
|
||
// 显示新增物料弹窗
|
||
showAddMaterialPopup() {
|
||
if(!this.selectedWarehouse)
|
||
return uni.showToast({
|
||
title: this.$t('stocktaking.confirmPK.selectWarehouse'),
|
||
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: this.$t('stocktaking.confirmPK.enterValidMaterialInfo'),
|
||
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: this.$t('stocktaking.confirmPK.addSuccess'),
|
||
icon: 'success'
|
||
})
|
||
// 关闭弹窗并刷新列表
|
||
this.hideAddMaterialPopup()
|
||
this.getInventoryList()
|
||
} else {
|
||
uni.showToast({
|
||
title: response.msg || this.$t('stocktaking.confirmPK.addFailed'),
|
||
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>
|
||
|