
<div class="layui-fluid">
    <style>
    .files_itemwsmrz{width:50px;height:50px;cursor:pointer; padding: 1px; background:#fff;display:-webkit-box;-moz-box-align:center;-webkit-box-align:center;-moz-box-pack:center;-webkit-box-pack:center;}
    .files_itemwsmrz img{width:48px;height:48px;}
    </style>
            <div class="layui-card">
                <div class="layui-card-header">
                    <form class="layui-form render">
                        <input type="hidden" name="groupid" id="smrz-groupid" value=""/>
                        <div class="layui-form-item">

                            <div class="layui-inline" style="width:250px;"><input type="text" name="kw" placeholder="用户名，用户手机号"  autocomplete="off" class="layui-input" lay-affix="clear"/></div>
                            <div class="layui-inline" style="width:150px;">
                                <select name="status">
                                    <option value="-1">审核状态</option>
                                    <option value="2">审核通过</option>
                                    <option value="1">审核失败</option>
                                    <option value="0">待审核</option>
                                </select>
                            </div>


                            <div class="layui-inline">
                                <div class="layui-btn-group">
                                    <button  class="layui-btn" lay-submit lay-filter="search-smrz"><i class="layui-icon layui-icon-search"></i> 搜索</button>
                                    <a class="layui-btn" lay-submit lay-filter="search-smrz-all" onclick="$('#smrz-groupid').val('')"><i class="layui-icon layui-icon-light"></i>全部</a>

                                </div>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="layui-card-body">

                    <div class="layui-card-box">
                    <table lay-filter="smrz" id="smrz"></table>
                    </div>
                </div>
            </div>

</div>

<script type="text/html" id="smrzdemo">
    <div class="layui-clear-space">


        <a class="layui-btn layui-btn-xs" lay-event="shenhei">审核</a>
        <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>
<!--        <a class="layui-btn layui-btn-xs" lay-event="more">-->
<!--            更多-->
<!--            <i class="layui-icon layui-icon-down"></i>-->
<!--        </a>-->
    </div>
</script>


<script type="text/html" id="smrzstatus-demo">
    {{# if (d.status === 2) { }}
    <a class="layui-btn layui-btn-xs layui-btn-normal" >{{=d.status_text}}</a>
    {{# } else { }}
    {{# if(d.status === 1) { }}
    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="statuserror">{{=d.status_text}}</a>
    {{# } else { }}
    <a class="layui-btn layui-btn-xs">{{=d.status_text}}</a>
    {{# } }}
    {{# } }}
</script>
<!--JS部分-->
<script>

    layui.use(['vinfo', 'buildItems'], function(){
        var map_root = layui.cache.maps;
        var app_root = map_root + 'users.smrz/';
        var layer = layui.layer,table=layui.table,form=layui.form,admin=layui.admin;
        var dropdown = layui.dropdown;
        /*初始渲染*/
        /*==============左树结构END==============*/
        /*渲染数据*/




        table.render({
            elem: '#smrz',
            page: true,
            limit:{$limit},

            url: app_root+"index?&do=json",
            css:".layui-table-cell{ height:auto;}",
            cols: [[
                {type:'checkbox',fixed:'left'},
                {field:'id',width:50,unresize:true,align:'center',title:'ID',sort:!0},
                {field:'smrzname',align:'center',width:160,title:'用户名',templet:'<div>{{d.getuserdata.username}}</div>'},
                {field:'mobile',align:'center',width:120,title:'用户手机号',templet:'<div>{{d.getuserdata.mobile}}</div>'},
                {field:'realname',align:'center',width:120,title:'姓名'},
                {field:'idcard',align:'center',title:'身份证号码'},
                {field:'idcard_q',width:150,align:'center',title:'身份证正面',templet:'<div class="files_itemwsmrz"><img src="{{d.idcard_qurl}}" lay-event="smrz-event-image" /></div>'},
                {field:'idcard_h',width:150,align:'center',title:'身份证背面',templet:'<div class="files_itemwsmrz"><img src="{{d.idcard_hurl}}" lay-event="smrz-event-image" /></div>'},
                {field:"status_text",width:100,align:'center',title:"状态",templet:'#smrzstatus-demo'},

                {field:'create_time',width:150,align:'center',title:'创建时间'},
                {fixed:'right',width:120,align:'center', templet: '#smrzdemo',title:'操作'}
            ]],
            done: function(){ admin.vShow($('[lay-table-id="smrz"]'));

            }
        });

        // 状态 - 开关操作
        form.on('switch(smrz-chang)', function(obj){
            var json = JSON.parse(decodeURIComponent($(this).data('json')));
            var av = obj.elem.checked ? 1 : 0;
            admin.req(app_root+"editup",{id:json.id,av:av,af:obj.elem.name},function(res){
                layer.tips(res.msg,obj.othis,{time:1000});
                if(res.code === 0) obj.elem.checked = parseInt(obj.value);
            },'post',{headersToken:true});
        });

        /*快编监听*/
        table.on('edit(smrz)',function(obj){
            admin.req(app_root+"editup",{id:obj.data.id,av:obj.value,af:obj.field},function(res){
                layer.msg(res.msg,{shade:[0.4,'#000'],time:500});
            },'post',{headersToken:true});
        });/**/

        /*工具条监听*/
        table.on('tool(smrz)', function(obj){
            var data = obj.data;
            var id = data.id;
            if(obj.event === 'detail'){

                smrzOpen(id);
            }else if(obj.event === 'del'){
                del(id);
            }else if(obj.event === 'smrz-event-image'){
                var src = $(this).attr('src'), alt = $(this).attr('alt');
                layer.photos({photos:{data:[{alt:alt,src:src}],start:'0'},anim:5,shade:[0.4,'#000']});
            }else if(obj.event === 'more'){

            }else if(obj.event === 'shenhei'){

                layer.confirm('选择审核状态？', {
                    btn: ['审核通过', '审核不通过'],
                    btn1: function(index, layero, that){

                        shajax(data.id,1);
                    },
                    btn2: function(index, layero, that){
                        layer.prompt({
                            formType: 2,
                            value: '',
                            title: '请输入失败原因',
                        }, function(value, index, elem){

                            shajax(data.id,2,value);

                        });
                    },
                });
            }else if(obj.event === 'statuserror'){
                layer.alert(data.status_desc,{title:'失败原因'});
            }
        });/**/
        /*删除*/
        function del(ids){
            layer.confirm('确定要删除所选记录吗？', function(){
                admin.req(app_root+"del",{id:ids},function(res){
                    layer.msg(res.msg,{shade:[0.4,'#000'],time:1500},function(){
                        if(res.code==1) table.reloadData('smrz');
                    });
                },'post',{headersToken:true});
            });
        }/**/


        /*弹出窗*/
        function smrzOpen(id='',type=''){
            layer.open({
                type: 2,
                area: ['900px', '900px'],
                title: '资料详情',
                btn: ['确定', '关闭'],
                fixed: false, //不固定
                content: '/admin/users.smrz/detail?id='+id+'&type='+type,
                yes: function(index, layero){
                    layer.close(index);
                },
            });
        }/**/

        function shajax(id,shstatus,errordesc=''){
            $.ajax({
                method: "post",
                url: layui.cache.maps+'/users.smrz/shenhesmrz',
                data: {id:id,shstatus:shstatus,errordesc:errordesc},
                dataType: "json",
                success: function (res){
                    if(res.code===1) {
                        layer.msg(res.msg,{icon:1,shade:[0.4,'#000'],time:1500},function (){
                            layer.closeAll();
                            table.reloadData('smrz');
                        });
                    }else{
                        layer.msg(res.msg,{icon:2,shade:[0.4,'#000'],time:1500},function (){

                        });
                    }


                }
            });
        }

    });
</script>