<link rel="stylesheet" href="<?php echo base_url();?>public/node_modules/bootstrap-select/dist/css/bootstrap-select.min.css">
<script src="<?php echo base_url();?>public/node_modules/bootstrap-select/dist/js/bootstrap-select.min.js"></script>
<link rel="stylesheet" href="<?php echo base_url();?>public/css/vendor/bootstrap/bootstrap-table.css">
<link rel="stylesheet" href="<?php echo base_url();?>public/css/vendor/bootstrap/table-fix-column.css">

<script src="<?php echo base_url();?>public/js/vendor/bootstrap/src/bootstrap-table.js"></script>
<script src="<?php echo base_url();?>public/js/vendor/bootstrap/src/table-fix-column.js"></script>
<style type="text/css">
    table {
        table-layout:fixed !important;
    }

    th{
        background: rgb(146, 208, 80);
    }

    td,th{
        /*max-width: 400px;*/
        word-wrap: break-word;
    }
    /*
    .fixed-table-header .table{
        height: 100px;
    }
    */

    table{
        table-layout:auto !important;
    }
    th{
        /*height: 100px;*/
    }

    .table-hover > tbody > tr:hover {
        background-color: #c8bd6d;
    }

    input {
        width:60px;
    }

    #roleTable tr:nth-child(5n){
        /*background:rgb(198, 239, 206);*/
    } /**隔五行*/

    .fixed-table-toolbar {
        display: none;
    }
    .fileinput-button {
        position: relative;
        top: -5px;
    }

    .fileinput-button input{
        position:absolute;
        right: 0px;
        top: 0px;
        opacity: 0;
        -ms-filter: 'alpha(opacity=0)';
    }


    <?php foreach ($redIndex as $idx) { ?>
    #reportBody tr td:nth-child(<?=$idx+2?>),
    <?php }?>
    #reportBody tr td:nth-child(0){
        color:red !important;
    }
    .fixed-table-body{
        /*overflow-x: visible;*/
        /*overflow-y: visible;*/
        /*height: auto;*/
    }
    #roleTable{
        margin-top: -41px !important;
    }
</style>
<div class="content_wrapper">
    <div class="container-fluid">
        <div class="row">
            <div class="col-sm-12">
                <aside>
                    <header><i class="fa fa-fw fa-file"></i><?php echo $title; ?></header>
                    <section>
                        <div class="container-fluid">
                            <div class="row">
                                <div class="col-sm-12">
                                    <form class="form-inline" role="form" method="POST" action="#adjuststa/dayReportView2" name="stanpform">
                                        <span class="gap"></span>
                                        <div class="form-group">
                                            <label>开始时间</label>
                                            <input type="text" class="form-control datetimepicker" value="<?php if($stime) echo $stime;?>" placeholder="结束时间" name="stime" />
                                        </div>
                                        <span class="gap"></span>
                                        <div class="form-group">
                                            <label>结束时间</label>
                                            <input type="text" class="form-control datetimepicker" value="<?php if($etime) echo $etime;?>" placeholder="结束时间" name="etime" />
                                        </div>
                                        <span class="gap"></span>
                                        <div class="form-group">
                                            <label>版本</label>
                                            <select class="form-control" name="user_os">
                                                <option value="all" <?php echo $user_os == ""?"selected":""; ?> >all</option>
                                                <option value="android" <?php echo $user_os == "android"?"selected":""; ?> >android</option>
                                                <option value="ios" <?php echo $user_os == "ios"?"selected":""; ?> >ios</option>
                                                <option value="windows" <?php echo $user_os == "windows"?"selected":""; ?> >windows</option>
                                            </select>
                                        </div>
                                        <span class="gap"></span>
                                        <div class="form-group addressTemp_group <?=$trackers_group_type?>"  <?php if(in_array($trackers_group_type, ['Google_ads'])){ ?> style="display: none;" <?}?>>
                                            <label>国家</label>
                                            <select class="selectpicker bla bla bli" multiple data-live-search="true" id="addressTemp">
                                                <option value="all" <?php echo $address == "all"?"selected":""; ?> >all</option>
                                                <?php
                                                foreach($addressList as $row){
                                                    $addressTempL = strtolower($row['code']);
                                                    $name = $row["country_name"];
                                                    echo '<option value="'.($addressTempL).'" '.($address == $addressTempL?"selected":"").'>'.$row['code'].'('.$name.')</option>';
                                                }
                                                ?>
                                            </select>
                                            <input type="hidden" name="address">
                                        </div>
                                        <span class="gap"></span>
                                        <div class="form-group">
                                            <label>展示列</label>
                                            <select class="selectpicker bla bla bli" multiple data-live-search="true" id="columns">
                                                <option value="all" <?php if(in_array('all', $columns))echo 'selected'; ?> >all</option>
                                                <?php
                                                foreach($headerTable as $row){ if($row == '日期')continue; ?>
                                                    <option value="<?=$row?>" <?php if(in_array($row, $columns))echo 'selected'; ?> ><?=$row?>  </option>
                                                <?php
                                                }
                                                ?>
                                            </select>
                                            <input type="hidden" name="columns">
                                        </div>
                                        <span class="gap"></span>
                                        <div class="form-group">
                                            <label>标红列</label>
                                            <select class="selectpicker bla bla bli" multiple data-live-search="true" id="redColumns">
                                                <option value="all" <?php if(in_array('all', $redColumns))echo 'selected'; ?> >all</option>
                                                <?php
                                                foreach($headerTable as $row){ if($row == '日期')continue; ?>
                                                    <option value="<?=$row?>" <?php if(in_array($row, $redColumns))echo 'selected'; ?> ><?=$row?>  </option>
                                                <?php
                                                }
                                                ?>
                                            </select>
                                            <input type="hidden" name="redColumns">
                                        </div>
                                        <span class="gap"></span>
                                        <div class="form-group">
                                            <label>广告渠道</label>
                                            <select class="form-control" name="trackers_group_type" id="trackers_group_type">
                                                <?php foreach($channels as $channel){ ?>
                                                    <option value="<?=$channel?>" <?php echo $trackers_group_type == "$channel"?"selected":""; ?> ><?=$channel?></option>
                                                <?php } ?>
