new Vue({
    el: '#headerView',
    data: {
        activeMenu: 2,
        keyword: '',
        MENUS:[],
        TYPES: [],
        PRODUCTS: [],
        saveLoading: false
    },
    methods: {
        getMenuClass: function (item) {
            var cls = '';
            if (item.menuSort == 3) {
                cls = 'menu_dd_pro'
            }
            if (this.activeMenu == item.menuSort) {
                cls += ' hover';
            }
            return cls;
        },
        handleSearch: function () {
            location.href = '/chanpin.html?k=' + this.keyword
        },
        loadMenus: function () {
            var that = this;
            $.ajax({
                url: "/api/menu/tree",
                type: "post",
                async: false,
                data: JSON.stringify({type: 0}),
                headers: {'Content-Type': 'application/json;charset=UTF-8'},
                dataType: "json",
                success: function (res) {
                    if (res.code == "success") {
                        that.MENUS = res.data.pc;
                    } else {
                        that.MENUS = [];
                    }
                }
            });
        },
        loadTypes: function () {
            var that = this;
            $.ajax({
                url: "/api/goods/type/all",
                type: "post",
                dataType: "json",
                success: function (res) {
                    if (res.code == "success") {
                        that.TYPES = res.data;
                    } else {
                        that.TYPES= [];
                    }
                }
            });
        },
        loadProducts: function () {
            var that = this;
            $.ajax({
                url: "/api/goods/page",
                type: "post",
                data: JSON.stringify({currentPage: 1, pageSize: 100}),
                headers: {'Content-Type': 'application/json;charset=UTF-8'},
                dataType: "json",
                success: function (res) {
                    if (res.code == "success") {
                        that.PRODUCTS = res.data.list;
                    } else {
                        that.PRODUCTS = [];
                    }
                }
            });
        },
    },
    mounted: function () {
        this.loadMenus();
        this.loadTypes();
        this.loadProducts();
    }
});

new Vue({
    el:'#bottomView',
    data:{
        BOTTOMMENUS:[],
        TYPES:[]
    },
    methods:{
        loadMenus: function () {
            var that = this;
            $.ajax({
                url: "/api/menu/tree",
                type: "post",
                async: false,
                data: JSON.stringify({type: 0}),
                headers: {'Content-Type': 'application/json;charset=UTF-8'},
                dataType: "json",
                success: function (res) {
                    if (res.code == "success") {
                        that.BOTTOMMENUS = res.data.bottom;
                    } else {
                        that.BOTTOMMENUS = [];
                    }
                }
            });
        },
        loadTypes:function() {
            var that = this;
            $.ajax({
                url:"/api/goods/type/all",
                type:"post",
                dataType:"json",
                success:function (res) {
                    if(res.code=="success"){
                        that.TYPES=res.data;
                    }else{
                        that.TYPES=[];
                    }
                }
            });
        }
    },
    mounted:function () {
        this.loadMenus();
        this.loadTypes();
    }
});