{extend name="Public/base"/}
{block name="js"}
<script src="__PUBLIC__/js/jquery.table2excel.js?v={$Think.const.APP_VERSION}" type="text/jscript"></script>
<script>
    $(function(){
        // $(".nul_bli").eq(3).find(".navb").addClass("active");
//        $(".navb.active").parent().find(".nul_s .nul_sli").eq(3).find(".navs").addClass("active");
    })
</script>
{/block}
{block name="css"}
<style>
    .layui-table-page {
        margin-left: 4px;
        height: auto!important;
    }
    .cus-con .layui-form-item .layui-input-inline {
        float: left;
        width: 6%;
        margin-right: -20px;
    }
    .time{
        width: 160px !important;
        padding-right: 2px;
    }
    #sub {
        background: #01b88a;
        color: #fff;
        border: 1px solid #01b88a;
        font-size: 16px;
        margin-left: 25px;
    }
</style>
<link rel="stylesheet" href="__PUBLIC__/item/css/layui.css?v={$Think.const.APP_VERSION}">
<link rel="stylesheet" href="__PUBLIC__/css/set.css?v={$Think.const.APP_VERSION}">
<link rel="stylesheet" href="__PUBLIC__/css/statistics.css?v={$Think.const.APP_VERSION}">
{/block}
{block name="main"}
<div class="if_wrap">
    <div class="cus-con">
        <div class="set_tit"><span>{$title}</span></div>
        <div class=" set-top layui-form layui-form-item">
            <label style="width:70px;" class="layui-form-label mkz_t1" style="width:50px;">推广人员</label>
            <div class="layui-input-inline " class="time" style="width: 100px;">
                <select name="add_shop_code" id="add_shop_code" class="layui-input" lay-filter="add_shop">
                    <option value="">请选择门店</option>
                    {volist name="all_shops" id="vo"}
                    <option value="{$vo.shop_code}">{$vo.shop_name}</option>
                    {/volist}
                </select>
            </div>
            <div class="layui-input-inline " class="time" style="padding-left:25px;width: 100px;">
                <select name="add_staff_id" id="add_staff_id" class="layui-input">
                    <option value="0">请选择员工</option>
                </select>
            </div>
            <label style="width:70px;" class="layui-form-label mkz_t1" style="width:50px;">邀约人员</label>
            <div class="layui-input-inline " class="time" style="width: 100px;">
                <select name="shop_code" id="shop_code" class="layui-input" lay-filter="sales_shop">
                    <option value="">请选择门店</option>
                    {volist name="all_shops" id="vo"}
                    <option value="{$vo.shop_code}">{$vo.shop_name}</option>
                    {/volist}
                </select>
                
            </div>
            <div class="layui-input-inline " class="time" style="padding-left:30px;width: 100px;">
                <select name="sales_staff_id" id="sales_staff_id" class="layui-input">
                    <option value="0">请选择员工</option>
                </select>
            </div>
            <label style="width:70px;" class="layui-form-label mkz_t1" style="width:50px;">统计时间：</label>
            <div class="layui-input-inline " class="time" style="width: 100px;">
                <input type="text" class="layui-input" id="start" name="timeArea" readonly="readonly" value="">
            </div>
            <label style="padding-right: 10px;" class="layui-form-label mkz_t1">-</label>
            <div class="layui-input-inline" class="time"style="padding-right: 15px;width: 100px">
                <input type="text" class="layui-input" id="end" name="timeArea" readonly="readonly" value="">
            </div>
            <input type="checkbox" name="sub_order" id="sub_order" title="包含子单" checked value="1">
            <input type="hidden" id="did" value="{$did}">
            <button class="layui-btn layui-btn-primary cus-model-btn" id="sub" >
                查询
            </button>
            <button class="layui-btn layui-btn-primary cus-model-btn" onclick="tableExcel('网络部数据统计.xls')">
                导出
            </button>
        </div>
        <div class="tableexcel">
        <table class="layui-table" lay-data="{height:'',url:'', page:false, id:'idTest',skin: 'row', even: true,loading:true}" lay-filter="demo">
            <thead>
            <tr class="noExl">
                <th lay-data="{width:70,field:'id',align:'center',templet: '#titleTpl'}">序号</th>
                <th lay-data="{width:150,field:'channel_name'}">渠道</th>
                <th lay-data="{width:100,field:'all_number',templet: '#mkz',sort: true}">毛客资</th>
                <th lay-data="{width:100,field:'youxiao_number',sort: true}">有效客资</th>
                <th lay-data="{width:100,field:'wuxiao_number'}">无效客资</th>
                <th lay-data="{width:100,field:'tel_number'}">电话量</th>
                <th lay-data="{width:100,field:'order_number',sort: true}">新单[邀约量]</th>
                <th lay-data="{width:100,field:'photo_number',sort: true}">拍摄量[到店量]</th>
                <th lay-data="{width:100,field:'photo_number_gq'}">拍摄改期</th>
                <!-- <th lay-data="{width:100,field:'photo_number_all'}">拍摄+改期</th> -->

                <th lay-data="{width:100,field:'sp_number',sort: true}">选片量</th>
                <th lay-data="{width:200,field:'first_payment_money'}">第一次拍摄金额</th>
                <th lay-data="{width:200,field:'first_shixiao'}">第一次实销金额</th>
                <th lay-data="{width:100,field:'payment_money_houqi',sort: true,templet: '#spyj'}">选片业绩[二销实收-退款]</th>
                <th lay-data="{width:100,field:'payment_money_houqi_avg',sort: true,templet: '#spavg'}">选片单价</th>
                <!-- <th lay-data="{width:100,field:'payment_money_qianqi_order',sort: true}">1111111</th> -->
                <th lay-data="{width:100,field:'payment_money_houqi_sx_avg',templet: '#spsxavg',sort: true}">选片实销单价</th>

                <th lay-data="{width:200,field:'payment_money_qianqi_avg'}">一销单价</th>
                <th lay-data="{width:200,field:'yixiao_rate',templet: '#yxcjl'}">一销成交率</th>
                <th lay-data="{width:100,field:'sx_rate',templet: '#spsxl',sort: true}">选片实销率</th>
                <th lay-data="{width:100,field:'erxiao_rate',templet: '#excjl',sort: true}">选片成交率</th>
                <th lay-data="{width:100,field:'vip_rate',templet: '#spczl'}">选片充值率</th>
                <th lay-data="{width:100,field:'xd_rate',templet: '#spxdl'}">选片续订率</th>
                <th lay-data="{width:100,field:'payment_money_vip'}">选片充值业绩</th>
                <th lay-data="{width:100,field:'payment_money_vip_avg'}">选片充值均价</th>
                <th lay-data="{width:100,field:'payment_money_houqi_xd'}">选片续订业绩</th>
                <th lay-data="{width:100,field:'payment_money_houqi_xd_avg'}">选片续订均价</th>
                <th lay-data="{width:200,field:'payment_money_fc1',sort: true,templet: '#zyjfc1'}">业绩[1服次实收-退款]</th>
                <th lay-data="{width:200,field:'payment_money_qianqi'}">一销业绩</th>
                <th lay-data="{width:200,field:'payment_money',sort: true,templet: '#zyj'}">总业绩[实收-退款]</th>
            </tr>
            </thead>
        </table>
        </div>
        <script type="text/html" id="titleTpl">
            {{d.LAY_TABLE_INDEX}}
        </script>
        <script type="text/html" id="spsxavg">
            {{# if (d.payment_money_houqi_sx_avg)  {}}
            {{parseFloat(d.payment_money_houqi_sx_avg).toFixed(2)}}
            {{# } }}
        </script>
        <script type="text/html" id="spsxyj">
            {{# if (d.payment_money_houqi_sx)  {}}
            {{parseFloat(d.payment_money_houqi_sx).toFixed(2)}}
            {{# } }}
        </script>
        <script type="text/html" id="spavg">
            {{# if (d.payment_money_houqi_avg)  {}}
            {{parseFloat(d.payment_money_houqi_avg).toFixed(2)}}
            {{# } }}
        </script>
        <script type="text/html" id="spyj">
            {{# if (d.payment_money_houqi)  {}}
            {{parseFloat(d.payment_money_houqi).toFixed(2)}}
            {{# } }}
        </script>
        <script type="text/html" id="zyjfc1">
            {{# if (d.payment_money_fc1)  {}}
            {{parseFloat(d.payment_money_fc1).toFixed(2)}}
            {{# } }}
        </script>
        <script type="text/html" id="zyj">
            {{# if (d.payment_money)  {}}
            {{parseFloat(d.payment_money).toFixed(2)}}
            {{# } }}
        </script>
        <script type="text/html" id="mkz">
            {{# if(d.all_number) { }}
            <a href="#3" class="show_detail" field='all_number' id ="{{d.customer_channel_id}}">{{d.all_number}}</a>
            {{# } }}
        </script>
        <script type="text/html" id="yxcjl">
            {{# if(d.yixiao_rate) { }}
            {{d.yixiao_rate}}%
            {{# }else{ }}
                -
            {{# } }}
        </script>
        <script type="text/html" id="excjl">
            {{# if(d.erxiao_rate) { }}
            {{parseFloat(d.erxiao_rate).toFixed(2)}}%
            {{# }else{ }}
                -
            {{# } }}
        </script>
        <script type="text/html" id="spczl">
            {{# if(d.vip_rate) { }}
            {{d.vip_rate}}%
            {{# }else{ }}
                -
            {{# } }}
        </script>
        <script type="text/html" id="spxdl">
            {{# if(d.xd_rate) { }}
            {{d.xd_rate}}%
            {{# }else{ }}
                -
            {{# } }}
        </script>
        <script type="text/html" id="spsxl">
            {{# if(d.sx_rate) { }}
            {{parseFloat(d.sx_rate).toFixed(2)}}%
            {{# }else{ }}
                -
            {{# } }}
        </script>
    </div>
</div>
<script type="text/javascript">
    function tableExcel(filename){
        $(".tableexcel").table2excel({
            exclude: ".noExl",//class="noExl"的列不导出
            name: "Excel Document Name",
            filename: filename,//文件名称
            fileext: ".xls",//文件后缀名
            exclude_img: true,//导出图片
            exclude_links: true,//导出超链接
            exclude_inputs: true//导出输入框内容
        });
    }
    //日历
    layui.use('laydate', function () {
        var laydate = layui.laydate;
        laydate.render({
            elem: '#start'
            ,format: 'yyyy-MM-dd'
            ,max:0
            ,value:new Date()
        });
        laydate.render({
            elem: '#end'
            ,format: 'yyyy-MM-dd'
            ,max:0
            ,value:new Date()
        });
    });
    // 数据表格
    layui.use(['laydate', 'laypage', 'layer', 'table', 'carousel', 'upload', 'element','form'], function(){
        var laydate  = layui.laydate, //日期
                laypage  = layui.laypage //分页
        layer    = layui.layer, //弹层
                table    = layui.table, //表格
                carousel = layui.carousel, //轮播
                upload   = layui.upload, //上传
                element  = layui.element; //元素操作
        var form = layui.form;
        form.on('select(add_shop)', function(data){
            $("#add_staff_id").empty();
            if(data.value){
                // $('#add_staff_id').html('<option value="">请选择员工</option>');
                form.render();
                $.ajax({
                    type: "POST",
                    url: '/crm/Customer/getShopStaffs',
                    data:{shop_code:data.value},
                    success: function (res) {
                       // alert(typeof res);return ;
                        if('object' == typeof res ){
                            var option = '<option value="">请选择员工</option>';
                            for (var i = res.length - 1; i >= 0; i--) {
                                option = option + '<option value="'+res[i].id+'">'+res[i].staffname+'</option>'
                            }
                            $('#add_staff_id').append(option);
                            form.render();
                        }
                    },
                    error:function(){
                        layer.alert('获取人员失败，请重试。');
                    }
                });
            }else{
                form.render();
            }
        })
        form.on('select(sales_shop)', function(data){
            $("#sales_staff_id").empty();
            if(data.value){
                // $('#sales_staff_id').html('<option value="">请选择员工</option>');
                form.render();
                $.ajax({
                    type: "POST",
                    url: '/crm/Customer/getShopStaffs',
                    data:{shop_code:data.value},
                    success: function (res) {
                       // alert(typeof res);return ;
                        if('object' == typeof res ){
                            var option = '<option value="">请选择员工</option>';
                            for (var i = res.length - 1; i >= 0; i--) {
                                option = option + '<option value="'+res[i].id+'">'+res[i].staffname+'</option>'
                            }
                            $('#sales_staff_id').append(option);
                            form.render();
                        }
                    },
                    error:function(){
                        layer.alert('获取人员失败，请重试。');
                    }
                });
            }else{
                form.render();
            }
        })
        //分页
        laypage.render({
            elem: 'pageDemo' //分页容器的id
            ,count: 100 //总页数
            ,skin: '#1E9FFF' //自定义选中色值
            // ,skip: true //开启跳页
            ,jump: function(obj, first){
                if(!first){
                    layer.msg('第'+ obj.curr +'页');
                }
            }
        });
    })

    // 查询按钮
    $("#sub").click(function(){
        // 生成表格
        var start   = $('#start').val();
        var end   = $('#end').val();
        var did   = $('#did').val();
        var dj_staff_id   = $('#add_staff_id').val();
        var shop_code   = $('#shop_code').val();
        var add_shop_code   = $('#add_shop_code').val();
        var sales_staff_id   = $('#sales_staff_id').val();
        var sales_staff = $('#sales_staff_id').find("option:selected").text();
        var where = {id:'Customer_channel_data',start:start,end:end,did:did};
        if($('#sub_order').is(':checked')){
            where.sub_order = 1;
        }else{
            where.sub_order = 0;
        }
        
        if(dj_staff_id){
            where.dj_staff_id = dj_staff_id;
        }else{
            where.dj_staff_id = '';
        }
        if(sales_staff_id){
            where.sales_staff_id = sales_staff_id;
            where.sales_staff = sales_staff;
        }else{
            where.sales_staff_id = '';
        }
        if(shop_code){
            where.shop_code = shop_code;
        }else{
            where.shop_code = '';
        }
        if(add_shop_code){
            where.add_shop_code = add_shop_code;
        }else{
            where.add_shop_code = '';
        }
        if (!start || typeof(start)=='undefined' || start.length <= 0) {
            layer.alert('请选择开始时间');
            return false;
        }
        if (!end || typeof(end)=='undefined' || end.length <= 0) {
            layer.alert('请选择结束时间');
            return false;
        }
        var index = layer.load(1, {shade: false}); //0代表加载的风格，支持0-2
        // 重新载入表格
        table.reload('idTest', {
            url: '/crm/Report/data.html',
            where: where, //设定异步数据接口的额外参数
            done: function(res, curr, count){
                layer.close(index);
                /*
                
                $(".show_detail").each(function(){
                    $(this).click(function(){
                         alert($(this).attr('id'));
                         return ;
                    });
                });
                */
            }
        });
    });

</script>
{/block}