<!--                                                <option value="Facebook" --><?php //echo $trackers_group_type == "Facebook"?"selected":""; ?><!-- >Facebook</option>-->
<!--                                                <option value="Google_ads" --><?php //echo $trackers_group_type == "Google_ads"?"selected":""; ?><!-- >Google_ads</option>-->
<!--                                                <option value="IronSource" --><?php //echo $trackers_group_type == "IronSource"?"selected":""; ?><!-- >IronSource</option>-->
<!--                                                <option value="Unity" --><?php //echo $trackers_group_type == "Unity"?"selected":""; ?><!-- >Unity</option>-->
<!--                                                <option value="Applovin" --><?php //echo $trackers_group_type == "Applovin"?"selected":""; ?><!-- >Applovin</option>-->
<!--                                                <option value="Chartboost" --><?php //echo $trackers_group_type == "Chartboost"?"selected":""; ?><!-- >Chartboost</option>-->
<!--                                                <option value="Mintegral" --><?php //echo $trackers_group_type == "Mintegral"?"selected":""; ?><!-- >Mintegral</option>-->
<!--                                                <option value="Tecdo" --><?php //echo $trackers_group_type == "Tecdo"?"selected":""; ?><!-- >Tecdo</option>-->
<!--                                                <option value="Inplayable" --><?php //echo $trackers_group_type == "Inplayable"?"selected":""; ?><!-- >Inplayable</option>-->
                                            </select>
                                        </div>
                                        <span class="gap"></span>
                                        <div class="form-group campaign_id_group">
                                            <label>广告系列</label>
                                            <select class="selectpicker bla bla bli" data-live-search="true" id="campaign_id">
                                                <option value="all" <?php echo $campaign_id == "all"?"selected":""; ?> >all</option>
                                                <?php
                                                foreach($campaignList as $row){
                                                    echo '<option value="'.$row["campaigns_id"].'" '. ($campaign_id == $row["campaigns_id"]?"selected":""). ' >'.$row["campaigns_name"].'</option>';
                                                }
                                                ?>
                                            </select>
                                            <input type="hidden" name="campaign_id">
                                        </div>
                                        <span class="gap"></span>
                                        <div class="form-group adset_id_group" <?php if(!in_array($trackers_group_type, ['Facebook','Google_ads','Mintegral','TikTok','苹果商店页搜索广告'])){ ?> style="display: none;" <?}?>>
                                            <label>广告组</label>
                                            <select class="selectpicker bla bla bli" data-live-search="true" id="adset_id">
                                                <option value="all" <?php echo $adset_id == "all"?"selected":""; ?> >all</option>
                                                <?php
                                                foreach($adsetList as $row){
                                                    echo '<option value="'.$row["adgroups_id"].'" '. ($adset_id == $row["adgroups_id"]?"selected":""). ' >'.$row["adgroups_name"].'('.$row["adgroups_id"].')'.'</option>';
                                                }
                                                ?>
                                            </select>
                                            <input type="hidden" name="adset_id">
                                        </div>
                                        <span class="gap"></span>

                                        <div class="form-group ad_id_group" <?php if(!in_array($trackers_group_type, ['Facebook','Google_ads','Mintegral','TikTok'])){ ?> style="display: none;" <?}?>>
                                            <label>广告</label>
                                            <select class="selectpicker bla bla bli" data-live-search="true" id="ad_id">
                                                <option value="all" <?php echo $ad_id == "all"?"selected":""; ?> >all</option>
                                                <?php
                                                foreach($adList as $row){
                                                    echo '<option value="'.$row["creatives_id"].'" '. ($ad_id == $row["creatives_id"]?"selected":""). ' >'.$row["creatives_name"].'('.$row["creatives_id"].')'.'</option>';
                                                }
                                                ?>
                                            </select>
                                            <input type="hidden" name="ad_id">
                                        </div>
                                        <span class="gap"></span>
                                        <button type="submit" class="btn btn-primary">查询</button>
                                        <button type="button" class="btn btn-success" onclick="show(1)">导出</button>
                                    </form>
                                </div>
                            </div>

                        </div>
                    </section>
                </aside>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <aside>
                    <a href="#adjuststa/dayReportView2/DESC" class="btn btn-success" target="_self">日期降序</a>
                    <a href="#adjuststa/dayReportView2/ASC" class="btn btn-success" target="_self">日期升序</a>
                </aside>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <aside>
                    <div class="table-responsive">
                        <table id="roleTable" class="table table-bordered table-hover"
                               data-toggle="table"
                               data-classes="table table-hover"
                               data-show-columns="true"
                               data-striped="true"
                               data-height="700" style="overflow: hidden;text-overflow: ellipsis;white-space: nowrap">
                            <thead>
                            <tr>
                                <th style="text-align: center;vertical-align: middle;width:200px;">日期</th>
                                <?php
                                foreach($showColumns as $key => $name){
                                    echo '<th>'.$name.'</th>';
                                }
                                ?>
                            </tr>
                            </thead>
                            <tbody id="reportBody">
                            <?
                            if(!empty($list)){
                                foreach($list as $date => $vos){
                                    foreach($vos as $vo){
                                        echo "<tr>";
                                        echo  '<td style="text-align: center;vertical-align: middle;width:200px;">'.$date.'</td>';
                                        foreach($showColumns as $showColumn){
                                            echo  '<td style="text-align: center;vertical-align: middle;width:200px;">'.$vo[$showColumn].'</td>';
                                        }
                                        echo "</tr>";
                                    }
                                }
                            }
                            ?>
                            </tbody>
                        </table>
                    </div>
                </aside>
            </div>
        </div>


    </div>
