<template>
    <div style="padding: 10px;background: #E5EBF6;min-height: 830px;">
        <div style="background: #FFF;padding: 10px;border-radius: 10px;margin-bottom: 20px;">
            <el-form :model="baseInfo" ref="baseInfo" :rules="baseRules" size="medium" :inline="true" label-width="80px">
                <el-form-item label="菜谱名称" prop="recipeName">
                    <el-input v-model="baseInfo.recipeName" placeholder="请输入菜谱名称" maxlength="20" clearable style="width: 300px"/>
                </el-form-item>
                <el-form-item label="所属区域" prop="areaId">
                    <el-cascader v-model="baseInfo.areaId"
                        :options="treeAreaOptions" :filterable="true" style="width: 300px" :show-all-levels="false"
                        :props="{  
                        emitPath: false,// 若设置 false，则只返回该节点的值，只返回最后选择的id
                        checkStrictly: true,//来设置父子节点取消选中关联，从而达到选择任意一级选项的目的
                        value:'id',label:'treeName'
                        }" @change="handleAreaChange">
                    </el-cascader>
                </el-form-item>
                <el-form-item label="所属食堂" prop="canteenId">
                    <el-select v-model="baseInfo.canteenId" placeholder="请选择所属食堂" style="width: 300px;" @change="handleCanteenChange">
                        <el-option v-for="item in canteenOptions"
                            :key="item.canteenId"
                            :label="item.canteenName"
                            :value="item.canteenId"
                        ></el-option>
                    </el-select> 
                </el-form-item>
                <el-form-item label="所属档口" prop="stallId">
                    <el-select v-model="baseInfo.stallId" placeholder="请选择所属档口" style="width: 300px;">
                        <el-option v-for="item in stallOptions"
                            :key="item.stallId"
                            :label="item.stallName"
                            :value="item.stallId"
                        ></el-option>
                    </el-select> 
                </el-form-item>
                <el-form-item label="菜谱类型" prop="recipeType">
                    <el-select v-model="baseInfo.recipeType" placeholder="请选择菜谱类型" style="width: 300px;" clearable @change="changeRecipeType">
                        <el-option label="指定日期" value="1"></el-option>
                        <el-option label="每日循环" value="2"></el-option>
                        <el-option label="每周循环" value="3"></el-option>
                    </el-select> 
                </el-form-item>
                <el-form-item label="用户范围" prop="effId">
                    <el-select v-model="baseInfo.effId" placeholder="请选择用户范围" style="width: 300px;" clearable>
                        <el-option v-for="item in effOptions"
                            :key="item.effId"
                            :label="item.effName"
                            :value="item.effId"
                        ></el-option>
                    </el-select> 
                </el-form-item>
                <el-row class="mb8" v-if="baseInfo.recipeType==1">
                    <el-form-item label="日期范围">
                        <el-date-picker
                            v-model="dateRange"
                            type="daterange"
                            align="right"
                            unlink-panels
                            range-separator="至"
                            start-placeholder="开始日期"
                            end-placeholder="结束日期"
                            @change="changeDateRange"
                            format="yyyy-MM-dd"
                            :picker-options="pickerOptions" >
                        </el-date-picker>
                    </el-form-item>
                </el-row>
                <el-row class="mb8" v-if="baseInfo.recipeType==1">
                        <el-col :span="1">
                            <span style="font-weight: bold;color: #606266;font-size: 14px;">日期</span>
                        </el-col>
                        <el-col :span="23">
                            <el-radio-group v-model="dateRangeRadio" @change="choseDateRadio">
                                <el-radio :label="item.applyDate" v-for="(item,index) in dateRangeList" :key="index" style="font-size: 14px;margin-bottom: 10px;">{{ item.applyDateStr }}</el-radio>
                            </el-radio-group>
                        </el-col>
                </el-row>
                <el-row class="mb8" v-if="baseInfo.recipeType==3">
                    <el-button plain v-for="(item,index) in weekDateList" :key="index" style="margin: 0;" :class="weekId==item.applyWeek?'primary':''" @click="choseWeekDate(item,index)">{{ item.weekStr }}</el-button>
                </el-row> 
            </el-form>
        </div> 
        <div style="width: 100%;height: 450px;padding: 10px;border-radius: 10px;margin-bottom: 10px;display: flex;" v-if="baseInfo.recipeType">
            <el-card class="dishes-card" v-for="item in detailList" :key="item.mealtimeType">
                <div slot="header">
                    <span>{{item.mealtimeName}}</span> 
                </div>
                <div class="body-card">
                    <span v-for="item in item.dishesList" :key="item.dishesId">{{item.dishesName}}</span>
                </div>
                <div class="bottom-card">
                    <el-button type="primary" @click="addDishes(item)" v-if="item.dishesList.length==0">新增</el-button>
                    <el-button plain type="primary" v-else @click="editDishes(item)" >修改</el-button>
                </div>
            </el-card> 
        </div>
        <div style="width: 100%;height: 80px;padding: 10px;background: #FFF;border-radius: 10px;display: flex;align-items: center;justify-content: center;">
            <el-button type="primary" @click="confirmSubmit">提 交</el-button>
            <el-button @click="jumpList">返 回</el-button>
        </div>



        <el-dialog title="选择菜品" :visible.sync="openDishes" width="90%" append-to-body>
            <div style="width: 100%;height:620px;display: flex;align-items: center;color: #000;">   
                <div class="dialog-left">
                    <div>已选菜品数量：{{dishesList.length}}</div>
                    <div>
                        <div style="font-weight: bold;margin: 10px 0;">计价方式</div>
                        <el-select v-model="queryDish.salesMode" style="width: 100%;" @change="getDishesPage">
                            <el-option label="按份" value="1" />
                            <el-option label="称重" value="2" />
                        </el-select>  
                    </div>
                    <div>
                        <div style="font-weight: bold;margin: 10px 0;">菜品分类</div>
                        <el-select v-model="queryDish.typeId" style="width: 100%;" clearable @change="getDishesPage">
                            <el-option v-for="item in typeOptions"
                                :key="item.typeId"
                                :label="item.typeName"
                                :value="item.typeId" 
                            ></el-option>
                        </el-select>
                    </div>
                    <div>
                        <div style="font-weight: bold;margin: 10px 0;">菜品名称</div>
                        <el-input  v-model="queryDish.dishesName" placeholder="请输入菜品名称" maxlength="30" clearable @input="getDishesPage"/>
                    </div>
                    <div style="margin-top: 20px;">
                        <el-card style="width: 100%;height: 360px;">
                            <div slot="header">
                                <span>菜品</span> 
                            </div>
                            <div style="width: 100%;height: 350px;overflow-y: auto;">
                                <div v-for="item in dishesPageList" :key="item.dishesId" class="dish-name" @click="chosenDishes(item)">
                                    <span v-if="item.sizeType==1">【标准】</span>
                                    <span v-if="item.sizeType==2">【大小份】</span>
                                    <span>{{ item.dishesName }}</span>
                                    <i class="el-icon-check" v-if="item.isChecked"></i>
                                </div>
                                 
                            </div>
                        </el-card> 
                    </div> 

                </div>
                <div class="dialog-center">
                    <div class="dialog-center-header">菜品分类</div>
                    <div v-for="(item,index) in dishesTypeList" :key="index" style="width: 100%;text-align: center;margin: 10px 0;">
                        <el-button plain :class="dishesType==item.typeId?'primary':''" style="width: 80%;" @click="choseDishesType(item)">{{ item.typeName }}</el-button>
                    </div> 
                </div>
                <div class="dialog-right">
                    <el-table :data="dishesTableList" height="450">
                        <el-table-column label="菜品编号" align="center" prop="dishesNum" />
                        <el-table-column label="菜品名称" align="center" prop="dishesName" />
                        <el-table-column label="所属食堂" align="center" prop="canteenName" />
                        <el-table-column label="规格" align="center" prop="sizeType">
                            <template slot-scope="scope">
                                <span v-if="scope.row.sizeType==1">标准</span>
                                <span v-if="scope.row.sizeType==2">大小份</span>
                            </template>
                        </el-table-column>
                        <el-table-column label="当餐售价" align="center" prop="price">
                            <template slot-scope="scope">
                                <el-input  v-model="scope.row.price" placeholder="请输入" maxlength="30" clearable @input="(v)=>(scope.row.price=v.replace(/[^\d.]/g,''))"/>
                            </template>
                        </el-table-column>
                        <el-table-column label="当餐优惠价" align="center" prop="salePrice">
                            <template slot-scope="scope">
                                <el-input  v-model="scope.row.salePrice" placeholder="请输入" maxlength="30" clearable @input="(v)=>(scope.row.salePrice=v.replace(/[^\d.]/g,''))"/>
                            </template>
                        </el-table-column>
                        <el-table-column label="最大供应量" align="center" prop="supplyNum">
                            <template slot-scope="scope">
                                <el-input  v-model="scope.row.supplyNum" placeholder="请输入" maxlength="30" clearable @input="(v)=>(scope.row.supplyNum=v.replace(/[^\d]/g,''))"/>
                            </template>
                        </el-table-column>
                        <el-table-column label="每人限购数" align="center" prop="restrictNum">
                            <template slot-scope="scope">
                                <el-input  v-model="scope.row.restrictNum" placeholder="请输入" maxlength="30" clearable @input="(v)=>(scope.row.restrictNum=v.replace(/[^\d]/g,''))"/>
                            </template>
                        </el-table-column>
                        <el-table-column label="移动端推荐" align="center" prop="recommendFlag">
                            <template slot-scope="scope">
                                <el-switch v-model="scope.row.recommendFlag"
                                    active-text="是" inactive-text="否"
                                    :active-value="1" :inactive-value="2">
                                </el-switch>
                            </template>
                        </el-table-column>
                        <el-table-column label="操作" align="center">
                            <template slot-scope="scope">
                                <el-button size="mini" type="text" style="color: red;"
                                @click="handleDelDishes(scope.row)" 
                                >删除</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                </div>
            </div>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="openDishes=false">确 定</el-button>
                <el-button @click="openDishes=false">取 消</el-button>
            </div>
        </el-dialog>

    </div>
