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:
@@ -1,51 +1,70 @@
|
|||||||
<template>
|
<template>
|
||||||
<view class="page">
|
<view class="page">
|
||||||
<!-- 搜索栏 -->
|
<!-- 搜索栏 -->
|
||||||
<view class="search-bar">
|
<view class="search-section">
|
||||||
<input
|
<view class="search-bar">
|
||||||
class="search-input"
|
<input
|
||||||
v-model="keyword"
|
class="search-input"
|
||||||
placeholder="搜索商品名称"
|
v-model="keyword"
|
||||||
@confirm="search"
|
placeholder="搜索商品名称"
|
||||||
/>
|
@confirm="search"
|
||||||
<button class="search-btn" @click="search">搜索</button>
|
/>
|
||||||
<button class="add-btn" @click="addProduct">+</button>
|
<button class="add-btn" @click="addProduct">+</button>
|
||||||
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<!-- 商品列表 -->
|
<!-- 分类侧栏 + 商品列表 -->
|
||||||
<view class="product-list">
|
<view class="content-wrapper">
|
||||||
<view
|
<!-- 左侧分类 -->
|
||||||
v-for="item in products"
|
<scroll-view scroll-y class="category-sidebar">
|
||||||
:key="item.productId"
|
<view class="category-item" :class="{ active: !categoryId }" @click="selectCategory('')">
|
||||||
class="product-item"
|
全部
|
||||||
>
|
</view>
|
||||||
<view class="product-info" @click="editProduct(item)">
|
<view v-for="cat in categories" :key="cat.categoryId" class="category-item" :class="{ active: categoryId === cat.categoryId }" @click="selectCategory(cat.categoryId)">
|
||||||
<text class="product-name">{{ item.name }}</text>
|
{{ cat.name }}
|
||||||
<text class="product-spec">{{ item.spec || '-' }}</text>
|
</view>
|
||||||
<view class="product-price">
|
</scroll-view>
|
||||||
<text class="price">¥{{ item.price }}</text>
|
|
||||||
<text class="unit">/{{ item.unit }}</text>
|
<!-- 右侧商品列表 -->
|
||||||
|
<scroll-view scroll-y class="product-scroll">
|
||||||
|
<view class="product-list">
|
||||||
|
<view
|
||||||
|
v-for="item in productList"
|
||||||
|
:key="item.productId"
|
||||||
|
class="product-item"
|
||||||
|
>
|
||||||
|
<view class="product-info" @click="editProduct(item)">
|
||||||
|
<view class="product-header">
|
||||||
|
<text class="product-name">{{ item.name }}</text>
|
||||||
|
<text class="product-category" v-if="item.categoryName">{{ item.categoryName }}</text>
|
||||||
|
</view>
|
||||||
|
<text class="product-spec">{{ item.spec || '-' }}</text>
|
||||||
|
<view class="product-price">
|
||||||
|
<text class="price">¥{{ item.price }}</text>
|
||||||
|
<text class="unit">/{{ item.unit }}</text>
|
||||||
|
</view>
|
||||||
|
<view class="product-status">
|
||||||
|
<text :class="['status', item.status === 1 ? 'on' : 'off']">
|
||||||
|
{{ item.status === 1 ? '上架' : '下架' }}
|
||||||
|
</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<view class="product-actions">
|
||||||
|
<view class="action-btn" @click="toggleStatus(item)">
|
||||||
|
{{ item.status === 1 ? '下架' : '上架' }}
|
||||||
|
</view>
|
||||||
|
<view class="action-btn delete" @click="deleteProduct(item)">
|
||||||
|
删除
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="product-status">
|
|
||||||
<text :class="['status', item.status === 1 ? 'on' : 'off']">
|
<!-- 空状态 -->
|
||||||
{{ item.status === 1 ? '上架' : '下架' }}
|
<view v-if="productList.length === 0" class="empty">
|
||||||
</text>
|
<text>暂无商品</text>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="product-actions">
|
</scroll-view>
|
||||||
<view class="action-btn" @click="toggleStatus(item)">
|
|
||||||
{{ item.status === 1 ? '下架' : '上架' }}
|
|
||||||
</view>
|
|
||||||
<view class="action-btn delete" @click="deleteProduct(item)">
|
|
||||||
删除
|
|
||||||
</view>
|
|
||||||
</view>
|
|
||||||
</view>
|
|
||||||
|
|
||||||
<!-- 空状态 -->
|
|
||||||
<view v-if="products.length === 0" class="empty">
|
|
||||||
<text>暂无商品</text>
|
|
||||||
</view>
|
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<!-- 商品表单弹窗 -->
|
<!-- 商品表单弹窗 -->
|
||||||
@@ -119,7 +138,8 @@ export default {
|
|||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
keyword: '',
|
keyword: '',
|
||||||
products: [],
|
categoryId: '',
|
||||||
|
productList: [],
|
||||||
categories: [],
|
categories: [],
|
||||||
showModal: false,
|
showModal: false,
|
||||||
isEdit: false,
|
isEdit: false,
|
||||||
@@ -176,14 +196,19 @@ export default {
|
|||||||
try {
|
try {
|
||||||
const res = await productApi.getProducts({
|
const res = await productApi.getProducts({
|
||||||
keyword: this.keyword,
|
keyword: this.keyword,
|
||||||
|
categoryId: this.categoryId,
|
||||||
page: 1,
|
page: 1,
|
||||||
pageSize: 100
|
pageSize: 100
|
||||||
})
|
})
|
||||||
this.products = res.records || []
|
this.productList = res.records || []
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
selectCategory(id) {
|
||||||
|
this.categoryId = id
|
||||||
|
this.loadProducts()
|
||||||
|
},
|
||||||
search() {
|
search() {
|
||||||
this.loadProducts()
|
this.loadProducts()
|
||||||
},
|
},
|
||||||
@@ -292,6 +317,81 @@ export default {
|
|||||||
|
|
||||||
<style>
|
<style>
|
||||||
.page {
|
.page {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
height: 100vh;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 搜索区域 */
|
||||||
|
.search-section {
|
||||||
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||||
|
padding: 20rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.search-bar {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
background: rgba(255, 255, 255, 0.95);
|
||||||
|
border-radius: 50rpx;
|
||||||
|
padding: 0 20rpx;
|
||||||
|
height: 70rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.search-input {
|
||||||
|
flex: 1;
|
||||||
|
font-size: 28rpx;
|
||||||
|
color: #333;
|
||||||
|
}
|
||||||
|
|
||||||
|
.add-btn {
|
||||||
|
width: 60rpx;
|
||||||
|
height: 60rpx;
|
||||||
|
line-height: 60rpx;
|
||||||
|
background: #3cc51f;
|
||||||
|
color: #fff;
|
||||||
|
border: none;
|
||||||
|
border-radius: 50%;
|
||||||
|
font-size: 36rpx;
|
||||||
|
margin-left: 16rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 内容区域:侧栏+列表 */
|
||||||
|
.content-wrapper {
|
||||||
|
display: flex;
|
||||||
|
flex: 1;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 分类侧栏 */
|
||||||
|
.category-sidebar {
|
||||||
|
width: 160rpx;
|
||||||
|
background: #fff;
|
||||||
|
flex-shrink: 0;
|
||||||
|
border-right: 1rpx solid #eee;
|
||||||
|
}
|
||||||
|
|
||||||
|
.category-item {
|
||||||
|
padding: 28rpx 16rpx;
|
||||||
|
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;
|
padding: 20rpx;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -355,6 +455,20 @@ export default {
|
|||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.product-header {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
}
|
||||||
|
|
||||||
|
.product-category {
|
||||||
|
font-size: 22rpx;
|
||||||
|
color: #667eea;
|
||||||
|
background: #f0f0ff;
|
||||||
|
padding: 4rpx 12rpx;
|
||||||
|
border-radius: 4rpx;
|
||||||
|
}
|
||||||
|
|
||||||
.product-spec {
|
.product-spec {
|
||||||
font-size: 24rpx;
|
font-size: 24rpx;
|
||||||
color: #999;
|
color: #999;
|
||||||
|
|||||||
Reference in New Issue
Block a user