{extend name="Public/base" /}
{block name="css"}
<style>
    .layui-table-page {
        /*margin-top: -60px;*/
        margin-left: 4px;
        height: auto!important;
    }
</style>
{/block}
{block name="main"}

<div class="if_wrap">
    <div class="cus-con">
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
            <legend>客资池未分配客资列表</legend>
        </fieldset>
        {if $switch}
        {auth code='menu1517042801'}
        <button class="layui-btn layui-btn-primary cus-model-btn" id="customerReAllot">
            <i class="fa fa-repeat" style="font-size: 14px"></i> 失败再分配
        </button>
        {/auth}
        {/if}
        <table class="layui-table" lay-data="{limit:15, url:'/crm/customer/customerBySalfJSON.html', page:true,id:'idMsg'}" lay-filter="msgTable">
            <thead>
            <tr>
                <!--<th lay-data="{type:'checkbox', fixed: 'left'}"></th>-->
                <th lay-data="{field:'id', width:50, sort: true,toolbar: '#titleTpl'}">序号</th>
                <th lay-data="{width:100, align:'center', toolbar: '#barDemo'}">操作</th>
                <th lay-data="{field:'id', width:100}">客资ID</th>
                <th lay-data="{field:'customer_name', width:100}">客资姓名</th>
                <th lay-data="{field:'customer_tel', width:150, sort: true}">手机</th>
                <th lay-data="{field:'customer_qq', width:100}">QQ</th>
                <th lay-data="{field:'customer_wechat', width:100}">微信</th>
                <th lay-data="{field:'mate_tel', width:150, sort: true}">配偶手机号</th>
                <th lay-data="{field:'customer_channel', width:150}">渠道名称</th>
                <th lay-data="{field:'access_model', width:100}">获取方式</th>
                <th lay-data="{field:'consultation_type', width:100,  }">消费类型</th>
                <th lay-data="{field:'dj_day', width:150,  }">录入时间</th>
                <th lay-data="{field:'dj_staff', width:100,  }">登记人</th>
                <th lay-data="{field:'is_fp', width:100,toolbar: '#fp' }">分配状态</th>
            </tr>
            </thead>
        </table>
        <script type="text/html" id="fp">
            {{#  if(d.is_fp == 1){ }}
            已分配
            {{#  } else if(d.is_fp == 2) { }}
            未分配
            {{#  } else if(d.is_fp == 3) { }}
            待接收
            {{#  } else if(d.is_fp == 4) { }}
            分配失败
            {{#  } }}
        </script>
        <script type="text/html" id="titleTpl">
            {{d.LAY_TABLE_INDEX+1}}
        </script>
        <script type="text/html" id="barDemo">
            <a class="layui-btn layui-btn-mini" lay-event="detail">分配给我</a>
        </script>
    </div>
</div>
<script src="__PUBLIC__/js/jquery-1.9.0.min.js?v={$Think.const.APP_VERSION}" type="text/jscript"></script>
<script type="text/javascript">
    // 表格
    layui.use(['laydate', 'laypage', 'layer', 'table', 'carousel', 'upload', 'element'], function(){
        var laydate  = layui.laydate, //日期
                laypage  = layui.laypage //分页
        layer    = layui.layer, //弹层
                table    = layui.table, //表格
                carousel = layui.carousel, //轮播
                upload   = layui.upload, //上传
                element  = layui.element; //元素操作
        //分页
        laypage.render({
            elem: 'pageDemo' //分页容器的id
            ,count: 100 //总页数
            ,limit:15
            ,skin: '#1E9FFF' //自定义选中色值
            ,jump: function(obj, first){
                if(!first){
                    layer.msg('第'+ obj.curr +'页');
                }
            }
        });

        table.on('tool(msgTable)', function (obj) {
            var data = obj.data, //获得当前行数据
                    layEvent = obj.event; //获得 lay-event 对应的值
            if (layEvent === 'detail') {
                $.ajax({
                    type: "POST",
                    url: '{:url("crm/Customer/allotReceive")}',
                    data: 'cid='+obj.data.id,
                    success: function (ret) {
                        if (ret) {
                            layer.alert(ret.msg);
                            table.reload('idMsg', {
                            });
                        } else {
                            layer.alert('操作失败');
                        }
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        var ret = XMLHttpRequest.responseJSON
                        layer.alert('操作有误');
                    }
                });
            }
        })
    })
    $('#customerReAllot').click(function(){
        $.ajax({
            type: "POST",
            url: 'customerReAllot',
            success: function(msg){
                // if( msg.code == 200 ){
                //     layer.alert(msg.msg);
                //     reloadGrid();
                //     return false;
                // }else{
                //     layer.alert(msg.msg);
                // }
                layer.alert('开始重新分配');
            },
            error:function(){
                layer.alert('操作有误');
            }
        });
    })
</script>
{/block}