{extend name="Public/base" /}
{block name="css"}
<style>
    .layui-table-page {
        margin-left: 4px;
        height: 62!important;
    }
    .w-120 {
        width: 127px;
    }
</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>
        <div class="set-top layui-form">
            ID搜索:
            <div class="layui-input-inline">
                <input type="text" class="layui-input" id="id" placeholder="请输ID号">
            </div>
            客资姓名:
            <div class="layui-input-inline w-150" >
                <input type="text" class="layui-input" id="customer_name" placeholder="请输入客资姓名">
            </div>
            联系方式:
            <div class="layui-input-inline w-150" >
                <input type="text" class="layui-input" id="customer_tel" placeholder="请输入联系方式">
            </div>
            登记人
            <div class="layui-input-inline">
                <select id="dj_staff_id" name="dj_staff_id"  lay-verify="required" lay-search="">
                    <option value="">请选择</option>
                    {volist name="staff" id="s"}
                    <option value="{$s.id}">{$s.staffname}</option>
                    {/volist}
                </select>
            </div>
            追踪人
            <div class="layui-input-inline">
                <select id="sales_staff_id" name="sales_staff_id"  lay-verify="required" lay-search="">
                    <option value="">请选择</option>
                    {volist name="sales" id="ss"}
                    <option value="{$ss.id}">{$ss.staffname}</option>
                    {/volist}
                </select>
            </div>
            开始时间:
            <div class="layui-input-inline w-150" >
                <input type="text" class="layui-input" id="start" readonly="readonly" placeholder="请选择操作开始时间">
            </div>
            结束时间:
            <div class="layui-input-inline w-150" >
                <input type="text" class="layui-input" id="end"  readonly="readonly" placeholder="请选择操作结束时间">
            </div>
            <button class="layui-btn" id="btn">查询</button>
        </div>
        <table class="layui-table" lay-data="{height:770,limit:50, url:'/crm/customer/customerBackJSON.html', page:true,id:'idTest'}" lay-filter="idTest">
            <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:80,}">登记人</th>
                <th lay-data="{field:'sales_staff', width:80,}">追踪人</th>
                <th lay-data="{field:'is_fp', width:80,toolbar: '#fp'}">分配状态</th>
                <th lay-data="{field:'staff_name', width:100}">操作人</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">
    $('#btn').click(function(){
        var customer_name = $('#customer_name').val();
        var customer_tel = $('#customer_tel').val();
        var dj_staff_id = $('#dj_staff_id').val();
        var sales_staff_id = $('#sales_staff_id').val();
        var start = $('#start').val();
        var end = $('#end').val();
        var index = layer.load(1, {shade: false}); //0代表加载的风格，支持0-2
        var id = $("#id").val();
        table.reload('idTest', {
            url: 'customerBackJSON'
            ,where: {customer_name:customer_name,customer_name:customer_name,customer_tel:customer_tel,sales_staff_id:sales_staff_id,dj_staff_id:dj_staff_id,start:start,end:end,id:id}, //设定异步数据接口的额外参数
            done: function(res, curr, count){
                layer.close(index);
            }
        });

    })
    // 表格
    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 +'页');
                }
            }
        });
        //日历
        layui.use('laydate', function () {
            var laydate = layui.laydate;
            laydate.render({
                elem: '#start'
                ,max:0
                ,format: 'yyyy-MM-dd'
            });
            laydate.render({
                elem: '#end'
                ,max:0
                ,format: 'yyyy-MM-dd'
            });
        });
        table.on('tool(idTest)', function (obj) {
            var data = obj.data, //获得当前行数据
            layEvent = obj.event; //获得 lay-event 对应的值
            if (layEvent === 'detail') {
                layer.confirm('真的要恢复吗？', function (index) {
                    $.ajax({
                        type: "POST",
                        url: '/crm/Customer/customerRecove',
                        data: 'cid='+obj.data.id,
                        success: function (ret) {
                            if (ret) {
                                layer.alert(ret.msg);
                                table.reload('idTest', {
                                });
                            } else {
                                layer.alert('操作失败');
                            }
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            var ret = XMLHttpRequest.responseJSON
                            layer.alert('操作有误');
                        }
                    });
                })
            }
        })
    })

</script>
{/block}