<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>

<div class="content_wrapper">
    <div id="msg-tip"></div>
    <div class="container-fluid ">
        <div class="row">
            <div class="col-sm-12">
                <aside>
                    <header><i class="fa fa-fw fa-file"></i>分享配置</header>
                    <section>
                        <div class="container-fluid">
                            <div class="row">
                                <div class="col-sm-12">
                                    <a style="margin:5px;" class="btn btn-primary " href="#config/sharePointListConfig" role="button">翻译配置</a>
                                    <a style="margin:5px;" class="btn btn-primary " href="#config/sharePointListConfig/img" role="button">配图配置</a>
                                </div>
                            </div>
                        </div>
                    </section>
                </aside>
                <aside>
                    <header><i class="fa fa-fw fa-file"></i>配图国家</header>
                    <section>
                        <div class="container-fluid">
                            <div class="row">
                                <div class="col-sm-2">
                                    <select class="form-control" id="lang" onchange="changeLang(this.value)">
                                        <?php foreach ($langList as $langKey=>$row){ ?>
                                            <option value="<?php echo $langKey;?>" <?php if($country == $langKey) echo 'selected';?>><?php echo $row;?></option>
                                        <?php } ?>
                                    </select>
                                </div>
                            </div>
                        </div>
                    </section>
                </aside>
                <aside>
                    <form class="form-horizontal" role="form" method="post" enctype="multipart/form-data"  id="goodForm" action="#" style="margin-top: 20px">
                        <section>
                            <div class="container-fluid">
                                <button type="button" style="margin-bottom: 10px;width: 80px;" class="btn btn-danger" id="commitBtn">提交A/B test配置</button>
                                <a target="_blank" href="<?php echo $href; ?>" type="button" style="margin-bottom: 10px;width: 80px;" class="btn btn-success" >上传图片</a>
                                <div class="row">
                                    <div class="col-sm-12">
                                        <div class="table-responsive">
                                            <table id="roleTable" class="table table-bordered">
                                                <thead>
                                                <tr>
                                                    <th>分享主键</th>
                                                    <th>默认图片标识</th>
                                                    <th>默认图片</th>
                                                    <th>link-A图片标识</th>
                                                    <th>link-A图片</th>
                                                    <th>link-B图片标识</th>
                                                    <th>link-B图片</th>
                                                    <th>状态（A/B）</th>
                                                </tr>
                                                </thead>
                                                <tbody>
                                                <?php
                                                if(is_array($langData)  && !empty($langData)){
                                                    foreach ($langData as $key => $vl) { ?>
                                                        <tr>
                                                            <td><input type="text" class="form-control" readonly value="<?php echo $key;?>"></td>
                                                            <td><input type="text" class="form-control" readonly value="<?php echo $country."-".$key;?>"></td>
                                                            <td><img src="<?php echo ($_SERVER['HTTPS']?"https://":"http://").$_SERVER['HTTP_HOST']."/img/feed/" . $country."/" . $country."-".$key.".jpg?".time(); ?>" height="100px" ></td>
                                                            <td><input type="text" class="form-control" readonly value="<?php echo $country."-".$key."-A";?>"></td>
                                                            <td><img src="<?php echo ($_SERVER['HTTPS']?"https://":"http://").$_SERVER['HTTP_HOST']."/img/feed/" . $country."/" . $country."-".$key."-A.jpg?".time(); ?>" height="100px" ></td>
                                                            <td><input type="text" class="form-control" readonly value="<?php echo $country."-".$key."-B";?>"></td>
                                                            <td><img src="<?php echo ($_SERVER['HTTPS']?"https://":"http://").$_SERVER['HTTP_HOST']."/img/feed/" . $country."/" . $country ."-".$key."-B.jpg?".time(); ?>" height="100px" ></td>
                                                            <td><input class='mySwitch abTest' type="checkbox" name="<?php echo $key;?>" value="<?php echo $vl;?>" <?php if($vl == 1){ echo 'checked';}?>></td>
                                                        </tr>
                                                    <?php } } else{?>
                                                    <tr>
                                                        <td colspan="14">暂无数据</td>
                                                    </tr>
                                                <?php } ?>
                                                </tbody>
                                            </table>
                                        </div>
                                    </div>

                                </div>
                            </div>
                        </section>
                    </form>
                </aside>
            </div>
        </div>
    </div>
</div>


<script>
    //提交表格数据
    $('#commitBtn').click(function () {
        var data = {};
        $('.abTest').each(function(){
            var name  = $(this).attr("name")
            var value = $(this).val()
            data[name]= value
        });
        $.post(rootPath + 'config/sharePointListConfigSetAbTest',{
            country : '<?php echo $country;?>',
            data : data,
        },function (ret) {
            ret = JSON.parse(ret);
            alert(ret.msg);
            // window.location.reload();
        });
    });

    $(".mySwitch").bootstrapSwitch({
        onSwitchChange:function(event, state){
            if(state){
                var state = 1;
            }else{
                var state = 0;
            }
            $(this).val(state);
        }
    });

    function changeLang(value) {
        window.location.href = "/#config/sharePointListConfig/img/"+value;
    }
</script>

