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

    .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)';
    }
</style>
<div class="content_wrapper">
    <div id="msg-tip"></div>
    <div class="container-fluid ">
        <div class="row hide">
            <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="#config/role">-->
                                    <!---->
                                    <!--                                        <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>大客户维护 <?php echo $type == 1?'所有':($type == 2?'鲸鱼玩家':'大R玩家'); ?></header>
                    <section>
                        <div class="container-fluid">
                        	<div class="btn-group" style="margin-bottom:20px;">
                            	<button type="button" style="width: 80px;" class="btn btn-danger" disabled id="commitBtn">提交</button>
                        	</div>
                        	<br>
                            <div class="" style="margin-bottom:20px;">
                                <a href="/#statistics/keyAccountSta/1/<?php echo $sort;?>" class="btn btn-primary">所有</a>
                                <a href="/#statistics/keyAccountSta/2/<?php echo $sort;?>" class="btn btn-primary">鲸鱼玩家</a>
                                <a href="/#statistics/keyAccountSta/3/<?php echo $sort;?>" class="btn btn-primary">大R玩家</a>
                            </div>
                          
                            <div class="" style="margin-bottom:20px;">
                                <a href="/#statistics/keyAccountSta/<?php echo $type;?>/money" class="btn btn-primary">金额</a>
                                <a href="/#statistics/keyAccountSta/<?php echo $type;?>/time" class="btn btn-primary">最后上线时间</a>
                            </div>
                            <div class="row">
								
                                <div class="col-sm-12">
                                    <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="500">
                                            <thead>
                                            <tr>
                                                <th>uid</th>
                                                <th>姓名、FB</th>
                                                <th>性别</th>
                                                <th>年龄</th>
                                                <th>设备</th>
                                                <th>国家</th>
                                                <th>设置语言</th>
                                                <th>订单数</th>
                                                <th>当前付费(美金)</th>
                                                <th>付费最多商品</th>
                                                <th>平均每日游玩(分)</th>
                                                <th>当前等级</th>
                                                <th>VIP积分</th>
                                                <th>是否为VIP</th>
                                                <th>最后上线时间</th>
                                                <th>付费关卡</th>
                                                <th>商品内容</th>
                                                <th>付费原因</th>
                                                <th>活动付费</th>
                                            </tr>
                                            </thead>
                                            <tbody>
                                            <?php
                                            if(is_array($list)  && !empty($list)){
                                                foreach ($list as $key => $vl) { ?>
                                                    <tr>
                                                        <td style="text-align: center;vertical-align: middle;"><a target = "_blank" href="#user/index/<?php echo $vl['uid']; ?>"><?php echo $vl['uid']; ?></a></td>
                                                        <td>
                                                        	<?php 
                                                        		if(!empty($vl['fb_url'])){
                                                        			echo "<a href='".$vl['fb_url']."' target='_blank'>".$vl['nick']."</a>";
                                                        		}else{
                                                        			echo $vl['nick'];
                                                        		}
                                                        	?>
                                                        </td>
                                                        <td><?php echo $vl['sex'];?></td>
                                                        <td><?php echo $vl['age'];?></td>
                                                        <td><?php echo $vl['device'];?></td>
                                                        <td><?php echo $vl['country'];?></td>
                                                        <td><?php echo $vl['lang'];?></td>
                                                        <td><?php echo $vl['order_count'];?></td>
                                                        <td><?php echo round($vl['spend'],2);?></td>
                                                        <td><?php echo $vl['maxGoodsGname'];?></td>
                                                        <td><?php echo $vl['loginTime'];?></td>
                                                        <td><?php echo $vl['level']; ?></td>
                                                        <td></td>
                                                        <td><?php echo $vl['vip']?'是':'否'; ?></td>
                                                        <td><?php echo date("Y-m-d H:i:s",$vl['lasttime']); ?></td>
                                                        <td><?php echo $vl['pay_level']; ?></td>
                                                        <td><?php echo $vl['goods_content']; ?></td>
                                                        <td>
                                                        	<select name="pay_reason" class="form-control pay_reason">
                                                        		<option value="取得优势" <? echo $vl['pay_reason']=="取得优势"?"selected":''; ?> >取得优势</option>
                                                        		<option value="克服障碍" <? echo $vl['pay_reason']=="克服障碍"?"selected":''; ?> >克服障碍</option>
                                                        		<option value="任务成就" <? echo $vl['pay_reason']=="任务成就"?"selected":''; ?> >任务成就</option>
                                                        		<option value="稀有物品" <? echo $vl['pay_reason']=="稀有物品"?"selected":''; ?> >稀有物品</option>
                                                        		<option value="打折优惠" <? echo $vl['pay_reason']=="打折优惠"?"selected":''; ?> >打折优惠</option>
                                                        		<option value="荣誉名声" <? echo $vl['pay_reason']=="荣誉名声"?"selected":''; ?> >荣誉名声</option>
                                                        	</select>	
                                                        </td>
                                                        <!--<td><?php echo $vl['pay_reason']; ?></td>-->
                                                        <td><?php echo $vl['pay_activity']; ?></td>
                                                    </tr>
                                                <?php } } else{?>
                                                <tr>
                                                    <td colspan="14">暂无数据</td>
                                                </tr>
                                            <?php } ?>
                                            </tbody>
                                        </table>
                                    </div>
