{extend name="Public/base"/}
{block name="js"}
<script src="__PUBLIC__/js/echarts.online.js?v={$Think.const.APP_VERSION}"></script>
<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">部门(店)：</label>
            <div class="layui-input-inline" style="width: 130px;">
                <select name="shop" id="shop" lay-filter="shop" lay-search="">
                    <option value="">请选择</option>
                    {volist name="shop" id="vo"}
                    <option value="{$vo.shop_code}"{if $Think.session.shop_code eq $vo.shop_code}selected{/if}>{$vo.shop_name}</option>
                    {/volist}
                </select>
            </div>-->

            <label style="width:70px;" class="layui-form-label mkz_t1" style="width:50px;">开始日期：</label>
            <div class="layui-input-inline w-120" class="time">
                <input type="text" class="layui-input" id="start" name="timeArea" readonly="readonly" value="">
            </div>
            <label style="width:70px;padding-right: 10px;" class="layui-form-label mkz_t1">结束日期：</label>
            <div class="layui-input-inline w-120" class="time"style="padding-right: 15px;">
                <input type="text" class="layui-input" id="end" name="timeArea" readonly="readonly" value="">
            </div>


            <label style="width:55px;" class="layui-form-label mkz_t1">渠道：</label>
            <div class="layui-input-inline">
                <select name="channel_id" id="channel_id" lay-filter="channel_id" lay-search="">
                    <option value="0">请选择</option>
                    {volist name="channel" id="vo"}
                    <option value="{$vo.id}">{$vo.channel_name}</option>
                    {/volist}
                </select>
            </div>

            <label style="width:55px;" class="layui-form-label mkz_t1">城市：</label>
            <div class="layui-input-inline">
                <select name="city_id" id="city_id" lay-filter="city_id" lay-search="">
                    <option value="0">请选择</option>
                    {volist name="address" id="vo"}
                    <option value="{$vo.id}">{$vo.name}</option>
                    {/volist}
                </select>
            </div>

            <label style="width:80px;" class="layui-form-label mkz_t1">专员：</label>
            <div class="layui-input-inline">
                <select name="staff_id" id="staff_id" lay-filter="staff_id" lay-search="">
                    <option value="0">请选择</option>
                    {volist name="staff" id="vo"}
                    <option value="{$vo.id}">{$vo.staffname}</option>
                    {/volist}
                </select>
            </div>


            <input type="hidden" id="did" value="{$did}">
            <button class="layui-btn layui-btn-primary cus-model-btn" id="sub" style="margin-left: 50px;">
                查询
            </button>

            <button class="layui-btn layui-btn-primary cus-model-btn" onclick="table2Excel('推广每日数据统计.xls')">
                <i class="iconfont"></i> 导出
            </button>
        </div>
        <div v-show="show==0" class="table2excel">
        <table class="layui-table" lay-data="{height:750,url:'/crm/Report/data.html?id=qqbaby_kf_data', page:false, id:'idTest',skin: 'row', even: true,loading:true,totalRow:true}" lay-filter="demo">
            <thead>
            <tr>

                <th lay-data="{width:100,field:'date'}">日期</th>
                <th lay-data="{width:100,sort:true,field:'staff_name'}">专员</th>
                <th lay-data="{width:100,sort:true,field:'channel_name'}">渠道</th>
                <th lay-data="{width:100,sort:true,field:'city_name'}">城市</th>

                <th lay-data="{width:100,sort:true,field:'subscribe_num',templet:'#subscribe_num'}">关注量</th>
                <th lay-data="{width:100,sort:true,field:'unsubscribe_num',templet:'#unsubscribe_num'}">取关量</th>
                <th lay-data="{width:130,sort:true,field:'chat_num',templet:'#chat_num'}">有效对话量</th>
                <th lay-data="{width:130,sort:true,field:'chat_lv',templet:'#chat_lv'}">有效对话率</th>

                <th lay-data="{width:100,sort:true,field:'all_kz'}">客资量</th>
                <th lay-data="{width:100,sort:true,field:'kz_lv',templet:'#kz_lv'}">获取率</th>
            </tr>
            </thead>
        </table>
        </div>
        <script type="text/html" id="subscribe_num">
        {{d.subscribe_num > 0 ?d.subscribe_num : 0}}
        </script>

        <script type="text/html" id="unsubscribe_num">
            {{d.unsubscribe_num > 0 ?d.unsubscribe_num : 0}}
        </script>

        <script type="text/html" id="chat_num">
            {{d.chat_num > 0 ?d.chat_num : 0}}
        </script>

        <script type="text/html" id="chat_lv">
            {{d.chat_lv > 0 ?d.chat_lv : '0.00'}}
        </script>

        <script type="text/html" id="all_kz">
            {{d.all_kz > 0 ?d.all_kz : 0}}
        </script>

        <script type="text/html" id="kz_lv">
            {{d.kz_lv > 0 ?d.kz_lv : '0.00'}}
        </script>

        <hr />
    </div>
</div>
<script type="text/javascript">
    $(function(){
        var shop = $('#shop').val();

    })
    //日历
    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, //表格
        form     = layui.form,
        carousel = layui.carousel, //轮播
        upload   = layui.upload, //上传
        element  = layui.element; //元素操作
    //分页
    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 shop_code = $('#shop').val();
    var city_id = $('#city_id').val();
    var city_name = $('#city_id option:selected').val();
    var channel_id = $('#channel_id').val();
    var channel_name = $('#channel_id option:selected').html();
    var staff_id = $('#staff_id').val();
    var staff_name = $('#staff_id option:selected').html();
    var start   = $('#start').val();
    var end   = $('#end').val();
    var did   = $('#did').val();

    if (!start || typeof(start)=='undefined' || start.length <= 0) {
        layer.alert('请选择开始时间');
        return false;
    }

    var index = layer.load(1, {shade: false}); //0代表加载的风格，支持0-2 
    // 重新载入表格
    table.reload('idTest', {
        url: '/crm/Report/data.html',
        totalRow:true,
        where: {id:'qqbaby_kf_data',channel_id:channel_id,channel_name:channel_name,city_id:city_id,city_name:city_name,start:start,end:end,staff_id:staff_id,staff_name:staff_name,did:did}, //设定异步数据接口的额外参数
        done: function(res, curr, count){
            layer.close(index);
        }
    });
});

    function table2Excel(filename){
        $(".table2excel").table2excel({
            exclude: ".noExl",//class="noExl"的列不导出
            name: "Excel Document Name",
            filename: filename,//文件名称
            fileext: ".xls",//文件后缀名
            exclude_img: true,//导出图片
            exclude_links: true,//导出超链接
            exclude_inputs: true//导出输入框内容
        });
    }
</script>
{/block}