
<div class="layui-fluid">

    <style>
        #mailcategoryTreeBar{padding:10px 15px;border:1px solid #e6e6e6;background-color:#f2f2f2}
        #mailcategoryTree{border:1px solid #e6e6e6;border-top:none;padding:10px 5px;overflow:auto;height:-webkit-calc(100vh - 290px);height:-moz-calc(100vh - 290px);height:calc(100vh - 290px)}
        .layui-tree-entry .layui-tree-txt{padding:0 5px;border:1px transparent solid;text-decoration:none!important}
        .layui-tree-entry.organ-tree-click .layui-tree-txt{background-color:#fff3e0;border:1px #ffe6b0 solid}
        .files_itemwmail{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_itemwmail 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="mail-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="user" placeholder="用户名，用户手机" autocomplete="off" class="layui-input" lay-affix="clear"/></div>


                            <div class="layui-inline">
                                <div class="layui-btn-group">
                                    <button  class="layui-btn" lay-submit lay-filter="search-mail"><i class="layui-icon layui-icon-search"></i> 搜索</button>
                                    <a class="layui-btn" lay-submit lay-filter="search-mail-all" onclick="$('#mail-groupid').val('')"><i class="layui-icon layui-icon-light"></i>全部</a>
                                    <a class="layui-btn" id="mail-add" ><i class="layui-icon layui-icon-add-circle"></i> 添加</a>
                                    <a class="layui-btn" id="mail-del"><i class="layui-icon layui-icon-delete"></i> 删除</a>

                                </div>
                            </div>
                        </div>
                    </form>
                </div>


                    <div class="layui-card-body">
                    <table lay-filter="mail" id="mail"></table>
                    </div>

            </div>
</div>


<script type="text/html" id="paystatus-demo">
    {{# if (d.pay_status === 1) { }}
    <a class="layui-btn layui-btn-xs layui-btn-normal" >{{=d.pay_status_text}}</a>
    {{# } else { }}
    {{# if(d.pay_status === 2) { }}
    <a class="layui-btn layui-btn-xs layui-btn-danger">{{=d.pay_status_text}}</a>
    {{# } else { }}
    <a class="layui-btn layui-btn-xs">{{=d.pay_status_text}}</a>
    {{# } }}
    {{# } }}
</script>
<!--JS部分-->
<script>

    layui.use(['vinfo', 'buildItems','dropdown'], function(){
        var map_root = layui.cache.maps;
        var app_root = map_root + 'users.mail/';
        var layer = layui.layer,table=layui.table,form=layui.form,admin=layui.admin;


        /*渲染数据*/
        table.render({
            elem: '#mail',
            page: true,
            limit:{$limit},
            height: 'full-341',
            url: app_root+"index?&do=json",
            // css: 'td .layui-table-cell{height:80px;line-height:80px;padding:0 5px;}',
            cols: [[
                {type:'checkbox',fixed:'left'},
                {field:'id',width:50,unresize:true,align:'center',title:'ID',sort:!0},
                {field:'username',align:'center',width:150,title:'用户名',templet:'<div>{{= d.getuserdata.username}}</div>'},
                {field:'mobile',align:'center',width:120,title:'用户手机',templet:'<div>{{= d.getuserdata.mobile}}</div>'},
                {field:'content',align:'center',title:'消息内容'},
                {field:'type_text',align:'center',width:100,title:'类型'},
                {field:'createtime',width:150,align:'center',title:'时间'},
                {fixed:'right',width:130,align:'center',toolbar:'<div><a class="layui-btn layui-btn-xs layui-btn-danger"  lay-event="del">删除</a></div>',title:'操作'}
            ]],
            done: function(){ admin.vShow($('[lay-table-id="mail"]'));

            }
        });



        /*快编监听*/
        table.on('edit(mail)',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(mail)', function(obj){
            var data = obj.data;
            var id = data.id;
            if(obj.event === 'detail'){
                mailOpen(data.id);
            }else if(obj.event === 'del'){
                del(id);
            }else if(obj.event === 'mail-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'){

            }
        });/**/


        /*删除*/
        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('mail');
                    });
                },'post',{headersToken:true});
            });
        }/**/
        /*顶部删除按钮*/
        $('#mail-del').on('click', function(){
            var checkRows = table.checkStatus('mail').data;
            if(checkRows.length === 0){return layer.msg('请选择需删除的记录');}
            var ids = checkRows.map(function(d){return d.id;});
                console.log(ids);
            del(ids);
        });/**/

        $('#mail-add').on('click',function(){mailOpen();});/**/
        /*弹出窗*/
        function mailOpen(id='',type=''){

            layer.open({
                type: 2,
                area: ['900px', '90%'],
                title: '发送消息',
                btn: ['确定', '关闭'],
                content: app_root+'/add?id='+id+'&type='+type,
                yes: function(index, layero){
                    var data = window["layui-layer-iframe" + index].callbackdata();
                    $.ajax({
                        method: "post",
                        url: app_root+'/add',
                        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('mail');
                                });
                            }else{
                                layer.msg(res.msg,{icon:2,shade:[0.4,'#000'],time:1500},function (){

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

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


    });
</script>