<div class="content_wrapper">
<style>
    .btn-name {
        white-space: nowrap;
    }
</style>
    <div class="container-fluid">
        <div id="msg-tip"></div>
        <div class="row">
            <div class="col-sm-12">
                <aside>
                    <section>
                        <div class="container-fluid">
                            <div class="row">
                                <div class="col-sm-12">
                                    <button style="margin:5px;" class="btn btn-primary" onclick="refreshActivityMd5()" role="button">刷新活动图片MD5配置</button>
                                </div>
                            </div>
                        </div>
                    </section>
                </aside>
            </div>
        </div>
        <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">
                                    <div class="btn-group" style="margin-bottom:20px;">
                                        <a class="btn btn-success" href="#activity/add?id=<?php echo $max_id+1;?>" role="button">添加活动</a>
                                    </div>
<!--                                    <div class="btn-group" style="margin-bottom:20px;">-->
<!--                                        <input class="btn btn-primary" type="button" value="登录时是否弹出活动弹窗" id="showActivity"/>-->
<!--                                    </div>-->
                                    <div class="table-responsive">
                                        <table id="example" class="table table-striped table-bordered table-hover" cellspacing="0" width="100%">
                                            <thead>
                                            <tr>
                                                <th>活动ID</th>
                                                <th>活动名称</th>
                                                <th>活动名称(英文)</th>
<!--                                                <th>图片</th>-->
                                                <th>开始时间</th>
                                                <th>结束时间</th>
                                                <th>排序</th>
                                                <th>是否上线</th>
                                                <th>状态</th>
                                                <th>操作</th>
                                            </tr>
                                            </thead>
                                            <tbody>
                                            <?php
                                            if(is_array($list)  && !empty($list)){
                                                foreach ($list['list'] as $key => $vl) { ?>
                                                    <tr>
                                                        <td><?php echo $vl['id'];?></td>
                                                        <td><?php echo $vl['name'];?></td>
                                                        <td><?php echo $vl['name_en']; ?></td>
<!--                                                        <td>--><?php //echo $vl['image']; ?><!--</td>-->
                                                        <td><?php echo date('Y-m-d H:i:s',$vl['start_time']);?></td>
                                                        <td><?php echo date('Y-m-d H:i:s',$vl['end_time']);?></td>
                                                        <td><?php echo $vl['sort'];?></td>
                                                        <td><?php echo $vl['is_online'] == 1 ?  '<span class="label label-success">是</span>' : '<span class="label label-default">否</span>';?></td>
                                                        <td><?php echo $vl['status'] == 1 ?  '<span class="label label-success">开始</span>' : '<span class="label label-default">停止</span>';?></td>
                                                        <td>
                                                            <a href="#activity/edit/<?php echo $vl['id'];?>" class="btn btn-primary active" role="button">编辑</a>
                                                            <button class="btn btn-success" role="button" onclick="refreshActivity(<?php echo $vl['id'];?>)">刷新活动数值</button>
                                                            <?php if(in_array($vl['id'],[2,6,7, 8,9,13,14,16])){?> <a href="#activity/config/<?php echo $vl['id'];?>" class="btn btn-danger" role="button">配置</a> <?php }?>
                                                        </td>
                                                    </tr>
                                                <?php }
                                            } else{?>
                                            <tr>
                                                <td colspan="10">暂无数据</td>
                                            </tr>
                                            <?php } ?>
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </section>
                </aside>
            </div>
        </div>
    </div>

</div>

<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <img src="" />
        </div>
    </div>
</div>

<!-- Modal -->
<div class="modal fade" id="showModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                <h4 class="modal-title" id="myModalLabel">活动弹窗设置</h4>
            </div>
            <div id="modal-msg-tip"></div>
            <form class="form-horizontal" role="form" method="post" action="#">
                <div class="modal-body">
                    <div class="form-group">
                        <label class="col-sm-5 control-label">是否在登录时弹出活动弹窗:</label>
                        <label class="radio-inline">
                            <input type="radio" name="showActivity"  value="1" <?php if($showActivity) echo 'checked';?> > 是
                        </label>
                        <label class="radio-inline">
                            <input type="radio" name="showActivity"  value="0" <?php if(!$showActivity) echo 'checked';?> > 否
                        </label>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary" id="submitBtn">提交</button>
                </div>
            </form>
        </div>
    </div>
</div>
<script src="<?php echo base_url();?>public/js/common.js"></script>
<script>

    //点击图片，显示大图
    $('.img-show').click(function () {
        var imgPath = $(this).attr('src');
        $('#myModal img').attr('src', imgPath);
       $('#myModal').modal();
    });

    //登录时是否弹出活动弹窗
    $('#showActivity').click(function () {
        $('#showModal').modal();
    });

    $('#submitBtn').click(function () {
        var showActivity = $('input[name="showActivity"]:checked').val();
        var modalMsgTip = $('#modal-msg-tip');
        var msgTip = $('#msg-tip');
        var _this = $(this);
        _this.attr('disabled', true);
        $.ajax({
            url: rootPath + 'activity/showActivity',
            type: 'POST',
            data: {
                'showActivity':showActivity
            },
            dataType: 'json',
            success: function (data) {
                if(data.ret != 0) {//修改失败
                    modalMsgTip.messager().error(data.msg);
                    _this.attr('disabled', false);
                }else{
                    _this.attr('disabled', false);
                    msgTip.messager().success(data.msg);
                    $('#showModal .close').click();
                }
            },
            error: function (msg) {
                modalMsgTip.messager().error('网络错误，请刷新后重试');
            }
        }) ;
    });
    
    function refreshActivity(id) {
        $.ajax({
            url: rootPath + 'activity/refreshActivity',
            type: 'POST',
            data: {
                'id':id
            },
            dataType: 'json',
            success: function (data) {
                alert(data.msg);
            },
            error: function (msg) {
                alert(data.msg);
            }
        }) ;
    }

    function refreshActivityMd5(){
        if( confirm('确认刷新活动图片Md5配置吗?') ) {
            $.post('/activity/refreshActivityMd5', {
                id: 1
            }, function (data) {
                alert("刷新成功")
            });
        }
    }

</script>