</div>
</div>
<script src="<?php echo base_url();?>public/js/common.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
        $('.selectpicker').selectpicker({
            'selectedText': 'cat'
        });
        $('#addressTemp').selectpicker('val',['<?php echo is_array($address)?implode("','",$address):$address;?>']);
        $('#campaign_id').selectpicker('val',['<?php echo $campaign_id;?>']);
        $('#adset_id').selectpicker('val',['<?php echo $adset_id;?>']);
        $('#ad_id').selectpicker('val',['<?php echo $ad_id;?>']);
        $('#columns').selectpicker('val',['<?php echo is_array($columns)?implode("','",$columns):$columns;?>']);
        $('#redColumns').selectpicker('val',['<?php echo is_array($redColumns)?implode("','",$redColumns):$redColumns;?>']);
    });
    $('#addressTemp').on('changed.bs.select',function(e){
        // alert($(this).val());
        $("input[name='address']").val($(this).val());
    });
    $('#campaign_id').on('changed.bs.select',function(e){
        // alert($(this).val());
        $("input[name='campaign_id']").val($(this).val());
    });
    $('#adset_id').on('changed.bs.select',function(e){
        // alert($(this).val());
        $("input[name='adset_id']").val($(this).val());
    });
    $('#ad_id').on('changed.bs.select',function(e){
        // alert($(this).val());
        $("input[name='ad_id']").val($(this).val());
    });
    $('#columns').on('changed.bs.select',function(e){
        // alert($(this).val());
        $("input[name='columns']").val($(this).val());
    });
    $('#redColumns').on('changed.bs.select',function(e){
        // alert($(this).val());
        $("input[name='redColumns']").val($(this).val());
    });

    function show(){
        window.location.href = "/adjuststa/exportAdjustViewData/<?php echo $stime; ?>/<?php echo $etime; ?>/<?php echo $address; ?>/<?php echo $trackers_group_type; ?>/<?php echo $user_os; ?>/<?php echo $campaign_id; ?>/<?php echo $adset_id; ?>/<?php echo $ad_id; ?>/<?php echo $sort; ?>"
    }
