
<div class="layui-fluid">
    <style>
    .files_itemadv{width:30px;height:30px;line-height:30px;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_itemadv img{max-width:28px;max-height:28px;border:0}
    </style>
            <div class="layui-card">
                <div class="layui-card-header">
                    <form class="layui-form render">
                        <input type="hidden" name="groupid" id="certorder-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:250px;"><input type="text" name="cert_title" placeholder="证书名称"  autocomplete="off" class="layui-input" lay-affix="clear"/></div>
                            <div class="layui-inline" style="width:150px;">
                                <select name="status">
                                    <option value="">审核状态</option>
                                    <option value="1">申请中</option>
                                    <option value="2">申请失败</option>
                                    <option value="3">申请成功</option>
                                </select>
                            </div>
                            <div class="layui-inline">
                                <div class="layui-btn-group">
                                    <button  class="layui-btn" lay-submit lay-filter="search-certorder"><i class="layui-icon layui-icon-search"></i> 搜索</button>
                                    <a class="layui-btn" lay-submit lay-filter="search-certorder-all" onclick="$('#certorder-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="certorder" id="certorder"></table>
                    </div>
                </div>
            </div>

</div>

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

        <a class="layui-btn layui-btn-xs" lay-event="detail">详情</a>
        <a class="layui-btn layui-btn-xs" lay-event="shenhei">审核</a>
        {{# if (d.certfiledata) { }}
        <a class="layui-btn layui-btn-xs" lay-event="uploadcert">查看证书</a>
        {{# } else { }}
            <a class="layui-btn layui-btn-xs" lay-event="uploadcert">上传证书</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="certorderstatus-demo">
    {{# if (d.status === 3) { }}
    <a class="layui-btn layui-btn-xs layui-btn-normal" >{{=d.status_text}}</a>
    {{# } else { }}
    {{# if(d.status === 2) { }}
    <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 + 'cert.cert_order/';
        var layer = layui.layer,table=layui.table,form=layui.form,admin=layui.admin;
        var dropdown = layui.dropdown;
        /*初始渲染*/
        /*==============左树结构END==============*/
        /*渲染数据*/

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

            url: app_root+"index?&do=json",
            cols: [[
                {type:'checkbox',fixed:'left'},
                {field:'id',width:50,unresize:true,align:'center',title:'ID',sort:!0},
                {field:'certordername',align:'center',width:160,title:'用户名',templet:'<div>{{d.userprofile.username}}</div>'},
                {field:'mobile',align:'center',width:120,title:'用户手机号',templet:'<div>{{d.userprofile.mobile}}</div>'},
                {field:'name',align:'center',title:'证书名称',templet:'<div>{{d.certdata.title}}</div>'},
                {field:"status_text",width:100,align:'center',title:"状态",templet:'#certorderstatus-demo'},
                {field:'name',align:'center',title:'报名姓名'},
                {field:'idcard',align:'center',title:'报名身份证号码'},
                {field:'mobile',align:'center',title:'报名手机号'},
                {field:'email',align:'center',title:'报名邮箱'},
                {field:'createtime',width:150,align:'center',title:'创建时间'},
                {fixed:'right',width:150,align:'center', templet: '#certorderdemo',title:'操作'}
            ]],
            done: function(){ admin.vShow($('[lay-table-id="certorder"]'));

            }
        });

        // 状态 - 开关操作
        form.on('switch(certorder-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(certorder)',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(certorder)', function(obj){
            var data = obj.data;
            var id = data.id;
            if(obj.event === 'detail'){
                certorderOpen(id);
            }else if(obj.event === 'del'){
                del(id);
            }else if(obj.event === 'uploadcert'){
                uploadcert(id);
            }else if(obj.event === 'certorder-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('certorder');
                    });
                },'post',{headersToken:true});
            });
        }/**/


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



        /*弹出窗*/
        function uploadcert(id='',type=''){
            var title = "上传证书";

            layer.open({
                type: 2,
                area: ['900px', '90%'],
                title: title,
                btn: ['确定', '关闭'],
                content: '/admin/cert.cert_file/edit?cert_order_id='+id,
                yes: function(index, layero){
                    var data = window["layui-layer-iframe" + index].callbackdata();
                    $.ajax({
                        method: "post",
                        url: '/admin/cert.cert_file/edit',
                        data: data,
                        dataType: "json",
                        success: function (res){
                            if(res.code===1) {
                                layer.msg(res.msg,{icon:1,shade:[0.4,'#000'],time:1500},function (){
                                    layer.close(index);
                                    table.reloadData('certorder');
                                });
                            }else{
                                layer.msg(res.msg,{icon:2,shade:[0.4,'#000'],time:1500},function (){

                                });
                            }
                            // layer.closeAll();

                        }
                    });
                },
            });
        }/**/

        function shajax(id,shstatus,errordesc=''){
            $.ajax({
                method: "post",
                url: app_root+'/shenhecertorder',
                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('certorder');
                        });
                    }else{
                        layer.msg(res.msg,{icon:2,shade:[0.4,'#000'],time:1500},function (){

                        });
                    }


                }
            });
        }

    });
</script>