Преглед на файлове

团餐商品列表增加审核提示文字,优化切换逻辑;
添加商品增加价格之间的校验;

郭鹏飞 преди 10 месеца
родител
ревизия
916621c751
променени са 3 файла, в които са добавени 94 реда и са изтрити 19 реда
  1. 38 2
      pages/groupMeal/goods/form-step1.vue
  2. 8 6
      pages/groupMeal/goods/form-step2.vue
  3. 48 11
      pages/groupMeal/goods/list.vue

+ 38 - 2
pages/groupMeal/goods/form-step1.vue

@@ -48,12 +48,21 @@
 				</u-form-item>
 
 				<u-form-item prop="price" label="团餐价" required borderBottom>
-					<u-input v-model.number="form.price" type="digit" height="41" :clearable="false" placeholder="请输入团餐价" inputAlign="right"></u-input>
+					<u-input type="digit" height="41" :clearable="false" 
+						inputAlign="right"
+						placeholder="请输入团餐价" 
+						v-model.number="form.price"
+						@input="onInput($event, 'price')"
+					></u-input>
 					<text slot="right" class="input-suffix">元</text>
 				</u-form-item>
 				
 				<u-form-item prop="sellingPrice" label="售价" required :borderBottom="true">
-					<u-input v-model.number="form.sellingPrice" type="digit" height="41" :clearable="false" placeholder="请输入商品售价" inputAlign="right"></u-input>
+					<u-input type="digit" height="41" :clearable="false" 
+					 	inputAlign="right" placeholder="请输入商品售价"
+						v-model.number="form.sellingPrice"
+						@input="onInput($event, 'sellingPrice')"
+					></u-input>
 					<text slot="right" class="input-suffix">元</text>
 				</u-form-item>
 			</u-form>
@@ -228,6 +237,33 @@ export default {
 			this.form.category = e.value;
 			this.form.categoryName = e.text;
 		},
+		// 价格数值处理
+		onInput(value, key) {
+			// 过滤所有非数字和非小数点的字符
+			let filtered = value.replace(/[^\d.]/g, '');
+			
+			// 处理多个小数点(只保留第一个)
+			filtered = filtered.replace(/^\./g, ''); // 移除开头的小数点(避免 ".123" 情况)
+			filtered = filtered.replace(/\.{2,}/g, '.'); // 多个小数点只保留第一个
+			
+			// 分割整数和小数部分,限制小数最多两位
+			const parts = filtered.split('.');
+			if (parts.length > 1) {
+				// 小数部分只保留前两位
+				filtered = parts[0] + '.' + (parts[1].slice(0, 2) || '');
+			}
+			
+			// 处理特殊情况(如 "000" 转为 "0",但价格允许 "0.00")
+			// 若需要严格限制整数部分首位不为0(非必须,根据业务决定):
+			// if (parts.length === 1 && filtered.length > 1 && filtered[0] === '0') {
+			//   filtered = filtered.replace(/^0+/, '0');
+			// }
+			
+			// 更新绑定值
+			this.$nextTick(() => {
+				this.form[key] = filtered;
+			});
+		},
 		// 图片处理
 		onUpload(event, type) {
 			this.fileList[type] = event;

+ 8 - 6
pages/groupMeal/goods/form-step2.vue

@@ -269,12 +269,14 @@ export default {
 						// 遍历二级菜品
 						category.items.forEach(item => {
 							// 创建新对象,只保留需要的属性
-							details.push({
-								category: category.id,
-								name: item.name,
-								price: item.price,
-								description: item.description
-							});
+							if (this.isEdited(item)) {
+								details.push({
+									category: category.id,
+									name: item.name,
+									price: item.price,
+									description: item.description
+								});
+							}
 						});
 					}
 				});

+ 48 - 11
pages/groupMeal/goods/list.vue

@@ -25,7 +25,7 @@
 		</view>
 
 		<!-- 一级分类Tabs -->
-		<u-tabs :list="statusTabs" 
+		<u-tabs ref="tabs" :list="statusTabs" 
 			:current="currentStatusTab" 
 			font-size="30"
 			inactive-color="#666666"
@@ -75,6 +75,7 @@
 									<text class="price"><text class="unit">¥</text>{{ goods.price }}</text>
 									<text class="original-price">¥{{ goods.sellingPrice }}</text>
 								</view>
+								<view class="status" v-if="currentStatusTab == 2 && goods.reviewStatus !== 1">{{ getReviewStatus(goods.reviewStatus) }}</view>
 							</view>
 							<!-- 根据模式和状态显示不同操作 -->
 							<view class="goods-actions">
