
<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="business-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="business" 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="1">审核通过</option>
                                    <option value="2">审核失败</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-business"><i class="layui-icon layui-icon-search"></i> 搜索</button>
                                    <a class="layui-btn" lay-submit lay-filter="search-business-all" onclick="$('#business-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="business" id="business"></table>
                    </div>
                </div>
            </div>

</div>

<script type="text/html" id="businessdemo">
    <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>
<!--        <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="status-demo">
    {{# if (d.status === 1) { }}
    <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 + 'users.business/';
        var layer = layui.layer,table=layui.table,form=layui.form,admin=layui.admin;
        var dropdown = layui.dropdown;
        /*初始渲染*/

        table.render({
            elem: '#business',
            page: true,
            limit:{$limit},
            height: 'full-341',
            url: app_root+"index?&do=json",
            cols: [[
                {type:'checkbox',fixed:'left'},
                {field:'id',width:50,unresize:true,align:'center',title:'ID',sort:!0},
                {field:'businessname',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:'name',align:'center',title:'企业名称'},
                {field:'type',align:'center',title:'类型'},
                {field:'addressxx',align:'center',title:'详细地址'},
                {field:"status_text",width:100,align:'center',title:"状态",templet:'#status-demo'},
                {field:'contacts_name',align:'center',width:100,title:'联系人姓名'},
                {field:'job',align:'center',width:100,title:'联系人职位'},
                {field:'contacts_phone',align:'center',width:130,title:'联系人手机号'},
                {field:'contacts_email',align:'center',width:150,title:'联系人邮箱'},
                {field:'create_time',width:150,align:'center',title:'创建时间'},
                {fixed:'right',width:120,align:'center', templet: '#businessdemo',title:'操作'}
            ]],
            done: function(){ admin.vShow($('[lay-table-id="business"]'));

            }
        });

        // 状态 - 开关操作
        form.on('switch(business-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(business)',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(business)', function(obj){
            var data = obj.data;
            var id = data.id;
            if(obj.event === 'detail'){

                businessOpen(id);
            }else if(obj.event === 'del'){
                del(id);
            }else if(obj.event === 'business-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('business');
                    });
                },'post',{headersToken:true});
            });
        }/**/


        /*弹出窗*/
        function businessOpen(id='',type=''){
            layer.open({
                type: 2,
                area: ['900px', '900px'],
                title: '资料详情',
                btn: ['确定', '关闭'],
                fixed: false, //不固定
                content: '/admin/users.business/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.business/shenhebusiness',
                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('business');
                        });
                    }else{
                        layer.msg(res.msg,{icon:2,shade:[0.4,'#000'],time:1500},function (){

                        });
                    }


                }
            });
        }

    });
</script>