feat: 新增商品详情页,点击商品卡片可查看详情
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -30,6 +30,12 @@
|
|||||||
"navigationBarTitleText": "选择商品"
|
"navigationBarTitleText": "选择商品"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"path": "pages/product/detail",
|
||||||
|
"style": {
|
||||||
|
"navigationBarTitleText": "商品详情"
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"path": "pages/order/create",
|
"path": "pages/order/create",
|
||||||
"style": {
|
"style": {
|
||||||
|
|||||||
250
src/pages/product/detail.vue
Normal file
250
src/pages/product/detail.vue
Normal file
@@ -0,0 +1,250 @@
|
|||||||
|
<template>
|
||||||
|
<view class="page">
|
||||||
|
<!-- 商品图片区域 -->
|
||||||
|
<view class="image-section">
|
||||||
|
<view class="product-image">
|
||||||
|
<Icon name="product" :size="120" color="#fff" />
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<!-- 商品基本信息 -->
|
||||||
|
<view class="info-section">
|
||||||
|
<view class="price-row">
|
||||||
|
<text class="price">¥{{ product.price }}</text>
|
||||||
|
<text class="unit">/{{ product.unit }}</text>
|
||||||
|
</view>
|
||||||
|
<text class="product-name">{{ product.name }}</text>
|
||||||
|
<text class="product-spec">规格: {{ product.spec || '-' }}</text>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<!-- 商品详情 -->
|
||||||
|
<view class="detail-section">
|
||||||
|
<view class="detail-header">
|
||||||
|
<text class="detail-title">商品详情</text>
|
||||||
|
</view>
|
||||||
|
<view class="detail-content">
|
||||||
|
<view class="detail-item">
|
||||||
|
<text class="detail-label">商品分类</text>
|
||||||
|
<text class="detail-value">{{ categoryName }}</text>
|
||||||
|
</view>
|
||||||
|
<view class="detail-item">
|
||||||
|
<text class="detail-label">商品编码</text>
|
||||||
|
<text class="detail-value">{{ product.productId }}</text>
|
||||||
|
</view>
|
||||||
|
<view class="detail-item">
|
||||||
|
<text class="detail-label">成本价</text>
|
||||||
|
<text class="detail-value">¥{{ product.costPrice || '-' }}</text>
|
||||||
|
</view>
|
||||||
|
<view class="detail-item">
|
||||||
|
<text class="detail-label">库存预警</text>
|
||||||
|
<text class="detail-value">{{ product.stockAlert || '-' }}</text>
|
||||||
|
</view>
|
||||||
|
<view class="detail-item">
|
||||||
|
<text class="detail-label">当前库存</text>
|
||||||
|
<text class="detail-value stock">{{ stock }}</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<!-- 底部操作按钮 -->
|
||||||
|
<view class="bottom-bar">
|
||||||
|
<button class="btn-edit" @click="editProduct" v-if="isAdmin">
|
||||||
|
<Icon name="edit" :size="32" color="#fff" style="margin-right: 10rpx" />
|
||||||
|
编辑商品
|
||||||
|
</button>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import productApi from '@/api/product'
|
||||||
|
import stockApi from '@/api/stock'
|
||||||
|
import { isAdmin } from '@/utils/auth'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
productId: '',
|
||||||
|
product: {},
|
||||||
|
categoryName: '',
|
||||||
|
stock: 0,
|
||||||
|
isAdmin: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onLoad(options) {
|
||||||
|
if (options.productId) {
|
||||||
|
this.productId = options.productId
|
||||||
|
this.isAdmin = isAdmin()
|
||||||
|
this.loadProductDetail()
|
||||||
|
this.loadStock()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
async loadProductDetail() {
|
||||||
|
try {
|
||||||
|
const res = await productApi.getProduct(this.productId)
|
||||||
|
this.product = res
|
||||||
|
// 获取分类名称
|
||||||
|
const categories = await productApi.getCategories()
|
||||||
|
const category = categories.find(c => c.categoryId === this.product.categoryId)
|
||||||
|
this.categoryName = category ? category.name : '-'
|
||||||
|
} catch (e) {
|
||||||
|
uni.showToast({ title: '加载失败', icon: 'none' })
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async loadStock() {
|
||||||
|
try {
|
||||||
|
const res = await stockApi.getStock(this.productId)
|
||||||
|
this.stock = res.quantity || 0
|
||||||
|
} catch (e) {
|
||||||
|
this.stock = 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
editProduct() {
|
||||||
|
uni.navigateTo({
|
||||||
|
url: `/pages/product/manage?productId=${this.productId}`
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.page {
|
||||||
|
min-height: 100vh;
|
||||||
|
background: #f8f9fa;
|
||||||
|
padding-bottom: 120rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 图片区域 */
|
||||||
|
.image-section {
|
||||||
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||||
|
padding: 60rpx;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.product-image {
|
||||||
|
width: 300rpx;
|
||||||
|
height: 300rpx;
|
||||||
|
background: rgba(255, 255, 255, 0.2);
|
||||||
|
border-radius: 24rpx;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 商品信息 */
|
||||||
|
.info-section {
|
||||||
|
background: #fff;
|
||||||
|
padding: 30rpx;
|
||||||
|
margin-bottom: 20rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.price-row {
|
||||||
|
display: flex;
|
||||||
|
align-items: baseline;
|
||||||
|
margin-bottom: 16rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.price {
|
||||||
|
font-size: 48rpx;
|
||||||
|
font-weight: bold;
|
||||||
|
color: #ff4d4f;
|
||||||
|
}
|
||||||
|
|
||||||
|
.unit {
|
||||||
|
font-size: 28rpx;
|
||||||
|
color: #999;
|
||||||
|
margin-left: 8rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.product-name {
|
||||||
|
display: block;
|
||||||
|
font-size: 36rpx;
|
||||||
|
font-weight: bold;
|
||||||
|
color: #333;
|
||||||
|
margin-bottom: 12rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.product-spec {
|
||||||
|
font-size: 26rpx;
|
||||||
|
color: #666;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 详情区域 */
|
||||||
|
.detail-section {
|
||||||
|
background: #fff;
|
||||||
|
margin: 0 20rpx;
|
||||||
|
border-radius: 20rpx;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.detail-header {
|
||||||
|
padding: 24rpx 30rpx;
|
||||||
|
border-bottom: 1rpx solid #f0f0f0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.detail-title {
|
||||||
|
font-size: 28rpx;
|
||||||
|
font-weight: bold;
|
||||||
|
color: #333;
|
||||||
|
}
|
||||||
|
|
||||||
|
.detail-content {
|
||||||
|
padding: 10rpx 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.detail-item {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
padding: 24rpx 30rpx;
|
||||||
|
border-bottom: 1rpx solid #f8f8f8;
|
||||||
|
}
|
||||||
|
|
||||||
|
.detail-item:last-child {
|
||||||
|
border-bottom: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.detail-label {
|
||||||
|
font-size: 26rpx;
|
||||||
|
color: #666;
|
||||||
|
}
|
||||||
|
|
||||||
|
.detail-value {
|
||||||
|
font-size: 26rpx;
|
||||||
|
color: #333;
|
||||||
|
}
|
||||||
|
|
||||||
|
.detail-value.stock {
|
||||||
|
font-size: 32rpx;
|
||||||
|
font-weight: bold;
|
||||||
|
color: #667eea;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 底部按钮 */
|
||||||
|
.bottom-bar {
|
||||||
|
position: fixed;
|
||||||
|
bottom: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
padding: 20rpx 30rpx;
|
||||||
|
background: #fff;
|
||||||
|
box-shadow: 0 -4rpx 20rpx rgba(0, 0, 0, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-edit {
|
||||||
|
width: 100%;
|
||||||
|
height: 88rpx;
|
||||||
|
line-height: 88rpx;
|
||||||
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||||
|
color: #fff;
|
||||||
|
border: none;
|
||||||
|
border-radius: 44rpx;
|
||||||
|
font-size: 30rpx;
|
||||||
|
font-weight: bold;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -154,7 +154,9 @@ export default {
|
|||||||
this.loadProducts()
|
this.loadProducts()
|
||||||
},
|
},
|
||||||
viewDetail(item) {
|
viewDetail(item) {
|
||||||
uni.showToast({ title: '商品详情开发中', icon: 'none' })
|
uni.navigateTo({
|
||||||
|
url: `/pages/product/detail?productId=${item.productId}`
|
||||||
|
})
|
||||||
},
|
},
|
||||||
getStock(productId) {
|
getStock(productId) {
|
||||||
return this.stocks[productId] || 0
|
return this.stocks[productId] || 0
|
||||||
|
|||||||
Reference in New Issue
Block a user