Dining_Hall/pages/weeklyMenu/menuList.vue

282 lines
7.3 KiB
Vue
Raw Normal View History

2025-02-19 09:34:34 +08:00
<template>
<page-meta :page-font-size="fontValue+'px'" :root-font-size="fontValue+'px'"></page-meta>
2025-02-19 09:34:34 +08:00
<view>
2025-05-12 09:22:02 +08:00
<Navbar title="周菜谱" :showRightText="true" :isBack="false" :text="'历史菜谱'" @clickIcon="handleRightText" />
<scroll-view class="date-view" scroll-x="true">
2025-02-19 09:34:34 +08:00
<view class="scroll-view-item" v-for="(item,index) in daysList" :key="index" :class="hIndex == index ? 'active' : ''" @click="changeDay(index)">
<view style="width: 100%;display: flex;flex-direction: column;align-items: center;">
<view>{{item.dateValue}}</view>
<view>{{item.weekValue}}</view>
<view class="activeLine" v-if="hIndex == index"></view>
</view>
</view>
</scroll-view>
2025-05-12 09:22:02 +08:00
<view class="tab-navigation" v-show="tabList.length>0">
2025-04-14 17:39:27 +08:00
<Tabs ref="Tabs" :tabList="tabList" @changeTab="changeTab" />
2025-02-19 09:34:34 +08:00
</view>
2025-05-12 09:22:02 +08:00
<view class="menuContent" v-if="menuData.length>0">
2025-02-19 09:34:34 +08:00
<scroll-view class="content-left" scroll-y="true">
2025-03-14 15:15:54 +08:00
<view class="scroll-view-item" v-for="(item,index) in typeList" :key="index" :class="tIndex == index ? 'active2' : ''" @click="changeModel(item,index)">
2025-02-19 09:34:34 +08:00
<view style="width: 100%;display: flex;flex-direction: column;align-items: center;">
2025-03-14 15:15:54 +08:00
<view>{{item.typeName}}</view>
2025-02-19 09:34:34 +08:00
</view>
</view>
</scroll-view>
2025-03-14 15:15:54 +08:00
<scroll-view class="content-right" scroll-y="true" :scroll-top="scrollLeftTop" scroll-with-animation="true">
<view v-for="(typeitem,typeindex) in typeList" :key="typeindex">
<view :id="'scroll'+typeitem.typeId" style="margin: 20rpx 10rpx;font-weight: bold;font-size: 28rpx;">{{typeitem.typeName}}</view>
2025-03-14 15:15:54 +08:00
<view class="scroll-right-item" v-for="(item,index) in typeitem.dishesList" :key="index" @click="goMenuList(item)">
<view style="width: 100%;display: flex;align-items: center;">
<view style="width: 26%;height: 100%;">
2025-03-14 15:15:54 +08:00
<image class="image" :src="item.dishesImgUrl"></image>
</view>
<view style="width: 70%;height: 100%;padding-left: 20px;">
<view>{{item.dishesDetailList[0].dishesName}}</view>
2025-03-14 15:15:54 +08:00
<view>食堂{{item.canteenName}}</view>
<view>档口{{item.stallName}}</view>
2025-04-14 17:39:27 +08:00
<view style="color: #DD7D3C;">{{(item.dishesDetailList[0].prefPrice/100).toFixed(2)}}</view>
2025-03-14 15:15:54 +08:00
</view>
2025-02-19 09:34:34 +08:00
</view>
</view>
</view>
2025-05-12 09:22:02 +08:00
</scroll-view>
2025-02-19 09:34:34 +08:00
</view>
2025-05-12 09:22:02 +08:00
<view v-if="menuData.length==0" class="flex justify-center align-center" style="height: 50vh" >
<u-empty icon="../../static/images/not_order.png" text="暂无数据" textColor="#000" />
</view>
2025-02-19 09:34:34 +08:00
</view>
</template>
<script>
import { getWeekDetailListAPI } from '../../api/week-menu/index'
import Tabs from '@/pages/components/Tabs.vue'
2025-04-27 15:58:51 +08:00
2025-02-19 09:34:34 +08:00
export default {
components: { Tabs },
data() {
return {
2025-04-27 15:58:51 +08:00
fontValue:uni.getStorageSync('fontSize') || 8,
2025-02-19 09:34:34 +08:00
daysList:[],//日期列表
hIndex:0,//日期选中index
recipeId:"",//菜谱ID
menuData:[],//菜谱列表数据
tabList: [],//菜品类型名称
typeList:[],//菜品类型数据
typeNameList:[],
tIndex:0,
2025-03-14 15:15:54 +08:00
scrollLeftTop:0,//滚动位置
2025-02-19 09:34:34 +08:00
}
},
onLoad(options) {
console.log(options)
options = JSON.parse(options.params)
this.recipeId=options.recipeId;
this.daysList = this.getRecentWeekDates()
this.getMenuListData()
},
methods: {
2025-05-12 09:22:02 +08:00
//跳转历史记录
handleRightText() {
console.log('?? ~ handleRightText ~ ')
let item = {
recipeId:this.recipeId
}
uni.navigateTo({
url: `/pages/weeklyMenu/menuHistory?params=${JSON.stringify(item)}`
})
},
2025-02-19 09:34:34 +08:00
getRecentWeekDates() {
let currentDate = new Date(); // 获取当前日期
let weekDates = [];
for (let i = 0; i < 7; i++) {
let day = currentDate.getDate();
let month = currentDate.getMonth() + 1; // 月份是从0开始计数的所以要+1
let year = currentDate.getFullYear();
//日期
let formattedDate = `${month < 10 ? '0' + month : month}-${day < 10 ? '0' + day : day}`;
let formattedDate2 = `${year}-${month < 10 ? '0' + month : month}-${day < 10 ? '0' + day : day}`;
//周几
var days = ['周日', '周一', '周二', '周三', '周四', '周五', '周六'];
var dayOfWeek = currentDate.getDay();
//对象
let obj = {
"data":formattedDate2,
"dateValue":formattedDate,
"weekValue":days[dayOfWeek]
}
weekDates.push(obj);
currentDate.setDate(currentDate.getDate() + 1); // 获取前一天的日期
}
return weekDates;
},
// 获取菜谱
async getMenuListData() {
let param = {
"recipeId":this.recipeId,
2025-05-12 09:22:02 +08:00
"date":this.daysList[this.hIndex].data
2025-02-19 09:34:34 +08:00
}
const res = await getWeekDetailListAPI(param)
console.log(res, '周菜谱')
if(res.code==200){
if(res.rows&&res.rows.length>0){
this.menuData = res.rows;
2025-04-14 17:39:27 +08:00
this.tabList=[]
2025-02-19 09:34:34 +08:00
//处理数据
this.menuData.forEach(item=>{//渲染类型
this.tabList.push(item.mealtimeName)
})
2025-04-14 17:39:27 +08:00
this.$refs.Tabs.handleTab(0)
// this.changeTab(0)
2025-02-19 09:34:34 +08:00
}else{
this.menuData = [];
this.tabList=[];
this.typeList=[]
this.typeNameList=[]
2025-03-14 15:15:54 +08:00
this.tIndex=0
2025-02-19 09:34:34 +08:00
}
}else{
uni.$u.toast(res.msg)
this.menuData = [];
this.tabList=[];
this.typeList=[]
this.typeNameList=[]
2025-03-14 15:15:54 +08:00
this.tIndex=0
2025-02-19 09:34:34 +08:00
}
},
//改变时间
changeDay(index){
this.hIndex=index;
this.getMenuListData()
},
//菜品类型1-早餐 2-午餐 3-下午茶 4-晚餐 5-夜宵)
changeTab(index) {
this.typeList = this.menuData[index].typeList;
//左侧类别列表
this.typeNameList=[]
this.typeList.forEach(item=>{
this.typeNameList.push(item.typeName)
})
//右侧菜列表
2025-03-14 15:15:54 +08:00
this.tIndex=0;
2025-02-19 09:34:34 +08:00
},
//菜品类型(面点,粗粮,精品菜,卤菜...
2025-03-14 15:15:54 +08:00
changeModel(item,index){
2025-02-19 09:34:34 +08:00
this.tIndex=index
2025-03-14 15:15:54 +08:00
var len = 0
if(index==0){
len=0
}else{
this.typeList.forEach((ite,i)=>{
console.log(i)
console.log(index)
if(i<index){
len = len+ite.dishesList.length
}
})
}
setTimeout(()=>{
uni.createSelectorQuery().in(this).select('#scroll'+item.typeId).boundingClientRect(res => {
console.log(res)
this.scrollLeftTop = 80 * len; // 设置滚动条距离左侧的距离
}).exec()
},100)
// this.dishesList = this.typeList[index].dishesList;
2025-02-19 09:34:34 +08:00
},
goMenuList(item){
uni.navigateTo({
url: `/pages/weeklyMenu/menuDetail?params=${JSON.stringify(item)}`
})
}
}
}
</script>
<style lang="scss" scoped>
page {
display: flex;
flex-direction: column;
box-sizing: border-box;
background-color: #fff;
2025-05-12 09:22:02 +08:00
height: 90vh;
2025-02-19 09:34:34 +08:00
}
2025-05-12 09:22:02 +08:00
.date-view {
2025-02-19 09:34:34 +08:00
white-space: nowrap;
width: 100%;
2025-05-12 09:22:02 +08:00
2025-02-19 09:34:34 +08:00
}
.scroll-view-item {
display: inline-block;
width: 160rpx;
height: 100rpx;
// line-height: 100rpx;
text-align: center;
color: #959FA4;
font-size: 24rpx;
2025-02-19 09:34:34 +08:00
.activeLine{
background: #DD7D3C;
border-radius: 10upx;
width: 100rpx;
height: 6upx;
}
}
.active {
color: #DD7D3C;
font-weight: bolder;
font-size: 28rpx;
2025-02-19 09:34:34 +08:00
}
.tab-navigation {
display: flex;
background-color: white;
padding: 0px 16px 0 16px;
}
.menuContent{
width: 100%;
display: flex;
2025-05-12 09:22:02 +08:00
height: 80vh;
2025-04-14 17:39:27 +08:00
// background-color: #ff6816;
2025-02-19 09:34:34 +08:00
}
.content-left{
width: 20%;
2025-05-12 09:22:02 +08:00
height: 80vh;
2025-02-19 09:34:34 +08:00
}
.active2 {
color: #DD7D3C;
font-weight: bolder;
font-size: 26rpx;
}
.content-right{
width: 80%;
2025-05-12 09:22:02 +08:00
height: 80vh;
2025-02-19 09:34:34 +08:00
}
.scroll-right-item{
width: 100%;
2025-02-21 10:03:35 +08:00
height: auto;
font-size: 28rpx;
2025-02-19 09:34:34 +08:00
// background-color: #959FA4;
}
.image {
width: 150rpx;
height: 150rpx;
2025-02-19 09:34:34 +08:00
border-radius: 10rpx;
margin: 20rpx;
}
</style>