This commit is contained in:
@@ -24,6 +24,12 @@
|
||||
"navigationBarTitleText": "商品管理"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/product/select",
|
||||
"style": {
|
||||
"navigationBarTitleText": "选择商品"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/order/create",
|
||||
"style": {
|
||||
|
||||
@@ -22,14 +22,7 @@
|
||||
<view class="section">
|
||||
<view class="section-header">
|
||||
<text class="section-title">商品明细</text>
|
||||
<picker
|
||||
mode="selector"
|
||||
:range="productList"
|
||||
range-key="name"
|
||||
@change="onProductSelect"
|
||||
>
|
||||
<text class="add-btn">+ 添加商品</text>
|
||||
</picker>
|
||||
<text class="add-btn" @click="goToSelectProduct">+ 添加商品</text>
|
||||
</view>
|
||||
|
||||
<view v-for="(item, index) in orderItems" :key="index" class="order-item">
|
||||
@@ -188,8 +181,10 @@ export default {
|
||||
selectCustomer(e) {
|
||||
this.selectedCustomer = this.customers[e.detail.value]
|
||||
},
|
||||
onProductSelect(e) {
|
||||
const product = this.productList[e.detail.value]
|
||||
goToSelectProduct() {
|
||||
uni.navigateTo({ url: '/pages/product/select' })
|
||||
},
|
||||
addProduct(product) {
|
||||
// 检查是否已添加
|
||||
const exists = this.orderItems.find(item => item.productId === product.productId)
|
||||
if (exists) {
|
||||
|
||||
169
src/pages/product/select.vue
Normal file
169
src/pages/product/select.vue
Normal 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>
|
||||
Reference in New Issue
Block a user