fix: 餐别显示修改

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

@ -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;

Loading…
Cancel
Save