From 721e425b72010cd1e23148303a52627a7bc042ef Mon Sep 17 00:00:00 2001 From: fy <> Date: Fri, 23 Jan 2026 15:36:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=95=86=E5=93=81=E8=AF=A6=E6=83=85=E5=8A=A0?= =?UTF-8?q?=E5=88=86=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/category/category.vue | 4 +- pages/edit/edit.vue | 257 +++++++++++++++++++++++++++++++++--- 2 files changed, 239 insertions(+), 22 deletions(-) diff --git a/pages/category/category.vue b/pages/category/category.vue index 202f391..51766a2 100644 --- a/pages/category/category.vue +++ b/pages/category/category.vue @@ -2,9 +2,7 @@ - - - + 分类管理 ··· diff --git a/pages/edit/edit.vue b/pages/edit/edit.vue index 3449050..62a7bf9 100644 --- a/pages/edit/edit.vue +++ b/pages/edit/edit.vue @@ -229,15 +229,13 @@ - - + + 商品分类 - + + {{ goodsInfo.category || '请选择分类' }} + > + @@ -249,7 +247,7 @@ - + @@ -321,6 +319,69 @@ + + + + + + + × + + 选择分类 + + 完成 + + + + + + + + + + + + + + + + + 分类管理 + + + + 商品编码 @@ -357,7 +418,7 @@ export default { stock: 1, buyPrice: 1.0, category: '默认', - brand: '那', // 匹配图片默认选中 + brand: '那', code: '1', shelfCode: '', productionDate: '' @@ -387,9 +448,15 @@ export default { // 品牌选择弹窗相关 showBrandSelector: false, brandSearchKeyword: '', - selectedBrand: '那', // 匹配图片默认选中 - brandData: [], // 品牌数据 - expandedBrands: {} // 记录展开状态的对象 + selectedBrand: '那', + brandData: [], + expandedBrands: {}, + // 分类选择弹窗相关 + showCategorySelector: false, + categorySearchKeyword: '', + selectedCategory: 'default', + categoryData: [], // 分类数据 + expandedCategories: {} // 记录展开状态的对象 } }, onLoad(options) { @@ -494,13 +561,14 @@ export default { salePrice: data.storePrice || this.goodsInfo.salePrice, stock: data.stockQuantity || this.goodsInfo.stock, buyPrice: data.costPrice || this.goodsInfo.buyPrice, - category: this.goodsInfo.category, + category: data.classifcation || this.goodsInfo.category, brand: data.productBrand || this.goodsInfo.brand, code: data.productCode || this.goodsInfo.code }; this.activePrice = data.storePrice || this.goodsInfo.salePrice; this.selectedBrand = data.productBrand || this.goodsInfo.brand; + this.selectedCategory = data.classifcation || this.goodsInfo.category; if (data.shelfLife) { this.switchStatus.expire = true; @@ -583,7 +651,8 @@ export default { approaching: this.switchStatus.expire ? this.expireSettings.warnDays : null, productionDate: this.goodsInfo.productionDate || '', storeId: storeId, - productBrand: this.goodsInfo.brand + productBrand: this.goodsInfo.brand, + classification: this.goodsInfo.category }; const res = await updateProductWithFile(this.goodsInfo.imageUrl || '', formData); @@ -638,6 +707,40 @@ export default { } }, + // 获取分类数据 + async getCategoryData() { + try { + const storeId = getStoreId(); + if (!storeId) { + uni.showToast({ + title: '请先选择门店', + icon: 'none' + }); + return; + } + + const res = await uni.request({ + url: `http://193.112.94.36:8081/mall/classification/getTree/${storeId}`, + method: 'GET' + }); + + if (res[1] && res[1].data && res[1].data.code === 200) { + this.categoryData = res[1].data.data; + } else { + uni.showToast({ + title: '获取分类数据失败', + icon: 'none' + }); + } + } catch (error) { + console.error('获取分类数据失败:', error); + uni.showToast({ + title: '网络请求失败', + icon: 'none' + }); + } + }, + // 品牌选择弹窗方法 selectBrand(brandName) { this.selectedBrand = brandName; @@ -659,7 +762,37 @@ export default { uni.navigateTo({ url: '/pages/addBrand/addBrand' }); - + }, + // 分类选择弹窗方法 + selectCategory(categoryName) { + this.selectedCategory = categoryName; + }, + confirmSelectedCategory() { + // 根据选中值映射显示名称 + const categoryMap = { + 'rx': '处方药(RX)', + 'vet-otc': '兽用非处方药', + 'vet-rx': '兽用处方药', + 'default': '默认', + 'otc-child': 'OTC子分类示例', + 'go-child': '子分类示例' + }; + this.goodsInfo.category = categoryMap[this.selectedCategory] || this.selectedCategory; + this.showCategorySelector = false; + this.categorySearchKeyword = ''; + }, + closeCategorySelector() { + this.showCategorySelector = false; + this.categorySearchKeyword = ''; + }, + toggleCategoryExpand(key) { + this.$set(this.expandedCategories, key, !this.expandedCategories[key]); + }, + goToCategoryManagement() { + this.showCategorySelector = false; + uni.navigateTo({ + url: '/pages/category/category' + }); } } }; @@ -1015,7 +1148,7 @@ export default { } } -// 商品品牌选中值样式 +// 商品品牌/分类选中值样式 .selected-value { font-size: 30rpx; color: #333; @@ -1023,7 +1156,7 @@ export default { } // -------------------------- -// 品牌选择弹窗样式(完全匹配参考代码) +// 品牌选择弹窗样式 // -------------------------- .brand-selector-overlay { position: fixed; @@ -1120,7 +1253,7 @@ export default { color: #999; transition: transform 0.2s ease; &.expanded { - transform: rotate(180deg); + transform: rotate(90deg); } } .parent-text { @@ -1136,4 +1269,90 @@ export default { font-size: 28rpx; border-top: 1rpx solid #f0f0f0; } + +// -------------------------- +// 分类选择弹窗样式(完全匹配图片) +// -------------------------- +.category-selector-overlay { + position: fixed; + top: 0; + left: 0; + right: 0; + bottom: 0; + background: rgba(0, 0, 0, 0.5); + display: flex; + align-items: flex-end; + z-index: 999; +} + +.category-selector-container { + width: 100%; + background: #fff; + border-radius: 16rpx 16rpx 0 0; + max-height: 80vh; + display: flex; + flex-direction: column; +} + +.category-list { + flex: 1; + overflow-y: auto; + // 普通分类项 + .category-item { + padding: 30rpx; + border-bottom: 1rpx solid #f0f0f0; + font-size: 30rpx; + color: #333; + position: relative; + &.active { + border: 1rpx solid #E62429; + border-radius: 8rpx; + margin: 0 16rpx; + &::after { + content: "✓"; + position: absolute; + right: 30rpx; + top: 50%; + transform: translateY(-50%); + font-size: 28rpx; + color: #E62429; + } + } + // 子节点样式 + &.child { + padding-left: 60rpx; + background-color: #fafafa; + } + } + + // 父节点样式 + .category-parent-item { + padding: 30rpx; + border-bottom: 1rpx solid #f0f0f0; + font-size: 30rpx; + color: #333; + display: flex; + align-items: center; + .expand-icon { + font-size: 24rpx; + margin-right: 10rpx; + color: #999; + transition: transform 0.2s ease; + &.expanded { + transform: rotate(90deg); + } + } + .parent-text { + flex: 1; + } + } +} + +.category-management { + padding: 30rpx; + text-align: center; + color: #1677FF; + font-size: 28rpx; + border-top: 1rpx solid #f0f0f0; +} \ No newline at end of file