feat: 入库页面改为先选种类->商品->弹窗填数量,支持多商品批量入库

This commit is contained in:
Agent
2026-03-27 04:39:35 +00:00
parent cd82ad2fa6
commit c399c54439

View File

@@ -1,45 +1,121 @@
<template>
<view class="stock-in">
<view class="form">
<view class="form-item">
<text class="label">商品</text>
<picker
mode="selector"
:range="productList"
range-key="name"
@change="onProductChange"
<view class="page">
<!-- 分类 + 商品列表 -->
<view class="content-wrapper">
<!-- 左侧分类 -->
<scroll-view scroll-y class="category-sidebar">
<view
class="category-item"
:class="{ active: !categoryId }"
@click="selectCategory('')"
>
<view class="picker">
{{ selectedProduct ? selectedProduct.name : '请选择商品' }}
全部
</view>
</picker>
<view
v-for="cat in categories"
:key="cat.categoryId"
class="category-item"
:class="{ active: categoryId === cat.categoryId }"
@click="selectCategory(cat.categoryId)"
>
{{ cat.name }}
</view>
</scroll-view>
<view class="form-item">
<text class="label">入库数量</text>
<input
class="input"
v-model="quantity"
type="number"
placeholder="请输入数量"
/>
<!-- 右侧商品列表 -->
<scroll-view scroll-y class="product-scroll">
<view class="product-list">
<view
v-for="item in productList"
:key="item.productId"
class="product-item"
@click="openQuantityPopup(item)"
>
<view class="product-info">
<text class="product-name">{{ item.name }}</text>
<text class="product-spec">{{ item.spec || '-' }}</text>
</view>
<view class="form-item">
<text class="label">备注</text>
<input
class="input"
v-model="remark"
placeholder="可选填写"
/>
<view class="product-add">
<text class="add-icon">+</text>
</view>
</view>
<view class="btn-area">
<view v-if="productList.length === 0" class="empty">
<text class="empty-icon">📭</text>
<text class="empty-text">暂无商品</text>
</view>
</view>
</scroll-view>
</view>
<!-- 已添加商品列表 -->
<view class="selected-section" v-if="selectedItems.length > 0">
<view class="selected-header">
<text class="selected-title">已选择商品</text>
<text class="selected-count">{{ selectedItems.length }} </text>
</view>
<scroll-view scroll-x class="selected-list">
<view
v-for="(item, index) in selectedItems"
:key="index"
class="selected-item"
>
<view class="selected-info">
<text class="selected-name">{{ item.productName }}</text>
<text class="selected-qty">× {{ item.quantity }}</text>
</view>
<text class="selected-delete" @click="removeItem(index)">×</text>
</view>
</scroll-view>
</view>
<!-- 底部提交按钮 -->
<view class="submit-bar" v-if="selectedItems.length > 0">
<view class="submit-info">
<text class="submit-label"> {{ totalQuantity }} </text>
</view>
<button class="submit-btn" @click="submit" :disabled="submitting">
{{ submitting ? '提交中...' : '确认入库' }}
</button>
</view>
<!-- 数量填写弹窗 -->
<view class="popup-mask" v-if="showPopup" @click="closePopup"></view>
<view class="popup-content" v-if="showPopup">
<view class="popup-header">
<text class="popup-title">{{ currentProduct.name }}</text>
<text class="popup-close" @click="closePopup">×</text>
</view>
<view class="popup-body">
<view class="popup-spec" v-if="currentProduct.spec">
规格: {{ currentProduct.spec }}
</view>
<view class="popup-qty">
<text class="qty-label">入库数量</text>
<view class="qty-input-wrapper">
<text class="qty-minus" @click="qtyMinus">-</text>
<input
class="qty-input"
type="number"
v-model="inputQuantity"
/>
<text class="qty-plus" @click="qtyPlus">+</text>
</view>
</view>
<view class="popup-remark">
<text class="remark-label">备注可选</text>
<input
class="remark-input"
v-model="inputRemark"
placeholder="填写备注"
/>
</view>
</view>
<view class="popup-footer">
<button class="popup-btn cancel" @click="closePopup">取消</button>
<button class="popup-btn confirm" @click="confirmAdd">确定</button>
</view>
</view>
</view>
</template>
@@ -50,55 +126,131 @@ import productApi from '@/api/product'
export default {
data() {
return {
categoryId: '',
categories: [],
productList: [],
selectedProduct: null,
quantity: '',
remark: '',
page: 1,
pageSize: 50,
loading: false,
// 已选择的商品
selectedItems: [],
// 弹窗相关
showPopup: false,
currentProduct: {},
inputQuantity: 1,
inputRemark: '',
// 提交状态
submitting: false
}
},
computed: {
totalQuantity() {
return this.selectedItems.reduce((sum, item) => sum + item.quantity, 0)
}
},
onLoad() {
this.loadCategories()
this.getProducts()
},
methods: {
async getProducts() {
async loadCategories() {
try {
const res = await productApi.getProducts({ page: 1, pageSize: 100 })
if (res.code === 0) {
this.productList = res.data.records || []
}
const categories = await productApi.getCategories()
this.categories = categories || []
} catch (e) {
uni.showToast({ title: '加载商品失败', icon: 'none' })
console.error(e)
}
},
onProductChange(e) {
this.selectedProduct = this.productList[e.detail.value]
async getProducts() {
this.loading = true
try {
const res = await productApi.getProducts({
categoryId: this.categoryId,
page: this.page,
pageSize: this.pageSize
})
this.productList = res.records || []
} catch (e) {
uni.showToast({ title: '加载失败', icon: 'none' })
} finally {
this.loading = false
}
},
async submit() {
if (!this.selectedProduct) {
uni.showToast({ title: '请选择商品', icon: 'none' })
selectCategory(id) {
this.categoryId = id
this.page = 1
this.getProducts()
},
openQuantityPopup(product) {
this.currentProduct = product
this.inputQuantity = 1
this.inputRemark = ''
this.showPopup = true
},
closePopup() {
this.showPopup = false
},
qtyMinus() {
if (this.inputQuantity > 1) {
this.inputQuantity--
}
},
qtyPlus() {
this.inputQuantity++
},
confirmAdd() {
if (this.inputQuantity <= 0) {
uni.showToast({ title: '请输入有效数量', icon: 'none' })
return
}
if (!this.quantity || this.quantity <= 0) {
uni.showToast({ title: '请输入有效数量', icon: 'none' })
// 检查是否已存在,存在则累加
const existsIndex = this.selectedItems.findIndex(
item => item.productId === this.currentProduct.productId
)
if (existsIndex > -1) {
this.selectedItems[existsIndex].quantity += parseInt(this.inputQuantity)
this.selectedItems[existsIndex].remark = this.inputRemark || this.selectedItems[existsIndex].remark
} else {
this.selectedItems.push({
productId: this.currentProduct.productId,
productName: this.currentProduct.name,
quantity: parseInt(this.inputQuantity),
remark: this.inputRemark
})
}
this.closePopup()
uni.showToast({ title: '已添加', icon: 'success' })
},
removeItem(index) {
this.selectedItems.splice(index, 1)
},
async submit() {
if (this.selectedItems.length === 0) {
uni.showToast({ title: '请先添加商品', icon: 'none' })
return
}
this.submitting = true
try {
const res = await stockApi.stockIn({
productId: this.selectedProduct.productId,
quantity: parseInt(this.quantity),
remark: this.remark
// 逐个入库
for (const item of this.selectedItems) {
await stockApi.stockIn({
productId: item.productId,
quantity: item.quantity,
remark: item.remark || ''
})
if (res.code === 0) {
}
uni.showToast({ title: '入库成功', icon: 'success' })
setTimeout(() => {
uni.navigateBack()
}, 1500)
} else {
uni.showToast({ title: res.message || '入库失败', icon: 'none' })
}
} catch (e) {
uni.showToast({ title: '入库失败', icon: 'none' })
} finally {
@@ -109,54 +261,346 @@ export default {
}
</script>
<style scoped>
.stock-in {
<style>
.page {
min-height: 100vh;
background: #f5f5f5;
background: #f8f9fa;
padding-bottom: 180rpx;
}
.form {
.content-wrapper {
display: flex;
height: calc(100vh - 200rpx);
}
/* 左侧分类 */
.category-sidebar {
width: 180rpx;
background: #fff;
margin: 20rpx;
border-radius: 12rpx;
padding: 0 30rpx;
flex-shrink: 0;
}
.form-item {
.category-item {
padding: 28rpx 20rpx;
font-size: 26rpx;
color: #666;
text-align: center;
border-left: 6rpx solid transparent;
}
.category-item.active {
background: #f8f9fa;
color: #667eea;
font-weight: bold;
border-left-color: #667eea;
}
/* 右侧商品 */
.product-scroll {
flex: 1;
background: #f8f9fa;
}
.product-list {
padding: 20rpx;
}
.product-item {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 20rpx;
padding: 30rpx;
background: #fff;
border-radius: 16rpx;
box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.06);
}
.product-info {
flex: 1;
}
.product-name {
display: block;
font-size: 30rpx;
font-weight: 500;
color: #333;
margin-bottom: 8rpx;
}
.product-spec {
font-size: 24rpx;
color: #999;
}
.product-add {
width: 60rpx;
height: 60rpx;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
border-radius: 30rpx;
display: flex;
align-items: center;
padding: 30rpx 0;
border-bottom: 1rpx solid #eee;
justify-content: center;
}
.form-item:last-child {
border-bottom: none;
.add-icon {
font-size: 36rpx;
color: #fff;
font-weight: bold;
}
.label {
width: 160rpx;
font-size: 30rpx;
.empty {
padding: 100rpx;
display: flex;
flex-direction: column;
align-items: center;
}
.picker, .input {
.empty-icon {
font-size: 80rpx;
margin-bottom: 20rpx;
}
.empty-text {
font-size: 28rpx;
color: #999;
}
/* 已选择商品 */
.selected-section {
position: fixed;
bottom: 120rpx;
left: 0;
right: 0;
background: #fff;
padding: 20rpx 30rpx;
box-shadow: 0 -4rpx 20rpx rgba(0, 0, 0, 0.1);
}
.selected-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 16rpx;
}
.selected-title {
font-size: 28rpx;
font-weight: bold;
color: #333;
}
.selected-count {
font-size: 24rpx;
color: #667eea;
}
.selected-list {
white-space: nowrap;
width: 100%;
}
.selected-item {
display: inline-flex;
align-items: center;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
border-radius: 12rpx;
padding: 16rpx 24rpx;
margin-right: 16rpx;
}
.selected-info {
display: flex;
flex-direction: column;
}
.selected-name {
font-size: 24rpx;
color: #fff;
max-width: 200rpx;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.selected-qty {
font-size: 22rpx;
color: rgba(255, 255, 255, 0.8);
margin-top: 4rpx;
}
.selected-delete {
margin-left: 16rpx;
font-size: 32rpx;
color: rgba(255, 255, 255, 0.8);
padding: 8rpx;
}
/* 底部提交 */
.submit-bar {
position: fixed;
bottom: 0;
left: 0;
right: 0;
display: flex;
align-items: center;
padding: 20rpx 30rpx;
background: #fff;
box-shadow: 0 -4rpx 20rpx rgba(0, 0, 0, 0.1);
}
.submit-info {
flex: 1;
font-size: 30rpx;
}
.btn-area {
padding: 40rpx 30rpx;
.submit-label {
font-size: 28rpx;
color: #666;
}
.submit-btn {
width: 240rpx;
height: 88rpx;
line-height: 88rpx;
background: #3cc51f;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: #fff;
font-size: 32rpx;
border-radius: 8rpx;
border: none;
border-radius: 44rpx;
font-size: 30rpx;
font-weight: bold;
box-shadow: 0 8rpx 30rpx rgba(102, 126, 234, 0.4);
}
.submit-btn[disabled] {
background: #ccc;
/* 弹窗 */
.popup-mask {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.5);
z-index: 100;
}
.popup-content {
position: fixed;
bottom: 0;
left: 0;
right: 0;
background: #fff;
border-radius: 32rpx 32rpx 0 0;
padding: 40rpx 30rpx;
padding-bottom: calc(40rpx + env(safe-area-inset-bottom));
z-index: 101;
}
.popup-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 30rpx;
}
.popup-title {
font-size: 32rpx;
font-weight: bold;
color: #333;
}
.popup-close {
font-size: 48rpx;
color: #999;
padding: 10rpx;
}
.popup-spec {
font-size: 26rpx;
color: #666;
margin-bottom: 30rpx;
}
.popup-qty {
display: flex;
align-items: center;
margin-bottom: 30rpx;
}
.qty-label {
font-size: 28rpx;
color: #333;
width: 160rpx;
}
.qty-input-wrapper {
display: flex;
align-items: center;
background: #f5f5f5;
border-radius: 12rpx;
}
.qty-minus, .qty-plus {
width: 80rpx;
height: 80rpx;
display: flex;
align-items: center;
justify-content: center;
font-size: 40rpx;
color: #667eea;
}
.qty-input {
width: 120rpx;
height: 80rpx;
text-align: center;
font-size: 32rpx;
background: transparent;
border-left: 1rpx solid #eee;
border-right: 1rpx solid #eee;
}
.popup-remark {
margin-bottom: 30rpx;
}
.remark-label {
font-size: 28rpx;
color: #333;
display: block;
margin-bottom: 16rpx;
}
.remark-input {
width: 100%;
height: 80rpx;
background: #f5f5f5;
border-radius: 12rpx;
padding: 0 20rpx;
font-size: 28rpx;
box-sizing: border-box;
}
.popup-footer {
display: flex;
gap: 20rpx;
}
.popup-btn {
flex: 1;
height: 88rpx;
line-height: 88rpx;
border-radius: 44rpx;
font-size: 30rpx;
font-weight: bold;
}
.popup-btn.cancel {
background: #f5f5f5;
color: #666;
}
.popup-btn.confirm {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: #fff;
box-shadow: 0 8rpx 30rpx rgba(102, 126, 234, 0.4);
}
</style>