layui.extend({
    common    :   'js/common'
}).use(['jquery','layer','common','form'],function () {
    //  Jquery插件
    var $ = layui.jquery;
    //  弹窗插件
    var layer = layui.layer;
    //  引入表单插件
    var form = layui.form;
    //  引入公共模块
    var common = layui.common;


    //审核通过
    form.on('submit(auditing_yes_button)', function(data){
        data.field.checkState = 1;
        common.sendAsyncRequest("/estate/access/updateUserCheckState",'POST',data.field,callbackFn);
    });

    form.on('submit(auditing_no_button)', function(data){
        if(data.field.checkOpinion == null || data.field.checkOpinion == ''){
            layer.msg("请先填写审核意见");
            return;
        }
        data.field.checkState = 2;
        common.sendAsyncRequest("/estate/access/updateUserCheckState",'POST',data.field,callbackFn);
    });


    //回调函数
    function callbackFn(result) {
        if(result.data){
            layer.msg("审核成功",{
                time: 500,
                shade : [0.1 , '#000' , true]
            },function () {
                //获取当前弹窗出层的名字
                var index = parent.layer.getFrameIndex(window.name);
                //关闭弹窗层
                parent.layer.close(index);
                // 父页面刷新
                parent.location.reload();
            });
        }else {//添加失败
            layer.msg("审核失败");
        }
    }

    //取消按钮
    $('#cancel_btn').on("click",function(){
        //获取当前弹窗出层的名字
        var index = parent.layer.getFrameIndex(window.name);
        //关闭弹窗层
        parent.layer.close(index);
    });
});