<link rel="stylesheet" href="<?php echo base_url();?>public/js/vendor/smalot_bootstrap-datetimepicker/css/bootstrap-datetimepicker.min.css">
<script src="<?php echo base_url();?>public/js/vendor/smalot_bootstrap-datetimepicker/js/bootstrap-datetimepicker.min.js"></script>
<script src="<?php echo base_url();?>public/js/vendor/smalot_bootstrap-datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js"></script>
<div class="content_wrapper">

    <div class="container-fluid">
        <div class="row">
            <div class="col-sm-12">
                <aside>
                    <section>
                        <div class="container-fluid">
                            <div class="row">
                                <div class="col-sm-12">
                                    <form class="form-inline" role="form" method="POST" action="#user/pokerlog" data-callBack="callback" name="pokerlogform">
                                        <input type="hidden" name="frompokerlog_user" value="1">
                                        <div class="form-group">
                                            <label>用户UID:</label>
                                            <input type="text" class="form-control" value="<?php if($uid) echo $uid;?>" placeholder="用户UID" name="userid">
                                        </div>
                                        <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="pokerlog_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="pokerlog_etime" />
                                        </div>
                                        <button type="submit" class="btn btn-primary">查询</button>
                                    </form>
                                </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="table-responsive">
                                        <table id="example" class="table table-striped table-bordered table-hover" cellspacing="0" width="100%">
                                            <thead>
                                            <tr>
                                                <th>用户ID</th>
                                                <th>桌子id</th>
                                                <th>牌局id</th>
                                                <th>场次id</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)){
                                                    foreach ($list as $key => $val) {
                                            ?>
                                                        <?php $gameName = ''; switch ($val['gameid'])
                                                        {
                                                            case 3:
                                                                $gameName='奥马哈';break;
                                                            case 4:
                                                            $gameName='百人场';break;
                                                            default:
                                                                if($val['level'] == 100){
                                                                    $gameName = '私人房';
                                                                }else{
                                                                    $gameName='德州';break;
                                                                }
                                                        } ?>
                                            <tr>
                                                <td><?php echo '<a target = "_blank" href="#user/index/'.$val['uid'].'">'.$val['uid'].'</a>';?></td>
                                                <td><?php echo $val['tid'];?></td>
                                                <td><?php echo $val['inner_id'];?></td>
                                                <td><?php echo $gameName;?></td>
                                                <td><?php echo $val['base'];?></td>
                                                <td><?php echo $val['deskfee'];?></td>
                                                <td><?php echo number_format($val['beformoney']);?></td>
                                                <td><?php echo number_format($val['currentmoney']);?></td>
                                                <td><?php echo number_format($val['wincoins']);?></td>
                                                <td><?php echo date('Y-m-d H:i:s', $val['start_time']);?></td>
                                                <td><?php echo date('Y-m-d H:i:s', $val['endtime']);?></td>
                                                <td><button type="button" class="btn btn-primary pokerdetail" data-toggle="modal" data-target=".pokerlogdetail" inner_id="<?php echo $val['inner_id']; ?>" month="<?php echo date('n', $val['start_time']);?>" tid="<?php echo $val['tid']; ?>" >牌局详情</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>

<!-- 牌局详情 START-->
<div class="modal fade pokerlogdetail" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
  <div class="modal-dialog modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">牌局详情</h4>
      </div>
      <div class="modal-body">
        <table class="table table-striped pokerdetailtable">
          <tr>
              <td>桌子ID</td>
              <td colspan="9" class="modal_tid"></td>
          </tr>
          <tr>
              <td>牌局ID</td>
              <td colspan="9" class="modal_innerid"></td>
          </tr>
          <tr>
              <td>盲住</td>
              <td colspan="9" class="modal_basechip"></td>
          </tr>
          <tr>
              <td>牌桌人数</td>
              <td colspan="9" class="modal_tbusercount"></td>
          </tr>
          <tr>
              <td>开始时间</td>
              <td colspan="9" class="modal_stime"></td>
          </tr>
          <tr>
              <td>结束时间</td>
              <td colspan="9" class="modal_etime"></td>
          </tr>

<!--            <tr class="redblack_detail">-->
<!--                <td class="redcards">金象牌</td>-->
<!--                <td>银象牌</td>-->
<!--                <td class="blackcards"></td>-->
<!--                <td>公共牌</td>-->
<!--                <td class="commoncards"></td>-->
<!--            </tr>-->
        </table>        
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
      </div>
    </div>
  </div>
</div>
<!-- 牌局详情 END-->

<script>
    $('.datetimepicker').datetimepicker({
        format: 'yyyy-mm-dd hh:ii:ss',
        locale: 'zh-cn'
    });

    function callback(returnData, $from) {
        var total = returnData.total;
        var page = returnData.pageurl;
        var dataList = returnData.list;

        //写入数据
        // $(".pagetotal").text(total);
        // $('.pagination li:gt(0)').remove();
        // $('.pagination li').append(page);
    }


    // 牌局详情按钮
    $(".pokerdetail").click(function(){
        var inner_id = $(this).attr('inner_id');
        var month = $(this).attr('month');
        var tid = $(this).attr('tid');
        $.ajax({
            type: "POST",
            url: "<?php echo base_url('user/getpokerdetail');?>",
            dataType: "json",
            data: {'inner_id':inner_id, 'month':month, 'tid':tid},
            success: function(e){
                if(e.code == 1){
                    $('.modal_tid').text(e.msg.tid);
                    $('.modal_innerid').text(e.msg.inner_id);
                    $('.modal_basechip').text(e.msg.basechip);
                    $('.modal_tbusercount').text(e.msg.tbusercount);
                    $('.modal_stime').text(e.msg.starttime);
                    $('.modal_etime').text(e.msg.endtime);

                    //先删除
                    $('.userdetail').remove();
                    //如果是红黑
                    var html = '';
                    if(e.msg.gameid == 4) {
                        html += '<tr class="userdetail"><td colspan="2">银象牌</td><td colspan="3">公共牌</td><td colspan="2">金象牌</td></tr>';
                        html += '<tr class="userdetail">';
                        html +='<td colspan="2">'+e.msg.blackcards+'</td>';
                        html +='<td colspan="3">'+e.msg.commoncards+'</td>';
                        html +='<td colspan="2">'+e.msg.redcards+'</td>';
                        html += '</tr>';
                    }
                    //详细信息
                    $.each(e.msg.list, function(i, n){
                        html += '<tr class="userdetail"><td>uid: '+i+'</td>';
                        $.each(n, function( m, j){
                            if(m == '下注'){
                                html +='<td colspan="3">'+m+': '+ j+'</td>';
                            }else {
                                html +='<td>'+m+': '+ j+'</td>';
                            }
                        });
                        html += '</tr>';
                    });
                    $('.pokerdetailtable').append(html);


                }
            }
        });
    });
</script>