new Vue({
    el: '#all',
    data: function () {
        return {
            widthRight: 30,
            showFixedStatus: false,
            searchInput: "",
            titles: "",//标题
            twoTitles: "",//二级标题
            isshowData: false,//是否显示有数据
            weekly: 0,//周次
            termname: "",//学期名称
            templateGuid: "",//创建模板id
            selectGuid: "",//选择的id           
            token: "",
            url: utils.kindergartenUrl + "/",
            url1: "http://192.168.1.112:50011/api",
            navFood: [
                {
                    id: 1,
                    name: "菜名",
                    className: 'in',
                    status: true
                }, {
                    id: 2,
                    name: "原料",
                    className: '',
                    status: false
                }
            ],
            week: [
                {
                    id: 1,
                    name: "周一",
                    className: 'in',
                    status: true
                }, {
                    id: 2,
                    name: "周二",
                    className: '',
                    status: false
                }, {
                    id: 3,
                    name: "周三",
                    className: '',
                    status: false
                }, {
                    id: 4,
                    name: "周四",
                    className: '',
                    status: false
                }, {
                    id: 5,
                    name: "周五",
                    className: '',
                    status: false
                },
                {
                    id: 6,
                    name: "全周",
                    className: '',
                    status: false
                }
            ],
            tableData: [
                {
                    id: 1,
                    bgStyle: false,
                    delShow: false,
                    type: "早餐",
                    dataFood: [
                        {
                            id: 1,
                            value: "牛奶",
                            number: 200,
                            bgStyle: false,
                            delShow: false,
                            data: [
                                {
                                    name: '鲜牛奶',
                                    delShow: false,
                                    number: 194
                                },
                                {
                                    name: '白糖',
                                    delShow: false,
                                    number: 6
                                },
                            ]
                        },
                        {
                            id: 2,
                            value: "面包",
                            number: 200,
                            bgStyle: false,
                            delShow: false,
                            data: [
                                {
                                    name: '面包',
                                    delShow: false,
                                    number: 200
                                },
                            ]
                        },
                        {
                            id: 3,
                            value: "鸡蛋",
                            number: 200,
                            bgStyle: false,
                            delShow: false,
                            data: [
                                {
                                    name: '鸡蛋',
                                    delShow: false,
                                    number: 194
                                },
                                {
                                    name: '油',
                                    delShow: false,
                                    number: 6
                                },
                            ]
                        },
                    ]
                },
                {
                    id: 2,
                    bgStyle: false,
                    type: "早点",
                    delShow: false,
                    dataFood: [
                        {
                            id: 1,
                            value: "牛奶",
                            number: 200,
                            bgStyle: false,
                            delShow: false,
                            data: [
                                {
                                    name: '鲜牛奶',
                                    delShow: false,
                                    number: 194
                                },
                                {
                                    name: '白糖',
                                    delShow: false,
                                    number: 6
                                },
                            ]
                        },
                        {
                            id: 2,
                            value: "面包",
                            number: 200,
                            bgStyle: false,
                            delShow: false,
                            data: [
                                {
                                    name: '面包',
                                    delShow: false,
                                    number: 200
                                },
                            ]
                        },
                    ]
                },
                {
                    id: 3,
                    bgStyle: false,
                    delShow: false,
                    type: "午餐",
                    dataFood: [
                        {
                            id: 1,
                            value: "牛奶",
                            number: 200,
                            bgStyle: false,
                            delShow: false,
                            data: [
                                {
                                    name: '鲜牛奶',
                                    delShow: false,
                                    number: 194
                                },
                                {
                                    name: '白糖',
                                    delShow: false,
                                    number: 6
                                },
                            ]
                        },
                        {
                            id: 2,
                            value: "面包",
                            number: 200,
                            bgStyle: false,
                            delShow: false,
                            data: [
                                {
                                    name: '面包',
                                    delShow: false,
                                    number: 200
                                },
                            ]
                        },
                    ]
                },
                {
                    id: 4,
                    bgStyle: false,
                    delShow: false,
                    type: "午点",
                    dataFood: [
                        {
                            id: 1,
                            value: "牛奶",
                            number: 200,
                            bgStyle: false,
                            delShow: false,
                            data: [
                                {
                                    name: '鲜牛奶',
                                    delShow: false,
                                    number: 194
                                },
                                {
                                    name: '白糖',
                                    delShow: false,
                                    number: 6
                                },
                            ]
                        },
                    ]
                },
                {
                    id: 5,
                    bgStyle: false,
                    delShow: false,
                    type: "晚餐",
                    dataFood: [
                        {
                            id: 1,
                            value: "牛奶",
                            number: 200,
                            bgStyle: false,
                            delShow: false,
                            data: [
                                {
                                    name: '鲜牛奶',
                                    delShow: false,
                                    number: 194
                                },
                                {
                                    name: '白糖',
                                    delShow: false,
                                    number: 6
                                },
                            ]
                        },
                    ]
                },
            ],
            type: 1,// 1菜谱 2食材
            weekType: 1,// 周星期次
            navFoodData: [
                {
                    id: 1,
                    title: "面食",
                    showData: false,
                    data: [
                        {
                            id: 1,
                            name: "红烧牛肉面"
                        },
                        {
                            id: 2,
                            name: "酸菜肉丝面"
                        },
                        {
                            id: 3,
                            name: "香菇鸡汤面"
                        },
                        {
                            id: 4,
                            name: "杂酱面"
                        },
                    ]
                },
                {
                    id: 2,
                    title: "糕点",
                    showData: false,
                    data: [
                        {
                            id: 1,
                            name: "南瓜饼"
                        },
                        {
                            id: 2,
                            name: "腰果"
                        },
                        {
                            id: 3,
                            name: "草莓蛋糕"
                        },
                        {
                            id: 4,
                            name: "芝麻酥"
                        },
                    ]
                },
                {
                    id: 3,
                    title: "主食",
                    showData: false,
                    data: [
                        {
                            id: 1,
                            name: "香米饭"
                        },
                        {
                            id: 2,
                            name: "玉米"
                        },
                        {
                            id: 3,
                            name: "糯米"
                        },
                        {
                            id: 4,
                            name: "薏米"
                        },
                    ]
                },
                {
                    id: 4,
                    title: "凉菜",
                    showData: false,
                    data: [
                        {
                            id: 1,
                            name: "香米饭"
                        },
                        {
                            id: 2,
                            name: "玉米"
                        },
                        {
                            id: 3,
                            name: "糯米"
                        },
                        {
                            id: 4,
                            name: "薏米"
                        },
                    ]
                },
                {
                    id: 5,
                    title: "水果",
                    showData: false,
                    data: [
                        {
                            id: 1,
                            name: "香米饭"
                        },
                        {
                            id: 2,
                            name: "玉米"
                        },
                        {
                            id: 3,
                            name: "糯米"
                        },
                        {
                            id: 4,
                            name: "薏米"
                        },
                    ]
                },
                {
                    id: 6,
                    title: "饮料",
                    showData: false,
                    data: [
                        {
                            id: 1,
                            name: "香米饭"
                        },
                        {
                            id: 2,
                            name: "玉米"
                        },
                        {
                            id: 3,
                            name: "糯米"
                        },
                        {
                            id: 4,
                            name: "薏米"
                        },
                    ]
                },
            ],
            rightData: [
                {
                    id: 1,
                    bgStyle: false,
                    type: "能量",//营养素
                    baseNumber: 1426.89,//标准量
                    eatIn: 1823.45,//摄入量
                    percentage: '127.79%',//百分比
                    judge: "充裕"//评价
                },
                {
                    id: 2,
                    bgStyle: false,
                    type: "蛋白质",
                    baseNumber: 34.94,
                    eatIn: 86.68,
                    percentage: '248.08%',
                    judge: "超标"
                },
                {
                    id: 3,
                    bgStyle: false,
                    type: "钙",
                    baseNumber: 792.47,
                    eatIn: 593.04,
                    percentage: '74.83%',
                    judge: "低下"
                },
                {
                    id: 4,
                    bgStyle: false,
                    type: "碳水化物",
                    baseNumber: 120.0,
                    eatIn: 224.12,
                    percentage: '186.77%',
                    judge: "充裕"
                },
                {
                    id: 5,
                    bgStyle: false,
                    type: "维生素A",
                    baseNumber: 310.0,
                    eatIn: 530.49,
                    percentage: '171.13%',
                    judge: "充裕"
                },
            ],
            fixedHeadChange: [
                {
                    name: "评价规则",
                    className: "in",
                },
                {
                    name: "计算逻辑",
                    className: "",
                }
            ],
            fixedHeadName: "评价规则",
            flexTableData: [
                {
                    rowSpanName: "能量",//类别
                    rowSpanData: [
                        {
                            value1: "能量",//营养素/评价
                            value2: "<85",//低下
                            value3: "85~100",//正常
                            value4: "100~200",//充裕
                            value5: ">200"//超出

                        }
                    ]
                },
                {
                    rowSpanName: "产能营养素",
                    rowSpanData: [
                        {
                            value1: "蛋白质",
                            value2: "<80",
                            value3: "80~110",
                            value4: "110~200",
                            value5: ">200"
                        },
                        {
                            value1: "脂肪",
                            value2: "<80",
                            value3: "80~100",
                            value4: "100~200",
                            value5: ">200"
                        },
                        {
                            value1: "碳水化合物",
                            value2: "<80",
                            value3: "80~100",
                            value4: "100~200",
                            value5: ">200"
                        }
                    ]
                },
                {
                    rowSpanName: "脂溶性维生素[1]",
                    rowSpanData: [
                        {
                            value1: "维生素A",
                            value2: "<80",
                            value3: "80~100",
                            value4: "100~340",
                            value5: ">340"
                        },
                        {
                            value1: "维生素E",
                            value2: "<80",
                            value3: "80~100",
                            value4: "100~450",
                            value5: ">450"
                        }
                    ]
                },
                {
                    rowSpanName: "水溶性维生素[2]",
                    rowSpanData: [
                        {
                            value1: "维生素B1",
                            value2: "<80",
                            value3: "80~100",
                            value4: "100~480",
                            value5: ">480"
                        },
                        {
                            value1: "维生素B2",
                            value2: "<80",
                            value3: "80~100",
                            value4: "100~480",
                            value5: ">480"
                        },
                        {
                            value1: "维生素B3",
                            value2: "<80",
                            value3: "80~100",
                            value4: "100~480",
                            value5: ">480"
                        },
                        {
                            value1: "维生素C",
                            value2: "<80",
                            value3: "80~100",
                            value4: "100~480",
                            value5: ">480"
                        }
                    ]
                },
                {
                    rowSpanName: "常量元素",
                    rowSpanData: [
                        {
                            value1: "	钙",
                            value2: "<80",
                            value3: "80~100",
                            value4: "100~250",
                            value5: ">250"
                        }
                    ]
                },
                {
                    rowSpanName: "微量元素",
                    rowSpanData: [
                        {
                            value1: "铁",
                            value2: "<80",
                            value3: "80~100",
                            value4: "100~300",
                            value5: ">300"
                        },
                        {
                            value1: "锌",
                            value2: "<80",
                            value3: "80~100",
                            value4: "100~230",
                            value5: ">230"
                        },
                        {
                            value1: "硒",
                            value2: "<80",
                            value3: "80~100",
                            value4: "100~740",
                            value5: ">740"
                        }
                    ]
                }
            ],
            choose: {},
            selectItem:"-1",
            selectItems: [
                { id: 11, name: '推荐食谱名称' }               
            ]
        }
    },
    mounted() {
        this.token = sessionStorage.getItem("token"); //与API交互     
        //班级运行情况
        this.changeWindow();      

        //加载基础数据
        this.termname = this.getUrlParam("tmer");//学期名称
        this.weekly = this.getUrlParam("week");//周次
        this.titles = this.termname;
        this.twoTitles = "第" + this.weekly + "周";
        //选择推荐菜
        this.GetselectCreateARecipe();
        //获取周菜数
        this.getBaseCInfo(1);       
    },
    methods: {
        selectFn(e) {
        //console.log(e)
            //console.log(e.target.selectedIndex)// 选择项的index索引
            console.log(e.target.value)// 选择项的value
            var values = e.target.value;
            if (values != "-1")
                this.AddSelectSpData(e.target.value);
        }, async AddSelectSpData(cjGUid) {
            console.log(this.tempname);
            let data = await this.request({
                type: "GET",
                url: `${this.url}api/kindergarten/Recipes_Pc/AddSelectSpData`,
                data: {
                    cjGUid: cjGUid,
                    tempname: this.termname,
                    weekly: this.weekly
                }
            })
            if (!data.iserror) {
                //获取周菜数
                this.getBaseCInfo(1);       
            }
        },
        // 请求数据
        request({
            type,
            url,
            data = {},
            headers = {
                'content-type': 'application/json',
                'Authorization': "Bearer " + this.token,
            }
        }) {
            return new Promise(resolve => {
                $.ajax({
                    type,
                    url,
                    data,
                    headers,
                    success(data) {
                        resolve(data);
                    }
                });
            });
        },
        changeWindow() {
            window.onresize = function () {
                setTimeout(function () {
                    window.location.reload();
                }, 200)
            }
        },
        // 菜谱食材的转化
        getFoodData(item) {
            if (!item.status) {
                this.type = item.id
                for (let i = 0; i < this.navFood.length; i++) {
                    if (item.id == this.navFood[i].id) {
                        this.navFood[i].className = "in"
                        this.navFood[i].status = true
                    } else {
                        this.navFood[i].className = ""
                        this.navFood[i].status = false
                    }
                }
                this.getDataFoodTable1("");
            }
        },
        // 修改周次数据的变化
        getWeekData(item) {
            if (!item.status) {
                this.weekType = item.id
                for (let i = 0; i < this.week.length; i++) {
                    if (item.id == this.week[i].id) {
                        this.week[i].className = "in"
                        this.week[i].status = true
                    } else {
                        this.week[i].className = ""
                        this.week[i].status = false
                    }
                }
                if (item.name !='全周'){
                    this.getDataTable1(item.name)
                }
                this.getDataTable2(item.name)
            }
        },
        // 前端用的不用管
        changeStatus(item) {
            for (let i = 0; i < this.navFoodData.length; i++) {
                if (item.id == this.navFoodData[i].id) {
                    this.navFoodData[i].showData = !this.navFoodData[i].showData
                }
            }

        },
        showFixed(status1){
            this.showFixedStatus = status1
        },
        // 改变右边的宽度
        changeWidth(){
            if (this.widthRight>=30){
                this.widthRight = 1
            }else{
                this.widthRight = 30
            }
        },
        changeFixedHeadChange(item){
            if (this.fixedHeadName != item.name){
                this.fixedHeadName = item.name
                for(let i= 0;i<this.fixedHeadChange.length;i++){
                    if(this.fixedHeadChange[i].name == item.name){
                        this.fixedHeadChange[i].className ="in"
                    }else{
                        this.fixedHeadChange[i].className =""
                    }
                }
            }
            
        },
        // 拖拽入目标
        test(itemn,indexn,item1,index1) {
            // console.log(itemn,indexn,item1,index1)
            if (item1!==undefined && index1!==undefined){
                for (let i = 0; i < this.tableData.length; i++) {
                    if (itemn.id == this.tableData[i].id) {
                        if (this.tableData[i].dataFood!=[] && this.tableData[i].dataFood[indexn] != null) {
                            this.tableData[i].dataFood[indexn].bgStyle = true
                        }
                        // this.tableData[i].dataFood[ele].delShow = true
                    }
                }
            }else{
                for (let i = 0; i < this.tableData.length; i++) {
                    if (itemn.id == this.tableData[i].id) {
                        this.tableData[i].bgStyle = true
                        // this.tableData[i].delShow = true
                        for (let j = 0; j < this.tableData[i].dataFood.length; j++){
                            if (this.tableData[i].dataFood != [] && this.tableData[i].dataFood[j] != null) {
                                this.tableData[i].dataFood[j].bgStyle = true
                            }
                        }
                    }
                }
            }
        },
        // 拖拽出目标
        test1(itemn,indexn,item1,index1) {
            // console.log(item,2)
            if (item1!==undefined && index1!==undefined){
                for (let i = 0; i < this.tableData.length; i++) {
                    if (itemn.id == this.tableData[i].id) {
                        if (this.tableData[i].dataFood != [] && this.tableData[i].dataFood[indexn] != null) {
                            this.tableData[i].dataFood[indexn].bgStyle = false
                        }
                        // this.tableData[i].dataFood[ele].delShow = false
                    }
                }
            }else{
                for (let i = 0; i < this.tableData.length; i++) {
                    if (itemn.id == this.tableData[i].id) {
                        this.tableData[i].bgStyle = false
                        // this.tableData[i].delShow = false
                        for (let j = 0; j < this.tableData[i].dataFood.length; j++){
                            if (this.tableData[i].dataFood != [] && this.tableData[i].dataFood[j] != null) {
                                this.tableData[i].dataFood[j].bgStyle = false
                            }
                        }
                    }
                }
            }
        },
        // 鼠标移入
        mouseenter(itemn,indexn,item1,index1){
            // console.log(itemn,indexn,item1,index1)
            if(item1!==undefined && index1!==undefined){
                for (let i = 0; i < this.tableData.length; i++) {
                    if (itemn.id == this.tableData[i].id) {
                        if (this.tableData[i].dataFood != [] && this.tableData[i].dataFood[indexn] != null) {
                            this.tableData[i].dataFood[indexn].bgStyle = true
                            this.tableData[i].dataFood[indexn].data[index1].delShow = true
                        }
                    }
                }
            }else{
                for (let i = 0; i < this.tableData.length; i++) {
                    if (itemn.id == this.tableData[i].id) {
                        this.tableData[i].bgStyle = true
                        if (this.tableData[i].dataFood != [] && this.tableData[i].dataFood[indexn] != null) {
                            this.tableData[i].dataFood[indexn].delShow = true
                        }
                    }
                }
            }
            
        },
        // 鼠标移开
        mouseleave(itemn,indexn,item1,index1){
            if(item1!==undefined && index1!==undefined){
                for (let i = 0; i < this.tableData.length; i++) {
                    if (itemn.id == this.tableData[i].id) {
                        if (this.tableData[i].dataFood != [] && this.tableData[i].dataFood[indexn] != null) {
                            this.tableData[i].dataFood[indexn].bgStyle = false
                            this.tableData[i].dataFood[indexn].data[index1].delShow = false
                        }
                    }
                }
            }else{
                for (let i = 0; i < this.tableData.length; i++) {
                    if (itemn.id == this.tableData[i].id) {
                        this.tableData[i].bgStyle = false
                        if (this.tableData[i].dataFood != [] && this.tableData[i].dataFood[indexn] != null) {
                            this.tableData[i].dataFood[indexn].delShow = false
                        }
                    }
                }
            }
        },
        // 修改数量
        changeNumber(itemn,indexn,item1,index1){
            console.log(itemn, indexn, item1, index1)
            let mrGuid = itemn.dataFood[indexn].data[index1].id;
            let number = itemn.dataFood[indexn].data[index1].number;
            this.UpdateMaterialAverageNum(mrGuid, number);
        }, async UpdateMaterialAverageNum(mrGuid, number) {
            let data = await this.request({
                type: "GET",
                url: `${this.url}api/kindergarten/Recipes_Pc/UpdateSelectMaterialAverageNum`,
                data: {
                    mrGuid: mrGuid,
                    number: number
                }
            })
            if (!data.iserror) {
                this.GetBusinessAnalysisAndCalculation();
            }
        }
          ,
        // 删除
        del(itemn,indexn,item1,index1){
            console.log(itemn, indexn, item1, index1)
            if (item1 == undefined) {
                //删除菜
                this.DeleteSpecificDishRecord(itemn.dataFood[indexn].id);
            } else {
                //删除原料
                this.DeleteMaterialRecord(itemn.dataFood[indexn].data[index1].id);
            }
            this.GetBusinessAnalysisAndCalculation();
        }, async DeleteSpecificDishRecord(mid) {
            let data = await this.request({
                type: "GET",
                url: `${this.url}api/kindergarten/Recipes_Pc/DeleteSelectSpecificDishRecord`,
                data: {
                    mid: mid                   
                }
            })
            if (!data.iserror) {
                this.getBaseCInfo(this.weekType);
            }
        }, async GetselectCreateARecipe() {//选择推荐菜
            let data = await this.request({
                type: "GET",
                url: `${this.url}api/kindergarten/Recipes_Pc/GetselectCreateARecipe`,               
            })
            if (!data.iserror) {
               var values = data.data.map(function (p) {
                    return {
                        id: p.cjGuid,
                        name: p.cName                       
                    }
               });
                this.selectItems = values;
            }
        }, async DeleteMaterialRecord(mrGuid) {
            let data = await this.request({
                type: "GET",
                url: `${this.url}api/kindergarten/Recipes_Pc/DeleteSelectMaterialRecord`,
                data: {
                    mrGuid: mrGuid
                }
            })
            if (!data.iserror) {
                this.getBaseCInfo(this.weekType);
            }
        },
        // 开始拖拽
        dragstart(e, item) {
            this.choose = item           
        },
        // 拖拽放入目标
        dragDrop(e,item,ele) {
            if (ele !== undefined) {
                if (this.type != 2)
                    return;
                    //得到位置
                let n = null;
                for (let i = 0; i < this.tableData.length; i++) {
                    if (item.id == this.tableData[i].id) {
                        n = i;
                    }
                }

                if (this.tableData[n].dataFood[ele].data[0] != null && this.tableData[n].dataFood[ele].data[0].id == "-1") {
                    this.tableData[n].dataFood[ele].data = []
                }

                for (let i = 0; i < this.tableData.length; i++) {
                    if (item.id == this.tableData[i].id) {
                        this.getmeateFood(this.tableData[i].dataFood[ele].id, i, ele);  
                    }
                }                
            } else {
                if (this.type != 1)
                    return;
                let n = null
                for (let i = 0; i < this.tableData.length; i++) {
                    if (this.tableData[i].type == item.type) {
                        n=i
                    }
                }
                if (this.tableData[n].dataFood[0]!=null && !this.tableData[n].dataFood[0].id) {
                    this.tableData[n].dataFood = []
                }
                for (let i = 0; i < this.tableData.length; i++) {
                    if (item.id == this.tableData[i].id) {
                        console.log(item);
                        this.tableData[i].bgStyle = false
                        this.tableData[i].delShow = false
                        if (this.tableData[i].dataFood.length > 0) {
                            for (let j = 0; j < this.tableData[i].dataFood.length; j++) {
                                this.tableData[i].dataFood[j].bgStyle = false
                                this.tableData[i].dataFood[j].delShow = false
                            }
                        } 
                        this.getbindFood(item.id,i);
               
                        return
                    }
                }
            }
        }, async getmeateFood(cguid,i,ele) {
            let datas = await this.request({
                type: "GET",
                url: `${this.url}api/kindergarten/Recipes_Pc/AddselectMaterialRecordRecord`,
                data: {
                    CGuid: cguid,
                    materialGuid: this.choose.id,
                    cname: this.choose.name
                }
            })

            if (!datas.iserror) {               
                this.tableData[i].dataFood[ele].data.push(
                    {    
                        id: datas.data.mrGuid,
                        name: this.choose.name,
                        delShow: false,
                        number: datas.data.number
                    }
                )
            }          
        }
        , async getbindFood(mealTypes, i) {
            let datas = await this.request({
                type: "GET",
                url: `${this.url}api/kindergarten/Recipes_Pc/GetSelectASingleDish`,
                data: {
                    guid: this.choose.id,
                    termName: this.termname,
                    mealTypes: mealTypes,
                    weekNum: this.weekType,
                    weekcNum: this.weekly
                }
            })

            if (!datas.iserror) {
                var mdatas = [{
                    id: "-1",
                    name: "",
                    delShow: false,
                    number: 0
                }];
                if (datas.data.mates.length > 0) {
                    mdatas = datas.data.mates.map(function (p) {
                        return {
                            id: p.mrGuid,
                            name: p.mname,
                            delShow: false,
                            number: p.number
                        }
                    });
                }
                this.tableData[i].dataFood.push(
                    {
                        id: datas.data.info.mId,
                        value: this.choose.name,
                        number: 0,
                        bgStyle: false,
                        delShow: false,
                        data: mdatas
                    },
                )
            }          
        },
        async getDataFoodTable1(sname) {
            if (this.isshowData == false) return;
            let data;
            if (this.type == 1) {
                data = await this.request({
                    type: "GET",
                    url: `${this.url}api/kindergarten/Recipes_Pc/GetMakeFoodsInfo`,
                    data: {
                        sname: sname
                    }
                })
            } else {
                data = await this.request({
                    type: "GET",
                    url: `${this.url}api/kindergarten/Recipes_Pc/GetMakeMaterialInfo`,
                    data: {
                        sname: sname
                    }
                })
            }
            if (!data.iserror) {
                this.navFoodData = []
                if (data.data.length > 0) {
                    var value = data.data.map(function (x) {
                        return {
                            id: x.id,
                            title: x.ctypename,
                            showData: false,
                            data: x.list.map(function (r) {
                                return {
                                    id: r.id,
                                    name: r.cname
                                }
                            })
                        };
                    });
                    this.navFoodData = value;
                }
            }
        },
        getDataTable1(week) {
            this.getBaseCInfo(this.weekType);
        },
        getDataTable2(week){
           this.GetBusinessAnalysisAndCalculation();
        }, async GetBusinessAnalysisAndCalculation() {//营养素分布
            let data = await this.request({
                type: "GET",
                url: `${this.url}api/kindergarten/Recipes_Pc/GetselectBusinessAnalysisAndCalculation`,
                data: {
                    tempname: this.termname,
                    weekly: this.weekly,
                    numberOfWeeks: this.weekType
                }
            })
            if (!data.iserror) {
                this.rightData = [];
                if (data.data.length > 0) {
                    var values = data.data.map(function (t) {
                        return {                            
                            bgStyle: false,
                            type: t.nutrients,//营养素
                            baseNumber: t.StandardQuantity,//标准量
                            eatIn: t.intake,//摄入量
                            percentage: t.percentage+'%',//百分比
                            judge: t.evaluation//评价
                        }
                    });
                    this.rightData = values;
                }
            }
        }, async getBaseCInfo(nuberw) {//获取模板菜的数据
           let data = await this.request({
                type: "GET",
               url: `${this.url}api/kindergarten/Recipes_Pc/GetSelectbasicTemplateDatas`,
               data: {
                   tempname: this.termname,
                   weekly: this.weekly,
                   nuberw: this.weekType
                }
           })
            if (!data.iserror) {
                if (data.data.length > 0) {
                    var pisShow = false;
                    var value = data.data.map(function (x) {
                        var dta = [
                            {
                                data: []
                            }                        ];
                        if (x.cInfo.length > 0) {
                           pisShow= true;                           
                            dta = x.cInfo.map(function (t) {
                                var yldata = [{
                                    id: "-1",
                                    name: "",
                                    delShow: false,
                                    number: 0
                                }];
                                if (t.list.length>0) {
                                    yldata = t.list.map(function (p) {
                                        return {
                                            id: p.mrGuid,
                                            name: p.mname,
                                            delShow: false,
                                            number: p.number
                                        }
                                    });
                                }

                                return {
                                    id: t.mId,
                                    value: t.cName,
                                    number: t.number,
                                    bgStyle: false,
                                    delShow: false,
                                    data: yldata
                                }
                            });
                        }
                        
                        return {
                            id: x.id,
                            bgStyle: x.bgStyle,
                            delShow: x.delShow,
                            type: x.type,
                            dataFood:dta
                        };
                    });
                   
                    this.tableData = value;
                    if (this.isshowData != true)
                          this.isshowData = pisShow;
                  
                    if (this.isshowData == true) {
                        //获取菜的数据
                        this.getDataFoodTable1();
                        //营养数据报告
                        this.GetBusinessAnalysisAndCalculation();
                    } else {
                        this.navFoodData = [];
                        this.rightData = [];
                    }

                }
            }

        },
        search(text) {
            this.getDataFoodTable1(text);
        }, getUrlParam(paraName) {//获取URL某个参数的值
            var reg = new RegExp("(^|&)" + paraName + "=([^&]*)(&|$)", "i");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) return decodeURI(r[2]); return "";           

            }
    }
})