feat: 添加商品选择页面
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Agent
2026-03-24 11:57:19 +00:00
parent cd9e2edc8e
commit 6cdfc47250
3 changed files with 180 additions and 10 deletions

View File

@@ -24,6 +24,12 @@
"navigationBarTitleText": "商品管理" "navigationBarTitleText": "商品管理"
} }
}, },
{
"path": "pages/product/select",
"style": {
"navigationBarTitleText": "选择商品"
}
},
{ {
"path": "pages/order/create", "path": "pages/order/create",
"style": { "style": {

View File

@@ -22,14 +22,7 @@
<view class="section"> <view class="section">
<view class="section-header"> <view class="section-header">
<text class="section-title">商品明细</text> <text class="section-title">商品明细</text>
<picker <text class="add-btn" @click="goToSelectProduct">+ 添加商品</text>
mode="selector"
:range="productList"
range-key="name"
@change="onProductSelect"
>
<text class="add-btn">+ 添加商品</text>
</picker>
</view> </view>
<view v-for="(item, index) in orderItems" :key="index" class="order-item"> <view v-for="(item, index) in orderItems" :key="index" class="order-item">
@@ -188,8 +181,10 @@ export default {
selectCustomer(e) { selectCustomer(e) {
this.selectedCustomer = this.customers[e.detail.value] this.selectedCustomer = this.customers[e.detail.value]
}, },
onProductSelect(e) { goToSelectProduct() {
const product = this.productList[e.detail.value] uni.navigateTo({ url: '/pages/product/select' })
},
addProduct(product) {
// 检查是否已添加 // 检查是否已添加
const exists = this.orderItems.find(item => item.productId === product.productId) const exists = this.orderItems.find(item => item.productId === product.productId)
if (exists) { if (exists) {

View File

@@ -0,0 +1,169 @@
<template>
<view class="page">
<!-- 搜索栏 -->
<view class="search-bar">
<input
class="search-input"
v-model="keyword"
placeholder="搜索商品名称"
@confirm="search"
/>
<button class="search-btn" @click="search">搜索</button>
</view>
<!-- 商品列表 -->
<scroll-view scroll-y class="product-list">
<view
v-for="item in productList"
:key="item.productId"
class="product-item"
@click="selectProduct(item)"
>
<view class="product-info">
<text class="product-name">{{ item.name }}</text>
<text class="product-spec">{{ item.spec || '-' }}</text>
</view>
<view class="product-price">
<text class="price">¥{{ item.price }}</text>
<text class="unit">{{ item.unit || '个' }}</text>
</view>
</view>
<view v-if="productList.length === 0" class="empty">
<text>暂无商品</text>
</view>
</scroll-view>
</view>
</template>
<script>
import productApi from '@/api/product'
export default {
data() {
return {
keyword: '',
productList: [],
page: 1,
pageSize: 50,
loading: false
}
},
onLoad() {
this.getProducts()
},
methods: {
async getProducts() {
this.loading = true
try {
const res = await productApi.getProducts({
keyword: this.keyword,
page: this.page,
pageSize: this.pageSize
})
if (res.code === 0) {
this.productList = res.data.records || []
}
} catch (e) {
uni.showToast({ title: '加载失败', icon: 'none' })
} finally {
this.loading = false
}
},
search() {
this.page = 1
this.getProducts()
},
selectProduct(item) {
// 返回上一页并传递选中的商品
const pages = getCurrentPages()
const prevPage = pages[pages.length - 2]
prevPage.$vm.addProduct(item)
uni.navigateBack()
}
}
}
</script>
<style scoped>
.page {
min-height: 100vh;
background: #f5f5f5;
}
.search-bar {
display: flex;
padding: 20rpx;
background: #fff;
}
.search-input {
flex: 1;
height: 72rpx;
background: #f5f5f5;
border-radius: 8rpx;
padding: 0 20rpx;
font-size: 28rpx;
}
.search-btn {
margin-left: 20rpx;
height: 72rpx;
line-height: 72rpx;
font-size: 28rpx;
background: #3cc51f;
color: #fff;
}
.product-list {
height: calc(100vh - 180rpx);
}
.product-item {
display: flex;
justify-content: space-between;
align-items: center;
margin: 20rpx;
padding: 30rpx;
background: #fff;
border-radius: 12rpx;
}
.product-info {
flex: 1;
}
.product-name {
display: block;
font-size: 30rpx;
font-weight: 500;
margin-bottom: 8rpx;
}
.product-spec {
font-size: 24rpx;
color: #999;
}
.product-price {
text-align: right;
}
.price {
display: block;
font-size: 32rpx;
font-weight: bold;
color: #3cc51f;
}
.unit {
font-size: 24rpx;
color: #999;
}
.empty {
text-align: center;
padding: 100rpx;
color: #999;
}
</style>