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