<!--                                    <button type="button"  class="btn btn-primary"  id="addBtn"><i class="fa fa-plus-square"></i>添加</button>-->

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




<script src="<?php echo base_url();?>public/js/common.js"></script>

<!--<script src="--><?php //echo base_url();?><!--public/js/imageChange.js"></script>-->
<script>


    $("#filespan").on("change", "input[type='file']", function() {
        var filePath = $(this).val();
        //如果仅上传图片 if(filePath.indexOf("jpg") != -1 || filePath.indexOf("png") != -1) {
        if (filePath) {
            $('#filespan').hide();
            $('#btn').show();
        } else {
            return false
        }
    });

	//下拉框选择
	$(document).on("change",".pay_reason",function(){
		var _input = $(this); //保存input对象
        var thisvalue = $(this).val();
        _input.parent().removeClass('input').html(thisvalue || '');
        if($('#commitBtn').prop('disabled')){
            $('#commitBtn').attr('disabled', false);
        }
	});

    $('#roleTable').on('dblclick','td',function(){
        var _this = $(this),//保存td
            tdText = _this.text();
        var  cellIndex =  _this[0].cellIndex;
        if(cellIndex == 0) {return false;} //点击操作列不可编辑
        if(cellIndex == 17){
        	//下拉框
        	return false;
        }
        if(!_this.is('.input')){
            _this.addClass('input').html('<input type="text" value="'+ tdText +'" />').find('input').focus().blur(function(){
                var _input = $(this); //保存input对象
                var thisvalue = $(this).val();
                if(cellIndex == 1){
                	//FB
                	_input.parent().removeClass('input').attr("fb-url",thisvalue || '');
                	_input.parent().removeClass('input').text(tdText);
                	
                }else{
                	_input.parent().removeClass('input').html(thisvalue || '');
                }
                
                if($('#commitBtn').prop('disabled')){
                    $('#commitBtn').attr('disabled', false);
                }
            });
        }

    });


    $('#roleTable').on('blur', '.add-row', function () {
        var _that = $(this);
        var thisval = _that.find('input').val();
        console.log(thisval);
        _that.removeClass('input').html(thisval || 0);
    });


    //提交表格数据
    $('#commitBtn').click(function () {
        var tableContent = $('#roleTable').html(),
            msgTip = $('#msg-tip');
        //如果还有添加未编辑的，则不能提交
        if($('#roleTable td').hasClass('input')){
            msgTip.messager().warn('列表中还有未编辑的');
            return;
        }

        var tr = $('#roleTable tr');
        var arr = [];
        for (var i = 1; i < tr.length; i++) {
            var tempData = {};
            var arrayTemp ={};
            td = $(tr[i]).find('td');
            for (var j = 0; j < td.length; j++) {
                switch (j) {
                    case 0:
                        tempData['uid'] = $(td[j]).html();
                    break;
                    case 1:
                        arrayTemp['fb_url'] = $(td[j]).attr("fb-url");
                        break;
                    case 2:
                        
                        break;
                    case 3:
                        arrayTemp['age'] = $(td[j]).html();
                        break;
                    case 15:
                        arrayTemp['pay_level'] = $(td[j]).html();
                        break;
                    case 16:
                        arrayTemp['goods_content'] = $(td[j]).html();
                        break;
                    case 17:
                        arrayTemp['pay_reason'] = $(td[j]).html();
                        break;
                    case 18:
                        arrayTemp['pay_activity'] = $(td[j]).html();
                        break;
                }
            }
            tempData['data'] = arrayTemp;
            arr.push(tempData)
        }

        $.ajaxSetup({
            async: true
        });


        $.ajax({
            type: 'POST',
            dataType: 'json',
            data:{
                data: JSON.stringify(arr)
            },
            url:'statistics/actionKeyAccountSta',
            success: function(data){
                if(data.ret == 0){
                    window.location.reload()
                    $('#commitBtn').attr('disabled', true);
                }else{
                    msgTip.messager().error(data.msg);
                }
            }
        });
    });



</script>

