From fe87d62a23e2c4773ccdf36f2d6305afacefdc8c Mon Sep 17 00:00:00 2001 From: wx-jincw Date: Sat, 11 Apr 2026 10:59:02 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=A4=90=E5=88=AB=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/pages/supply_chain/day_menu/index.vue | 71 +++++++++++++++-------- 1 file changed, 47 insertions(+), 24 deletions(-) diff --git a/app/pages/supply_chain/day_menu/index.vue b/app/pages/supply_chain/day_menu/index.vue index 74e05d3..859c052 100644 --- a/app/pages/supply_chain/day_menu/index.vue +++ b/app/pages/supply_chain/day_menu/index.vue @@ -143,18 +143,14 @@ import { } from '@/api/property.js'; export default { - dicts: ['canteen_name'], + dicts: ['canteen_name', 'meal_type'], data() { return { selectedDate: '', menuList: [], rankingType: 'like', rankingList: [], - mealSections: [ - { key: 'breakfast', label: '早餐', list: [] }, - { key: 'lunch', label: '中餐', list: [] }, - { key: 'dinner', label: '晚餐', list: [] } - ], + mealSections: [], canteens: [], selectedCanteen: '', rankingDateRange: { @@ -175,6 +171,11 @@ export default { // 监听字典数据变化 this.$on('dictChange', () => { this.loadCanteens(); + this.loadMealTypes(); + // 如果菜单数据已加载,则重新分组 + if (this.menuList && this.menuList.length > 0) { + this.groupMeals(this.menuList); + } }); }, beforeUnmount() { @@ -194,6 +195,14 @@ export default { this.selectedCanteen = this.canteens[0].value; } }, + loadMealTypes() { + const mealTypeDict = this.dict.get('meal_type') || []; + this.mealSections = mealTypeDict.map(item => ({ + key: item.dictValue, + label: item.dictLabel, + list: [] + })); + }, async loadMenuByDate() { try { uni.showLoading({ title: '加载菜单中...', mask: true }); @@ -216,32 +225,46 @@ export default { } }, groupMeals(list) { - const breakfast = []; - const lunch = []; - const dinner = []; + // 重新从字典获取餐次类型,确保数据最新 + const mealTypeDict = this.dict.get('meal_type') || []; + const mealTypeMap = {}; + mealTypeDict.forEach(item => { + mealTypeMap[item.dictValue] = item.dictLabel; + }); + + // 按餐次类型分组 + const grouped = {}; list.forEach((item) => { const mealType = this.normalizeMealType(item.mealType); - if (mealType === 'breakfast') { - breakfast.push(item); - } else if (mealType === 'lunch') { - lunch.push(item); - } else if (mealType === 'dinner') { - dinner.push(item); + if (mealType && !grouped[mealType]) { + grouped[mealType] = []; + } + if (mealType) { + grouped[mealType].push(item); } }); - this.mealSections = [ - { key: 'breakfast', label: '早餐', list: breakfast }, - { key: 'lunch', label: '中餐', list: lunch }, - { key: 'dinner', label: '晚餐', list: dinner } - ]; + + // 根据字典顺序重新构建 mealSections + this.mealSections = mealTypeDict.map(item => ({ + key: item.dictValue, + label: item.dictLabel, + list: grouped[item.dictValue] || [] + })); }, normalizeMealType(type) { if (!type) return ''; const v = String(type).trim(); - if (v === '早餐' || v === '1' || v.toLowerCase() === 'breakfast') return 'breakfast'; - if (v === '中餐' || v === '午餐' || v === '2' || v.toLowerCase() === 'lunch') return 'lunch'; - if (v === '晚餐' || v === '3' || v.toLowerCase() === 'dinner') return 'dinner'; - return ''; + // 直接返回 dictValue + const mealTypeDict = this.dict.get('meal_type') || []; + for (const item of mealTypeDict) { + // 匹配 dictValue 或 dictLabel + if (String(item.dictValue).trim() === v || + String(item.dictLabel).trim() === v || + String(item.dictValue).toLowerCase() === v.toLowerCase()) { + return item.dictValue; + } + } + return v; }, async submitLike(item, likeType) { if (!item || !item.id) return;