var vue = new Vue({
    el: ".container-index",
    data: {
        data_module: [],
        data_class: [
            {classname: "index"},
            {classname: "sjcx"},
            {classname: "jkgl"},
            {classname: "sjfx"},
            {classname: "jgsbgl"},
            {classname: "tstj"},
            {classname: "xtgl"},
        ],
        num: 0,
        level: 1,
        src: '',
        name: ''
    },
    methods: {
        xgmm: function () {
            vue_password.data_s = {
                password_old: '',
                password_new: '',
            }
            $("#myModal_xgmm").modal("show");
        },
        change: function (index, target, as, item) {
            this.num = index;
            var a = index + 1;
            for (var i = 0; i < target.currentTarget.parentElement.children.length; i++) {
                var src1 = target.currentTarget.parentElement.children[i].children[0].firstElementChild.src.replace("-1", "")
                target.currentTarget.parentElement.children[i].children[0].firstElementChild.src = src1;
            }
            target.currentTarget.children[0].firstElementChild.src = 'img/title/' + a + '-1.png';
            this.src = '' + item.html + '?id=' + item.id + '&url=' + item.url;
        },
        imgsrc: function (index) {
            if (index == 0) {
                return "img/title/1.png"
            }
            var a = index + 1;
            return "img/title/" + a + ".png";
        },
        logout: function () {
            sessionStorage.removeItem("tabs");
            sessionStorage.removeItem("currentTabId");
            window.location = "logout";
        }
    },
    mounted(){
        this.name = getCookie("bjpt_Name");
        $.ajax({
            url: "/firstmenu",
            dataType: "json",
            type: "POST",
            data: {
                "username": getCookie("bjpt_realName"),
            },
            success: function (result) {
                vue.data_module = [];
                if (result.code == 0) {
                    if (result.data.length > 0) {
                        result.data.forEach((item, index)=> {
                            vue.data_module.push({
                                name: item.menu_name,
                                html: "/pub_index",
                                classname: vue.data_class[0].classname,
                                id: item.menu_id,
                                url: item.url
                            })
                        });
                        vue.src = '' + vue.data_module[0].html + '?id=' + vue.data_module[0].id + '&url=' + vue.data_module[0].url;
                    }
                }

            }
        });
    }
});
// 重复弹框
$(document).on('show.bs.modal', '.modal', function (event) {
    $(this).appendTo($('body'));
}).on('shown.bs.modal', '.modal.in', function (event) {
    setModalsAndBackdropsOrder();
}).on('hidden.bs.modal', '.modal', function (event) {
    setModalsAndBackdropsOrder();
});


function setModalsAndBackdropsOrder() {
    var modalZIndex = 1040;
    $('.modal.in').each(function (index) {
        var $modal = $(this);
        modalZIndex++;
        $modal.css('zIndex', modalZIndex);
        $modal.next('.modal-backdrop.in').addClass('hidden').css('zIndex', modalZIndex - 1);
    });
    $('.modal.in:visible:last').focus().next('.modal-backdrop.in').removeClass('hidden');
}

var vue_password = new Vue({
        el: '#myModal_xgmm',
        data: {
            data_s: {
                password_old: '',
                password_new: '',
            }
        },
        methods: {
            define:function () {
                $.ajax({
                    url: "/user/myreset/newpwd="+this.data_s.password_new,
                    dataType: "json",
                    type: "POST",
                    data: {
                        "userId":getCookie("bjpt_userId"),
                        "password":this.data_s.password_old,
                        "username":getCookie("bjpt_realName"),
                        // "":,
                    },
                    success: function (result) {
                        // vue.data_module = [];
                        if(result.code==-1){
                            info_new("原密码输入错误");
                            window.setTimeout("$('#info-warning-new').modal('hide')", 2000);
                            this.data_s={
                                password_old: '',
                                password_new: '',
                            };
                        }else if(result.code==0){
                            info_new("修改密码成功");
                            window.setTimeout("$('#info-warning-new').modal('hide')", 2000);
                            $("#myModal_xgmm").modal("hide");
                        }
                    }
                });
            }
        }
    });