</script>
<script type="text/javascript">
    //选择日期
    $('.datetimepicker').datepicker({
        language:'zh-CN',
        format:'yyyy-mm-dd',
        autoclose:true,
        zIndexOffset:906  //控制z-index
    });

    var addressValue = ''
    $(document).on("change","#trackers_group_type",function(){
        var stime = $("input[name='stime']").val();
        var etime = $("input[name='etime']").val();
        var address = addressValue = $("input[name='address']").val();
        var user_os = $("input[name='user_os']").val();
        var channel = $("select[name='trackers_group_type']").val();

        $("input[name='campaign_id']").val('all');
        $("input[name='adset_id']").val('all');
        $("input[name='ad_id']").val('all');
        if(channel == 'Google_ads'){
            $('.addressTemp_group').hide();
            address = 'all'
            $("input[name='address']").val('all')
        }else{
            if(addressValue != ''){
                $('.addressTemp_group').show();
                $("input[name='address']").val(addressValue)
            }
        }
        if(
            channel == 'IronSource'||
            channel == 'Unity'||
            channel == 'Applovin'||
            channel == 'Chartboost'
        ){
            console.log(348)
            $(".adset_id_group").hide()
            $(".ad_id_group").hide()
            return false;
        }else{
            console.log(353)
            $(".adset_id_group").show()
            $(".ad_id_group").show()
        }
        // alert(stime);
        $.ajax({
            type:"post",
            url:"/adjuststa/getThreeType",
            async:false,//设置同步/异步的参数[true异步  false同步]
            data:{"type":"channel","stime":stime,"etime":etime,address:address,user_os:user_os,"channel":channel,"class":channel},
            dataType:"json",
            success:function(data){
                $("#campaign_id").html("");
                $("#campaign_id").append('<option value="all" >all</option>');
                $("#adset_id").html("");
                $("#adset_id").append('<option value="all" >all</option>');
                $("#ad_id").html("");
                $("#ad_id").append('<option value="all" >all</option>');
                if(data.state == "success"){
                    for(var i = 0;i < data.data.length; i++){
                        $("#campaign_id").append('<option value="'+data.data[i].adset_id+'" >'+data.data[i].adset_name+'('+data.data[i].adset_id+')'+'</option>');
                    }
                }
                $('.selectpicker').selectpicker('refresh');
            },
            error:function(e){
                msg=e;
            }
        });
    });

    $(document).on("change","#campaign_id",function(){
        var campaign_id = $(this).val();
        var stime = $("input[name='stime']").val();
        var etime = $("input[name='etime']").val();
        var address = $("input[name='address']").val();
        var user_os = $("input[name='user_os']").val();
        var channel = $("select[name='trackers_group_type']").val();

        // alert(stime);
        $.ajax({
            type:"post",
            url:"/adjuststa/getThreeType",
            async:false,//设置同步/异步的参数[true异步  false同步]
            data:{"type":"campaign","campaign_id":campaign_id,"stime":stime,"etime":etime,address:address,user_os:user_os,"class":channel},
            dataType:"json",
            success:function(data){
                $("#adset_id").html("");
                $("#adset_id").append('<option value="all" >all</option>');
                $("#ad_id").html("");
                $("#ad_id").append('<option value="all" >all</option>');
                if(data.state == "success"){
                    for(var i = 0;i < data.data.length; i++){
                        $("#adset_id").append('<option value="'+data.data[i].adset_id+'" >'+data.data[i].adset_name+'('+data.data[i].adset_id+')'+'</option>');
                    }
                }
                $('.selectpicker').selectpicker('refresh');
            },
            error:function(e){
                msg=e;
            }
        });
    });

    $(document).on("change","#adset_id",function(){
        var adset_id = $(this).val();
        var stime = $("input[name='stime']").val();
        var etime = $("input[name='etime']").val();
        var address = $("input[name='address']").val();
        var user_os = $("input[name='user_os']").val();
        var channel = $("select[name='trackers_group_type']").val();
        // alert(stime);
        if(
            channel == 'Google_ads'
            || channel == 'Mintegral'
        )return;
        $.ajax({
            type:"post",
            url:"/adjuststa/getThreeType",
            async:false,//设置同步/异步的参数[true异步  false同步]
            data:{"type":"adset","adset_id":adset_id,"stime":stime,"etime":etime,address:address,user_os:user_os,"class":channel},
            dataType:"json",
            success:function(data){
                $("#ad_id").html("");
                $("#ad_id").append('<option value="all" >all</option>');
                if(data.state == "success"){
                    for(var i = 0;i < data.data.length; i++){
                        $("#ad_id").append('<option value="'+data.data[i].ad_id+'" >'+data.data[i].ad_name+'('+data.data[i].ad_id+')'+'</option>');
                    }
                }
                $('.selectpicker').selectpicker('refresh');
            },
            error:function(e){
                msg=e;
            }
        });
    });
</script>