<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>比赛场配置</header>
                    <section>
                        <div class="container-fluid">
                            <div class="row">
                                <div class="col-sm-12">
                                    <div class="btn-group" style="margin-bottom:20px;">
                                        <button type="button" class="btn btn-success" data-toggle="modal" data-target="#actionAdd">添加新比赛场</button>
                                    </div>
                                    <div class="table-responsive">
                                        <table id="example" class="table table-striped table-bordered table-hover" cellspacing="0" width="100%">
                                            <thead>
                                            <tr>
                                                <th>MatchLevel</th>
                                                <th>比赛类型</th>
                                                <th>比赛泰语名称</th>
                                                <th>比赛中文名称</th>
                                                <th>比赛中文繁体名称</th>
                                                <th>比赛英语名称</th>
                                                <th>参数人数</th>
                                                <th>奖励</th>
                                                <th>服务费</th>
                                                <th>参赛费</th>
                                                <th>初始筹码</th>
                                                <th>初始盲注</th>
                                                <th>涨盲时间(s)</th>
                                                <th>是否禁赛</th>
                                                <th>操作</th>
                                            </tr>
                                            </thead>
                                            <tbody>
                                            <?php 
                                                if(is_array($list)){
                                                    foreach ($list as $key => $val) {
                                                      //比赛场名称解析
                                                        $matchInfo = unserialize($val['name']);
                                            ?>
                                            <tr>
                                                <td><?php echo $val['matchlevel'];?></td>
                                                <td><?php echo $val['MatchType'];?></td>
                                                <td><?php echo $matchInfo['matchname'] ?? '';?></td>
                                                <td><?php echo $matchInfo['matchname_zh'] ?? '';?></td>
                                                <td><?php echo $matchInfo['matchname_tw'] ?? '';?></td>
                                                <td><?php echo $matchInfo['matchname_en'] ?? '';?></td>
                                                <td><?php echo $val['MaxUserCount'];?></td>
                                                <td><?php echo $val['matchrewardstr'];?></td>
                                                <td><?php echo $val['service_fee'];?></td>
                                                <td><?php echo $val['TicketMoney'];?></td>
                                                <td><?php echo $val['init_money'];?></td>
                                                <td><?php echo $val['smallblinds'];?></td>
                                                <td><?php echo $val['zhangmang_jiange'];?></td>
                                                <td><?php echo $val['match_disable'] == 0 ? '开启' : '关闭';?></td>
                                                <td>
                                                    <a href="#match/edit/<?php echo $val['matchlevel'];?>" class="btn btn-primary active" role="button">编辑</a>
                                                    <button type="button" class="btn btn-warning closematch" matchlevel="<?php echo $val['matchlevel'];?>" match_disable="<?php echo $val['match_disable'] == 0 ? 1 : 0;?>"><?php echo $val['match_disable'] == 0 ? '关闭' : '开启';?></button>
                                                </td>
                                            </tr>
                                            <?php } } else{?>
                                            <tr>
                                                <td colspan="10">暂无数据</td>
                                            </tr>
                                            <?php } ?>
                                            </tbody>
                                        </table>
                                    </div>
                                    <nav>
                                        <ul class="pagination">
                                            <li class="disabled"><a href="#">共<span class="pagetotal"><?php echo $total;?></span>条</a></li>
                                            <?php echo $pageurl;?>
                                        </ul>
                                    </nav>
                                </div>
                            </div>
                        </div>
                    </section>
                </aside>
            </div>
        </div>
    </div>

</div>

<div class="modal fade" id="actionAdd" 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>
            <form class="form-horizontal J_ajaxForm" role="form" method="post" action="match/actionAdd">
                <div class="modal-body">
                    <div class="form-group">
                        <label class="col-sm-3 control-label">MatchLevel:</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" placeholder="MatchLevel" name="matchlevel">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">比赛场名称:</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" placeholder="比赛场名称" name="matchname">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">比赛场中文名称:</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" placeholder="比赛场中文名称" name="matchname_zh" value="">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">比赛场繁体中文名称:</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" placeholder="比赛场繁体中文名称" name="matchname_tw" value="">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">比赛场英文名称:</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" placeholder="比赛场英文名称" name="matchname_en" value="">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">参数人数:</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" placeholder="参数人数" name="MaxUserCount">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">奖励:</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" placeholder="第一名奖励" name="rewardList[]">
                            <input type="text" class="form-control" placeholder="第二名奖励" name="rewardList[]">
                            <input type="text" class="form-control" placeholder="第三名奖励" name="rewardList[]">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">参赛费:</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" placeholder="参赛费" name="TicketMoney">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">服务费:</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" placeholder="服务费" name="service_fee">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">初始筹码:</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" placeholder="初始筹码" name="init_money">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">初始盲注:</label>
                        <div class="col-sm-9">
                            <textarea class="form-control" rows="5" name="smallblinds" placeholder="逗号分隔"></textarea>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">涨盲时间:</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" placeholder="涨盲时间" name="zhangmang_jiange">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">是否关闭:</label>
                        <div class="col-sm-9">
                            <label class="radio-inline">
                              <input type="radio" name="match_disable" value="1"> 是
                            </label>
                            <label class="radio-inline">
                              <input type="radio" name="match_disable" value="0" checked="checked"> 否
                            </label>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary J_ajaxSubmitBtn">提交</button>
                </div>
            </form>
        </div>
    </div>
</div>


<script>
    //是否停止比赛
    $('.closematch').click(function(){
        var matchlevel = $(this).attr("matchlevel");
        var match_disable = $(this).attr("match_disable");
        console.log(matchlevel);
        console.log(match_disable);
        var strName = (match_disable == 0) ? '开启' : '关闭';
        if( confirm('确定'+strName+'该场次比赛吗?') ){
            $.ajax({
                type: 'POST',
                dataType: 'json',
                data:'matchlevel='+matchlevel+'&match_disable='+match_disable,
                url:'match/closeMatch',
                success: function(e){
                    console.log(e);
                    if(e.code == 1){
                        alert(strName+'成功');
                        window.location.reload()
                    }else{
                        alert(strName+'失败');
                    }
                }
            });
        }
    });
</script>