@@ -197,9 +198,9 @@ export default {
 			let params = {
 				// 商品状态: 0 未上架, 1 已上架
 				status: 0,
-				// 审核状态: 0 审核中, 1 已审核
+				// 审核状态: 0 审核中, 1 已审核, 2 驳回
 				// reviewStatus: 0,
-				queryName: this.queryName,
+				name: this.queryName,
 			}
 			// 售卖中
 			if (this.currentStatusTab == 0) {
@@ -222,7 +223,7 @@ export default {
 				params = {
 					...params,
 					status: 0,
-					reviewStatus: 1,
+					// reviewStatus: 1,
 				}
 			}
 			return params;
@@ -239,6 +240,9 @@ export default {
 	methods: {
 		// 商品数据
 		getData() {
+			uni.showLoading({
+				title: '加载中'
+			});
 			let params = {
 				pageNo: 1,
 				pageSize: 100,
@@ -253,6 +257,7 @@ export default {
 						}
 					});
 				}
+				uni.hideLoading();
 			});
 		},
 		// 餐品分类
@@ -261,11 +266,20 @@ export default {
 				if (res.data.code === 200) {}
 			});
 		},
+		getReviewStatus(status) {
+			// 审核状态: 0 审核中, 1 已审核, 2 驳回
+			const statusMap = {
+				0: '审核中',
+				1: '已通过',
+				2: '未通过',
+			};
+			return statusMap[status] || '';
+		},
 		// 操作模式
 		toggleManageMode() {
 			this.isManaging = !this.isManaging;
-			this.selectedGoods = []; // 切换模式时清空选择
-			this.isAllSelected = false;
+			// 切换模式时清空选择
+			this.onClearSel();
 			if (!this.isManaging) {
 				this.filteredGoods.flatMap(category => category.items.forEach(item => {
 					item.checked = false;
@@ -278,12 +292,12 @@ export default {
 		// 主分类事件
 		onTabChange(e) {
 			this.currentStatusTab = e;
-			this.selectedGoods = []; // 切换Tab时清空选择
-			this.isAllSelected = false;
+			// 切换Tab时清空选择
+			this.onClearSel();
 			// 列表数据
 			this.getData();
 			// 切换 Tab 后,重置左侧分类高亮到第一个
-			// this.currentCategoryTab = 0; 
+			this.currentCategoryTab = 0; 
 			// this.$nextTick(() => {
 			// 	// 确保在新数据渲染后,滚动到第一个分类
 			// 	this.scrollIntoViewId = this.filteredGoods[0]?.scrollId || '';
@@ -291,12 +305,14 @@ export default {
 		},
 		// 添加商品
 		addGoods() {
+			this.isManaging = false;
 			uni.navigateTo({
 				url: '/pages/groupMeal/goods/form-step1'
 			});
 		},
 		// 编辑商品
 		editGoods(goods) {
+			this.isManaging = false;
 			uni.navigateTo({
 				url: '/pages/groupMeal/goods/form-step1?id=' + goods.id
 			});
@@ -351,7 +367,10 @@ export default {
 				this.$http.delete('/groupmeal/gmMerchantPackage/deleteBatch', {}, {
 					params: { ids: this.selectedGoods.join() }
 				}).then(res => {
-					if (res.data.code === 200) {}
+					if (res.data.code === 200) {
+						this.onClearSel();
+						this.getData();
+					}
 					this.$tip.toast(res.data.message);
 				});
 			} else {
@@ -362,11 +381,19 @@ export default {
 					ids: this.selectedGoods,
 					status: this.currentStatusTab == 2 ? 1 : 0 
 				}).then(res => {
-					if (res.data.code === 200) {}
+					if (res.data.code === 200) {
+						this.onClearSel();
+						this.getData();
+					}
 					this.$tip.toast(res.data.message);
 				});
 			}
 		},
+		// 完成某种操作后,清空数据
+		onClearSel() {
+			this.selectedGoods = []; 
+			this.isAllSelected = false;
+		},
 		// 核心功能 1: 点击左侧二级分类,右侧商品列表滚动到对应位置
 		onCategoryTabChange(index) {
 			this.currentCategoryTab = index;
@@ -568,6 +595,16 @@ export default {
 					margin-left: 10rpx;
 				}
 			}
+			.status {
+				color: #fff;
+				font-size: 24rpx;
+				padding: 5rpx 10rpx;
+				border-radius: 12rpx 0 12rpx;
+				background: #449AFF;
+				position: absolute;
+				top: 20rpx;
+				left: 0;
+			}
 		}
 		.goods-actions {
 			position: absolute;