fix: 餐别显示修改

main
wx-jincw 1 month ago
parent 2928cf997d
commit fe87d62a23

@ -143,18 +143,14 @@ import {
} from '@/api/property.js'; } from '@/api/property.js';
export default { export default {
dicts: ['canteen_name'], dicts: ['canteen_name', 'meal_type'],
data() { data() {
return { return {
selectedDate: '', selectedDate: '',
menuList: [], menuList: [],
rankingType: 'like', rankingType: 'like',
rankingList: [], rankingList: [],
mealSections: [ mealSections: [],
{ key: 'breakfast', label: '早餐', list: [] },
{ key: 'lunch', label: '中餐', list: [] },
{ key: 'dinner', label: '晚餐', list: [] }
],
canteens: [], canteens: [],
selectedCanteen: '', selectedCanteen: '',
rankingDateRange: { rankingDateRange: {
@ -175,6 +171,11 @@ export default {
// //
this.$on('dictChange', () => { this.$on('dictChange', () => {
this.loadCanteens(); this.loadCanteens();
this.loadMealTypes();
//
if (this.menuList && this.menuList.length > 0) {
this.groupMeals(this.menuList);
}
}); });
}, },
beforeUnmount() { beforeUnmount() {
@ -194,6 +195,14 @@ export default {
this.selectedCanteen = this.canteens[0].value; 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() { async loadMenuByDate() {
try { try {
uni.showLoading({ title: '加载菜单中...', mask: true }); uni.showLoading({ title: '加载菜单中...', mask: true });
@ -216,32 +225,46 @@ export default {
} }
}, },
groupMeals(list) { groupMeals(list) {
const breakfast = []; //
const lunch = []; const mealTypeDict = this.dict.get('meal_type') || [];
const dinner = []; const mealTypeMap = {};
mealTypeDict.forEach(item => {
mealTypeMap[item.dictValue] = item.dictLabel;
});
//
const grouped = {};
list.forEach((item) => { list.forEach((item) => {
const mealType = this.normalizeMealType(item.mealType); const mealType = this.normalizeMealType(item.mealType);
if (mealType === 'breakfast') { if (mealType && !grouped[mealType]) {
breakfast.push(item); grouped[mealType] = [];
} else if (mealType === 'lunch') { }
lunch.push(item); if (mealType) {
} else if (mealType === 'dinner') { grouped[mealType].push(item);
dinner.push(item);
} }
}); });
this.mealSections = [
{ key: 'breakfast', label: '早餐', list: breakfast }, // mealSections
{ key: 'lunch', label: '中餐', list: lunch }, this.mealSections = mealTypeDict.map(item => ({
{ key: 'dinner', label: '晚餐', list: dinner } key: item.dictValue,
]; label: item.dictLabel,
list: grouped[item.dictValue] || []
}));
}, },
normalizeMealType(type) { normalizeMealType(type) {
if (!type) return ''; if (!type) return '';
const v = String(type).trim(); const v = String(type).trim();
if (v === '早餐' || v === '1' || v.toLowerCase() === 'breakfast') return 'breakfast'; // dictValue
if (v === '中餐' || v === '午餐' || v === '2' || v.toLowerCase() === 'lunch') return 'lunch'; const mealTypeDict = this.dict.get('meal_type') || [];
if (v === '晚餐' || v === '3' || v.toLowerCase() === 'dinner') return 'dinner'; for (const item of mealTypeDict) {
return ''; // 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) { async submitLike(item, likeType) {
if (!item || !item.id) return; if (!item || !item.id) return;

Loading…
Cancel
Save