var myUser=getCookie('user');
if(!myUser){
    layer.msg('无权限进入');
}else{
    myUser=JSON.parse(myUser);
}
//layui初始化
layui.use(['form'], function(){
    form = layui.form;
    form.render(); //更新全部    
    querycommunity();
    querymodule();
});     

//layui打开
function layerOpen(layui_open_option,callback) {
    layer.open({
        type: 1,
        title: layui_open_option.title,
        area: layui_open_option.area, //宽高
        content: layui_open_option.content,
        offset: ['50px'],
        btn: ["确定","关闭"],
        resize: false,
        yes: function (index, layero) {
            if(callback){
                callback(index);
            }else{
                layer.close(index);
            }
        }
    });
}

var vue_baseedit = new Vue({
    el: '#basemanage',
    data: {
        fzrs: [{
                xm: "张枫",
                dh: "13851869557",
                zw: "党委书记"
            },
            {
                xm: "张枫	",
                dh: "15062279270",
                zw: "社区主任"
            }
        ],
        jbxx: [{key:"整体面积",value:"3.8平方公里"},{key:"总房栋数",value:"349"},{key:"户   数",value:"8069"},{key:"人口总数",value:"3.22万人"},{key:"企业数",value:"183"},{key:"个体户数",value:"297"}]
 
    },
    methods:{
        save:function(){
            alert(1);
        }
    }
});

/**
 * 网格数据
 */
//查询网格数据列表
function querycommunity(){
    getByAjax("../rest/gridquery/xwsq", result => {
        vue_communitydata.datax = result.grid;
        if(result.length==0){
            layer.msg("未查找到数据");
        }
    });
}
//网格数据列表
var vue_communitydata = new Vue({
    el: '#communitymanage',
    data: {
        datax: []
    },
    methods: {
        query:function(){
            querycommunity();
        },
        edit:function(item,index){                
            var layui_open_option = {
                title: ['编辑网格信息', 'font-weight: 700;'],
                content: $('.communitybjtcc-div'),
                area: ['700px', '400px'], //宽高
            };
            vue_communityedit.xq = Object.assign({}, item);
            layerOpen(layui_open_option, (layerindex) => {
                layer.confirm('是否确定要保存？', {
                    btn: ['确定', '取消'] //按钮
                }, function (layerindex1) { //确定删除 
                    layer.close(layerindex1);
                    postByAjax('../edit/updatecommunity', vue_communityedit.xq, result => {
                        if(result){
                            layer.msg("保存成功");
                            Vue.set(vue_communitydata.datax, index, vue_communityedit.xq)    
                         }else{
                            layer.msg("保存失败");
                         }
                     });
                    layer.close(layerindex);
                });
            });
        }
    }
});
//网格弹出面板修改
var vue_communityedit=new Vue({
    el:'#community_edit',
    data:{
        xq:{}
    }
});
 
/**
 * 模块管理
 */
//查询模块数据列表
function querymodule(){
    getByAjax("../rest/modulequery", result => {
        vue_moduledata.datax = result;
        if(result.length==0){
            layer.msg("未查找到数据");
        }
    });
}
//模块数据列表
var vue_moduledata = new Vue({
    el: '#modulemanage',
    data: {
        datax: [],
        condition: {
            name: '',
            xb: '',
            zjhm: '',
            unrelation: false,
            temporary: false,
            party: false,
            expire: false
        },
        totals: 0
    },
    methods: {
        query:function(){
            querymodule();
        },
        edit: function (item, index) {
            var layui_open_option = {
                title: ['编辑人员信息', 'font-weight: 700;'],
                content: $('.modulebjtcc-div'),
                area: ['700px', '610px'], //宽高
            };
            vue_moduleedit.xq = item;
            vue_moduleedit.contentobj=JSON.parse(vue_moduleedit.xq.content);
            //打开
            layerOpen(layui_open_option, (layerindex) => {
                layer.confirm('是否确定要保存？', {
                    btn: ['确定', '取消'] //按钮
                }, function (layerindex1) { //确定删除 
                    layer.close(layerindex1);
                    postByAjax('../edit/updatemodule', {
                        content: JSON.stringify(vue_moduleedit.contentobj),
                        id: item.id
                    }, result => {
                        if (result) {
                            layer.msg("保存成功");
                            vue_moduleedit.xq.content=JSON.stringify(vue_moduleedit.contentobj);
                            Vue.set(vue_moduledata.datax, index, vue_moduleedit.xq)
                        } else {
                            layer.msg("保存失败");
                        }
                    });
                    layer.close(layerindex);
                });
            });
        }
    }
});

//模块弹出面板修改
var vue_moduleedit=new Vue({
    el:'#module_edit',
    data:{
        xq:{content:"[]"},
        contentobj:null
    }
});