</template>
  
<script>  
import { mealTimeList,systemAreaTreeApi,getCanteenByAreaApi,getStallByCanteenApi,getmkteffectiveApi,getDishesByTypePageApi,addMenuRecipeApi } from "@/api/dish/menu"; 
import { menuDishesTypeAllListApi } from "@/api/dish/dish";

export default {
    name: "MenuDetail",
    dicts: [],
    data() {
      return {
        baseInfo: { 
            recipeName:undefined,
            recipeType:undefined,
            areaId:undefined,
            canteenId:undefined,
            stallId:undefined,
            effId:undefined,
        },
        // 表单校验
        baseRules: {
            recipeName: [
                { required: true, message: "菜谱名称不能为空", trigger: "blur" }
            ],
            areaId: [
                { required: true, message: "所属区域不能为空", trigger: "change" }
            ],
            canteenId: [
                { required: true, message: "所属食堂不能为空", trigger: "change" }
            ],
            stallId: [
                { required: true, message: "所属档口不能为空", trigger: "change" }
            ],
            recipeType: [
                { required: true, message: "菜谱类型不能为空", trigger: "change" }
            ]
        },
        treeAreaOptions:[],
        canteenOptions:[],
        stallOptions:[],
        effOptions:[],
        dateRange:[new Date(),new Date().setDate(new Date().getDate() + 6)],
        dateRangeRadio:"",
        dateRangeList:[],
        pickerOptions: {
            shortcuts: [{
                text: '最近一周',
                onClick(picker) {
                const start = new Date();
                const end = new Date();
                end.setTime(start.getTime() + 3600 * 1000 * 24 * 6);
                picker.$emit('pick', [start, end]);
                }
            }, {
                text: '最近一个月',
                onClick(picker) {
                const start = new Date();
                const end = new Date();
                end.setTime(start.getTime() + 3600 * 1000 * 24 * 30);
                picker.$emit('pick', [start, end]);
                }
            }],
            disabledDate(v) {
                return v.getTime() < (new Date().getTime() - 86400000) ||v.getTime() > (new Date().getTime() + 3600 * 1000 * 24 * 60);//  - 86400000是否包括当天
            }
        },
        recipeDateList:[
            // {   //指定日期-1
            //     applyDate:"2025-03-14",
            //     detailList:[
            //         {
            //             mealtimeType:"1",
            //             mealtimeName:"早餐",
            //             dishesList:[{dishesId:"385767644524974080",dishesName:"农场山芋"}]
            //         },
            //         {
            //             mealtimeType:"2",
            //             mealtimeName:"午餐",
            //             dishesList:[{dishesId:"385767644524974080",dishesName:"农场山芋"}]
            //         },
            //         {
            //             mealtimeType:"3",
            //             mealtimeName:"下午茶",
            //             dishesList:[{dishesId:"385767644524974080",dishesName:"农场山芋"}]
            //         },
            //         {
            //             mealtimeType:"4",
            //             mealtimeName:"晚餐",
            //             dishesList:[{dishesId:"385767644524974080",dishesName:"农场山芋"}]
            //         },
            //         {
            //             mealtimeType:"5",
            //             mealtimeName:"夜宵",
            //             dishesList:[{dishesId:"385767644524974080",dishesName:"农场山芋"}]
            //         },
            //     ],  
            // },
            // {   //指定日期-1
            //     applyDate:"2025-03-15",
            //     detailList:[
            //         {
            //             mealtimeType:"1",
            //             mealtimeName:"早餐",
            //             dishesList:[{dishesId:"385767644524974080",dishesName:"农场山芋"}]
            //         },
            //         {
            //             mealtimeType:"2",
            //             mealtimeName:"午餐",
            //             dishesList:[{dishesId:"385767644524974080",dishesName:"农场山芋"}]
            //         },
            //         {
            //             mealtimeType:"3",
            //             mealtimeName:"下午茶",
            //             dishesList:[{dishesId:"385767644524974080",dishesName:"农场山芋"}]
            //         },
            //         {
            //             mealtimeType:"4",
            //             mealtimeName:"晚餐",
            //             dishesList:[{dishesId:"385767644524974080",dishesName:"农场山芋"}]
            //         },
            //         {
            //             mealtimeType:"5",
            //             mealtimeName:"夜宵",
            //             dishesList:[{dishesId:"385767644524974080",dishesName:"农场山芋"}]
            //         },
            //     ],  
            // },
            // {   //每日循环-2
            //     anyone:"repeat",
            //     detailList:[
            //         {
            //             mealtimeType:"1",
            //             mealtimeName:"早餐",
            //             dishesList:[{dishesId:"385767644524974080",dishesName:"农场山芋"}]
            //         },
            //         {
            //             mealtimeType:"2",
            //             mealtimeName:"午餐",
            //             dishesList:[{dishesId:"385767644524974080",dishesName:"农场山芋"}]
            //         },
            //         {
            //             mealtimeType:"3",
            //             mealtimeName:"下午茶",
            //             dishesList:[{dishesId:"385767644524974080",dishesName:"农场山芋"}]
            //         },
            //         {
            //             mealtimeType:"4",
            //             mealtimeName:"晚餐",
            //             dishesList:[{dishesId:"385767644524974080",dishesName:"农场山芋"}]
            //         },
            //         {
            //             mealtimeType:"5",
            //             mealtimeName:"夜宵",
            //             dishesList:[{dishesId:"385767644524974080",dishesName:"农场山芋"}]
            //         },
            //     ],  
            // },
            // {   //每周循环-3
            //     applyWeek:"1",//周一
            //     detailList:[
            //         {
            //             mealtimeType:"1",
            //             mealtimeName:"早餐",
            //             dishesList:[{dishesId:"385767644524974080",dishesName:"农场山芋"}]
            //         },
            //         {
            //             mealtimeType:"2",
            //             mealtimeName:"午餐",
            //             dishesList:[{dishesId:"385767644524974080",dishesName:"农场山芋"}]
            //         },
            //         {
            //             mealtimeType:"3",
            //             mealtimeName:"下午茶",
            //             dishesList:[{dishesId:"385767644524974080",dishesName:"农场山芋"}]
            //         },
            //         {
            //             mealtimeType:"4",
            //             mealtimeName:"晚餐",
            //             dishesList:[{dishesId:"385767644524974080",dishesName:"农场山芋"}]
            //         },
            //         {
            //             mealtimeType:"5",
            //             mealtimeName:"夜宵",
            //             dishesList:[{dishesId:"385767644524974080",dishesName:"农场山芋"}]
            //         },
            //     ],  
            // }, 
        ],
        weekDateList:[],
        weekId:'1',
        detailList:[],
        openDishes:false,
        // 查询菜品
        queryDish:{
            salesMode:null,
            typeId:null,
            dishesName:''
        },
        typeOptions:[],
        //弹窗左侧待选菜品
        dishesPageList:[],
        //弹窗中间待选菜品
        dishesTypeList:[],
        dishesType:"",
        //弹窗右侧已选菜品
        dishesTableList:[],

        dishesList:[],
      };
    },
    created() {
        this.getAreaTreeData()
        this.getmkteffective() 
        //获取菜品类型
        this.getTypeData()
    },
    methods: {
        // 返回列表页
        jumpList() {
            const obj = { path: "/dish/menuDetail" };
            this.$tab.closeOpenPage(obj);
            this.$router.replace({ path: "/dish/menu" }); // 要打开的页面 
        },
        //区域树
        getAreaTreeData() {
            systemAreaTreeApi({}).then((response) => {
                this.treeAreaOptions = response;
                if(this.treeAreaOptions.length>0){
                    this.baseInfo.areaId = this.getFirstChild(this.treeAreaOptions[0]).id;
                    this.handleAreaChange()
                }
            });
        },
        getFirstChild(node) {
            if (!node.children || node.children.length === 0) {
                return node; // 没有子节点或子节点为空，返回当前节点
            } else {
                return this.getFirstChild(node.children[0]); // 递归调用最后一个子节点
            }
        },
        //选中区域-查询食堂
        handleAreaChange(e){ 
            let param= {
                areaIdList:[this.baseInfo.areaId]
            }
            getCanteenByAreaApi(param).then((response) => {
                this.canteenOptions=response||[]
                if(this.canteenOptions.length>0){
                    this.baseInfo.canteenId = this.canteenOptions[0].canteenId;
                    this.handleCanteenChange()
                }
            });
        },
        //选中食堂-查询档口
        handleCanteenChange(e){
            let param= {
                canteenIdList:[this.baseInfo.canteenId]
            }
            getStallByCanteenApi(param).then((response) => {
                this.stallOptions=response||[]
                if(this.stallOptions.length>0){
                    this.baseInfo.stallId = this.stallOptions[0].stallId;
                }
            });
        },
        //用户范围
        getmkteffective() {
            let param = {object:{},page:{size:-1}}
            getmkteffectiveApi({"content":JSON.stringify(param)}).then((response) => {
                this.effOptions = response.data.records; 
            });
        },
        //切换菜谱类型
        changeRecipeType(e){
            console.log(this.baseInfo.recipeType)
            if(this.baseInfo.recipeType==1){//日期范围
                this.dateRangeList = this.getDateRange(this.dateRange[0],this.dateRange[1])
                this.dateRangeRadio = this.formatDate(this.dateRange[0])
                this.detailList = this.dateRangeList[0].detailList
            }
            //-----每日重复类型----
            if(this.baseInfo.recipeType==2){//每日重复
                this.detailList = [
                    {
                        mealtimeType:"1",
                        mealtimeName:"早餐",
                        dishesList:[]
                    },
                    {
                        mealtimeType:"2",
                        mealtimeName:"午餐",
                        dishesList:[]
                    },
                    {
                        mealtimeType:"3",
                        mealtimeName:"下午茶",
                        dishesList:[]
                    },
                    {
                        mealtimeType:"4",
                        mealtimeName:"晚餐",
                        dishesList:[]
                    },
                    {
                        mealtimeType:"5",
                        mealtimeName:"夜宵",
                        dishesList:[]
                    }
                ]
            }
            //-----每周重复类型----
            if(this.baseInfo.recipeType==3){//每周重复
                this.weekDateList = this.getWeekDates()
                this.weekId = '1';
                this.detailList = this.weekDateList[0].detailList;
            }
        },
        //-----指定日期类型----
        //选择日期范围
        changeDateRange(e){ 
            this.dateRangeList = this.getDateRange(this.formatDate(e[0]),this.formatDate(e[1]))
            this.dateRangeRadio = this.formatDate(e[0])
            this.detailList = this.dateRangeList[0].detailList 
        },
        //获取两日期间所有日期-构建每日菜谱数据
        getDateRange(startDate, endDate) {
            let start = new Date(startDate);
            let end = new Date(endDate);
            let dateArray = []; 
            while (start <= end) {
                //周几
				var days = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
				var dayOfWeek = start.getDay();
                let obj = {
                    applyDate:start.toISOString().split('T')[0],
                    applyDateStr:start.toISOString().split('T')[0]+" "+days[dayOfWeek],
                    detailList:[
                        {
                            mealtimeType:"1",
                            mealtimeName:"早餐",
                            dishesList:[]
                        },
                        {
                            mealtimeType:"2",
                            mealtimeName:"午餐",
                            dishesList:[]
                        },
                        {
                            mealtimeType:"3",
                            mealtimeName:"下午茶",
                            dishesList:[]
                        },
                        {
                            mealtimeType:"4",
                            mealtimeName:"晚餐",
                            dishesList:[]
                        },
                        {
                            mealtimeType:"5",
                            mealtimeName:"夜宵",
                            dishesList:[]
                        }
                    ]
                }
                dateArray.push(obj); // 转换为 YYYY-MM-DD 格式
                start.setDate(start.getDate() + 1); // 日期加 1 
            } 
            return dateArray; 
        },
        //切换日期菜谱
        choseDateRadio(e){
            let index = this.dateRangeList.findIndex(v=>v.applyDate==this.dateRangeRadio) 
            this.detailList = this.dateRangeList[index].detailList
        },
        // ----每周重复-----
        getWeekDates() { 
			let weekDates = []; 
			for (let i = 0; i < 7; i++) { 
				//周几
				var days = ['星期一', '星期二', '星期三', '星期四', '星期五', '星期六','星期日']; 
				//对象
				let obj = {
                    applyWeek:i+1,
                    weekStr:days[i],
                    detailList:[
                        {
                            mealtimeType:"1",
                            mealtimeName:"早餐",
                            dishesList:[]
                        },
                        {
                            mealtimeType:"2",
                            mealtimeName:"午餐",
                            dishesList:[]
                        },
                        {
                            mealtimeType:"3",
                            mealtimeName:"下午茶",
                            dishesList:[]
                        },
                        {
                            mealtimeType:"4",
                            mealtimeName:"晚餐",
                            dishesList:[]
                        },
                        {
                            mealtimeType:"5",
                            mealtimeName:"夜宵",
                            dishesList:[]
                        }
                    ]
				}
				weekDates.push(obj);  
			} 
			return weekDates;
		},
        choseWeekDate(item,index){
            this.weekId = item.applyWeek;
            this.detailList = this.weekDateList[index].detailList;
        },

        
        /** 查询新增页面-菜品类型下拉 */
        getTypeData() {
            menuDishesTypeAllListApi({}).then((response) => {
                this.typeOptions = response.data; 
            });
        },
        //新增
        addDishes(item){ 
            this.dishesList=item.dishesList; 
            this.dishesTypeList=[]
            this.dishesTableList=[]
            this.getDishesPage()
            this.openDishes=true
        },
        //修改
        editDishes(item){
            console.log(item)
            this.dishesList=item.dishesList; 
            this.dishesTypeList=[]
            this.dishesList.forEach(dish=>{
                let index = this.dishesTypeList.findIndex(v=>v.typeId==dish.typeId)
                if(index==-1){
                    this.dishesTypeList.push({typeId:dish.typeId,typeName:dish.typeName})
                }
            })
            console.log(this.dishesTypeList) 
            this.choseDishesType(this.dishesTypeList[0])
            this.getDishesPage()
            this.openDishes=true
        },
        //获取左侧待选菜品
        getDishesPage(){
            let param = {
                "areaId":this.baseInfo.areaId,
                "canteenId":this.baseInfo.canteenId,
                "stallId":this.baseInfo.stallId,
                "salesMode":this.queryDish.salesMode,
                "typeId":this.queryDish.typeId,
                "dishesName":this.queryDish.dishesName, 
                "current":1,
                "size":100
            }
            getDishesByTypePageApi(param).then((response) => {
                console.log(response)
                this.dishesPageList = response.data.records;
                for(let i =0 ;i < this.dishesList.length ;i++){
                    this.dishesPageList.forEach(item=>{
                        if(item.dishesId==this.dishesList[i].dishesId){
                            item.isChecked=true
                        }
                    })
                }
            });
        },
        //点击左侧待选菜品
        chosenDishes(obj){
            console.log(obj) 
            obj.salePrice=0;
            obj.supplyNum=999;
            obj.restrictNum=999;
            //判断是否为新菜品类型
            let index = this.dishesList.findIndex(v=>v.dishesId==obj.dishesId)
            if(index==-1){
                this.dishesList.push(obj)
                //反显选中样式
                this.dishesPageList.forEach(item=>{
                    if(obj.dishesId==item.dishesId){
                        item.isChecked = true;
                    }
                })
            }else{
                this.dishesList.splice(index,1)
                //反显选中样式
                this.dishesPageList.forEach(item=>{
                    if(obj.dishesId==item.dishesId){
                        item.isChecked = null;
                    }
                })
            } 
            //判断是否为新菜品类型
            let index2 = this.dishesTypeList.findIndex(v=>v.typeId==obj.typeId)
            if(index2==-1){
                this.dishesTypeList.push({typeId:obj.typeId,typeName:obj.typeName})
            }
            //选中类型
            this.choseDishesType(obj)
        },
        //选中菜品类型-更新右侧表格数据
        choseDishesType(item){
            console.log(item)
            this.dishesType = item.typeId;
            this.dishesTableList = []
            this.dishesList.forEach(dish=>{
                if(dish.typeId==item.typeId){
                    this.dishesTableList.push(dish)
                }
            })
            console.log(this.dishesTableList)
        },
        handleDelDishes(item){
            let index = this.dishesList.findIndex(v=>v.dishesId==item.dishesId) 
            if(index>-1){
                this.dishesList.splice(index,1)
                let index2 = this.dishesTableList.findIndex(v=>v.dishesId==item.dishesId) 
                this.dishesTableList.splice(index2,1)
                this.dishesPageList.forEach(dish=>{
                    if(dish.dishesId==item.dishesId){
                        dish.isChecked = null;
                    }
                })
            }
        },

        

        // 提交按钮
        confirmSubmit(){
            console.log(this.baseInfo)
            let param = this.baseInfo
            if(this.baseInfo.recipeType==1){
                console.log(this.dateRangeList)
                param.recipeDateList = this.dateRangeList
            }
            if(this.baseInfo.recipeType==2){ 
                param.recipeDateList = [{
                    anyone:"repeat",
                    detailList:this.detailList
                }]
            }
            if(this.baseInfo.recipeType==3){
                console.log(this.weekDateList)
                param.recipeDateList = this.weekDateList
            }
            console.log(param)
            addMenuRecipeApi(param).then((response) => {  
                this.jumpList() 
            });
        },
        //日期
        formatDate(date) {
            // 格式化为 YYYY-MM-DD
            const year = date.getFullYear();
            const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从0开始
            const day = String(date.getDate()).padStart(2, '0');
            return `${year}-${month}-${day}`;
        } 
    }
};
</script>
<style scoped>
    .dishes-card{
        width: 20%;
        height: 100%;
        margin-right: 15px;
        position: relative;
    }
    .body-card{
        width: 96%;
        margin: 10px auto;
        display: flex;
        flex-direction: column;
    }

    .bottom-card{
        width: 100%;
        height: 60px;
        display: flex;
        align-items: center;
        justify-content: center;
        position: absolute;
        bottom: 0;
    }


    .dialog-left{
        width: 20%;
        height: 100%;
    }
    .dish-name{
        width: 100%;
        height: 32px;
        display: flex;
        align-items: center;
        cursor: pointer;
    }
    .dish-name:hover{ 
        background-color:rgba(0, 0, 0, 0.1);
        color: #4b80fd;
    } 

    .dialog-center{
        width: 10%;
        height: 100%;
        /* background: #4b80fd; */
        border: 1px solid #ccc;
        border-radius: 5px;
        margin: 0 1%;
    }
    .dialog-center-header{
        width: 100%;display: flex;align-items: center;justify-content: center;height: 60px;font-weight: bold;border-bottom: 1px solid #ccc;
    }
    .dialog-right{
        width: 70%;
        height: 100%;
    }
    .primary{
        background: #1890ff!important;
        color: #fff!important;
    }

</style>




  