<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">
            <div class="col-sm-12">
                <aside>
                    <header><i class="fa fa-fw fa-file"></i>异常金币体力分析</header>
                    <section>
                    	
                        <div class="container-fluid">
                        	<div class="btn-group" style="margin-bottom:20px;">
                        		<button type="button" class="btn btn-danger" disabled id="commitBtn">提交</button>
                        	</div>
                        	<br>
                            <div class="btn-group" style="margin-bottom:20px;">
                                <a href="#abnormal/moneyspins/money<?php if($level) echo "/".$level; ?><?php if($money) echo "/".$money; ?><?php if($spins) echo "/".$spins; ?>" class="btn btn-success">金币</a>
                                <a href="#abnormal/moneyspins/spins<?php if($level) echo "/".$level; ?><?php if($money) echo "/".$money; ?><?php if($spins) echo "/".$spins; ?>" class="btn btn-success">体力</a>
                                <a href="#abnormal/moneyspins/star<?php if($level) echo "/".$level; ?><?php if($money) echo "/".$money; ?><?php if($spins) echo "/".$spins; ?>" class="btn btn-success">星星</a>
                            </div>
                            <div class="row">
                                <div class="col-sm-12">
                                    <form class="form-inline" role="form" method="POST" action="">
                                        <span class="gap"></span>
                                        <div class="form-group">
                                            <label>金币:</label>
                                            
                                            <input type="text" class="form-control" value="<?php if($money) echo $money;?>" placeholder="金币" name="money" />
                                        </div>
                                        <span class="gap"></span>
                                        <div class="form-group">
                                            <label>体力:</label>
                                            
                                            <input type="text" class="form-control" value="<?php if($spins) echo $spins;?>" placeholder="体力" name="spins" />
                                        </div>
                                        <div class="form-group">
                                            <label>等级:</label>
                                            
                                            <input type="text" class="form-control" value="<?php if($level) echo $level;?>" placeholder="等级" name="level" />
                                        </div>
                                        <button type="button" class="btn btn-primary" id="query">查询</button>
                                    </form>
                                </div>
                            </div>
                            <br>
                            <div class="row">
                            	<div class="col-sm-12">
	                                <div class="table-responsive">
	                                    <table id="roleTable" class="table table-striped table-bordered table-hover" cellspacing="0" width="100%">
	                                        <thead>
		                                        <tr>
		                                            <th style="text-align: center;vertical-align: middle;">uid</th>
		                                            <th style="text-align: center;vertical-align: middle;">昵称</th>
		                                            <th style="text-align: center;vertical-align: middle;">当前岛</th>
		                                            <th style="text-align: center;vertical-align: middle;">星星</th>
		                                            <th style="text-align: center;vertical-align: middle;">金币</th>
		                                            <th style="text-align: center;vertical-align: middle;">体力</th>
		                                            <th style="text-align: center;vertical-align: middle;">注册时间</th>
		                                            <th style="text-align: center;vertical-align: middle;">最后登录时间</th>
		                                            <th style="text-align: center;vertical-align: middle;">FB/游客</th>
		                                            <th style="text-align: center;vertical-align: middle;">累计游戏时间</th>
		                                            <th style="text-align: center;vertical-align: middle;">是否VIP</th>
		                                            <th style="text-align: center;vertical-align: middle;">充值金额</th>
		                                            <th style="text-align: center;vertical-align: middle;">处理原因(双击编辑)</th>
		                                            <th style="text-align: center;vertical-align: middle;">操作</th>
		                                        </tr>
	                                        
	                                        </thead>
	                                        <tbody id="roleBody">
	                                        	<?php foreach($data as $k => $v){ ?>
	                                        	<tr>
	                                        		<td style="text-align: center;vertical-align: middle;"><a target = "_blank" href="#user/index/<?php echo $v['uid']; ?>"><?php echo $v['uid']; ?></a></td>
	                                        		<td style="text-align: center;vertical-align: middle;"><?php echo $v['nick']; ?></td>
	                                        		<td style="text-align: center;vertical-align: middle;"><?php echo $v['levelId']; ?></td>
	                                        		<td style="text-align: center;vertical-align: middle;"><?php echo $v['star']; ?></td>
	                                        		<td style="text-align: center;vertical-align: middle;" uid="<?php echo $v['uid']; ?>"><?php echo $v['money']; ?></td>
	                                        		<td style="text-align: center;vertical-align: middle;" uid="<?php echo $v['uid']; ?>"><?php echo $v['spins']; ?></td>
	                                        		<td style="text-align: center;vertical-align: middle;"><?php echo date("Y-m-d H:i:s",$v['createtime']); ?></td>
	                                        		<td style="text-align: center;vertical-align: middle;"><?php echo date("Y-m-d H:i:s",$v['lasttime']); ?></td>
	                                        		<td style="text-align: center;vertical-align: middle;"><?php echo $v['isVistor']?'游客':'FB'; ?></td>
	                                        		<td style="text-align: center;vertical-align: middle;"><?php echo $v['loginTime']; ?></td>
	                                        		<td style="text-align: center;vertical-align: middle;"><?php echo $v['vip']?'是':'否'; ?></td>
	                                        		<td style="text-align: center;vertical-align: middle;"><?php echo $v['sumMoney']; ?></td>
	                                        		<td style="text-align: center;vertical-align: middle;"><div><?php echo $v['reason']; ?></div></td>
	                                        		<td style="text-align: center;vertical-align: middle;">
	                                        			<?php
						                                    if(empty($v['chatLock']) || !$v['chatLock']){
						                                        echo '<button id="chatLock" type="button" class="btn btn-danger btn-xs" onclick="changeChatLock(1,'.$v['uid'].')">聊天禁言</button>';
						                                    }else{
						                                        echo '<button id="chatLock" type="button" class="btn btn-success btn-xs" onclick="changeChatLock(2,'.$v['uid'].')">解除禁言</button>';
						                                    }
						                                    echo "<br><br>";
						                                    if($v['status'] == 1){
						                                        echo '<button id="chatLock" type="button" class="btn btn-danger btn-xs" onclick="suspendAccount(1,'.$v['uid'].')">封号</button>';
						                                    }else{
						                                        echo '<button id="chatLock" type="button" class="btn btn-success btn-xs" onclick="suspendAccount(2,'.$v['uid'].')">解除封号</button>';
						                                    }
						                                    echo "<br><br>";
						                                 ?>
						                                 <a href="#abnormal/moneySpinsSource/<?php echo $v['uid']; ?>" target="_blank" class="btn btn-primary btn-xs" role="button" id="order">金币体力来源</a>
	                                        		</td>
	                                        	</tr>
	                                        	<?php } ?>
	                                        </tbody>
	                                    </table>
	                                </div>
                                </div>
                            </div>
                            
                            
                            
                            
                        </div>
                    </section>
                </aside>
            </div>
        </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 type="text/javascript">
    //选择日期
    $('.datetimepicker').datepicker({
        language:'zh-CN',
        format:'yyyy-mm',
        zIndexOffset:906  //控制z-index
    });
</script>
<script>
	$("body").on("click","#query",function(){
		var level = $("input[name='level']").val();
		var spins = $("input[name='spins']").val();
		var money = $("input[name='money']").val();
		if(level == ""){
			alert("请输入等级");
			return false;
		}
		if(spins == ""){
			alert("请输入体力");
			return false;
		}
		if(money == ""){
			alert("请输入金币");
			return false;
		}
		location.href = "#abnormal/moneyspins/spins/"+level+"/"+money+"/"+spins;
	})

    $("#btnpro").click(function(){
        var formData = new FormData();
        formData.append("file",document.getElementById("upfilepro").files[0]);
        $.ajax({
            type: "POST", // 数据提交类型
            url: "Reconciliation/import/<?php echo $month;?>", // 发送地址
            data: formData, //发送数据
            async: true, // 是否异步
            processData: false, //processData 默认为false，当设置为true的时候,jquery ajax 提交的时候不会序列化 data，而是直接使用data
            contentType: false, //
            success: function(data) { // 成功回调
                data = JSON.parse(data);
                if(data.ret == 0){
                    window.location.reload();
                }else {
                    msgTip = $('#msg-tip');
                    msgTip.messager().warn('上传失败');
                }
            }
        });
    });

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

    $("#btncoin").click(function(){
        var formData = new FormData();
        formData.append("file",document.getElementById("upfilecoin").files[0]);
        $.ajax({
            type: "POST", // 数据提交类型
            url: "Reconciliation/import", // 发送地址
            data: formData, //发送数据
            async: true, // 是否异步
            processData: false, //processData 默认为false，当设置为true的时候,jquery ajax 提交的时候不会序列化 data，而是直接使用data
            contentType: false, //
            success: function(data) { // 成功回调
                data = JSON.parse(data);
                if(data.ret == 0){
                    window.location.reload();
                }else {
                    msgTip = $('#msg-tip');
                    msgTip.messager().warn('上传失败');
                }
            }
        });
    });

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



    $('#roleTable').on('paste', 'input', function (e) {
        var _that =  $(this);
        var strArr = [];
        var pastedText = undefined;
        if (window.clipboardData && window.clipboardData.getData) { // IE
            pastedText = window.clipboardData.getData('Text');
        } else {
            pastedText = e.originalEvent.clipboardData.getData('Text');//e.clipboardData.getData('text/plain');
        }
        if(pastedText == undefined || pastedText == null || pastedText == ''){
            return;
        }
        //处理粘贴的数据,已空格拆分
        pastedText = pastedText.replace(/,/g, '');
        strArr = pastedText.split(/\s+/);

        setTimeout(function () {
            _that.val(strArr[0]);
        }, 200);

        for(var i=1; i < strArr.length; i++){
            _that.parent().siblings().eq(i-1).removeClass('input').html(strArr[i] || '');
        }
    });

    $('#roleTable').on('dblclick','td',function(){
        var _this = $(this),//保存td
            tdText = _this.text();
        var  cellIndex =  _this[0].cellIndex;
        if(cellIndex == 0) {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();
                
                _input.parent().removeClass('input').html(thisvalue || '');
                
                if(cellIndex == 4 || cellIndex == 5){
                	var uid = $(_this).attr("uid");
                	switch(cellIndex){
                		case 4:
                			if( confirm('确认增加/扣除：'+ thisvalue + ' 金币吗？') ){
	                			//修改金币
	                			$.post("user/actionusermoney", { 'actionuid': uid,'newmoney':thisvalue }, function(data){
					                if( data.state == 'success' ){
					                    window.location.reload();
					                    alert('操作成功');
					                }else {
					                    alert('操作失败');
					                }
					            },"json");
                			}
                			break;
                		case 5:
                			//修改体力
                			if( confirm('确认增加/扣除：'+ thisvalue + ' 体力吗？') ){
	                			//修改金币
	                			$.post("user/actionusermoney", { 'actionuid': uid,'newspins':thisvalue }, function(data){
					                if( data.state == 'success' ){
					                    window.location.reload();
					                    alert('操作成功');
					                }else {
					                    alert('操作失败');
					                }
					            },"json");
                			}
                			break;
                	}
                	return false;
                }
                
                if($('#commitBtn').prop('disabled')){
                    $('#commitBtn').attr('disabled', false);
                }
            });
        }

    });


    //新增一行
    $('#addBtn').click(function () {
        var editUserList = '<?php echo json_encode($editUserList) ?>';
        var username = '<?php echo get_cookie('username');?>';
        var msgTip = $('#msg-tip');

        editUserList = JSON.parse(editUserList);
        if($.inArray(username, editUserList) < 0){
            //msgTip.messager().warn('没有编辑权限');
            //return;
        }

        if($('#commitBtn').prop('disabled')){
            $('#commitBtn').attr('disabled', false);
        }
        var html = '<tr>';
        for(var i=0; i<11; i++){
            if(i<5){
                html += '<td class="input add-row"><div><input value=""/></div></td>';
            }else{
                html += '<td class="input add-row"><div><input value=""/></div><div><input value=""/></div></td>';
            }
        }

        html += ' </tr>';
        $('#roleTable').append(html);
    });

    //删除一行
    $('#roleTable').on('click','.delete-row',function () {
        if(confirm('是否确认删除该行')){
            if($('#commitBtn').prop('disabled')){
                $('#commitBtn').attr('disabled', false);
            }
            $(this).parent().parent().remove();
        }

    });


    $('#roleTable').on('blur', '.add-row', function () {
        var _that = $(this);
        var thisval = _that.find('input');
        var div = $(thisval[0]).parent();
        if($(thisval[0]).val() == ""){
            div.html(0);
        }else{
            div.html($(thisval[0]).val());
        }

        div.removeClass('input');
        div.parent().removeClass('input');
    });


    //提交表格数据
    $('#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:
                    	if($(td[12]).text() != ''){
                    		tempData['uid'] = $(td[j]).text();
                    	}
                        
                    	break;
                    case 12:
                    	if($(td[j]).text() != ''){
                    		arrayTemp['reason'] = $(td[j]).text();
                    	}
                        break;
                    
                }
            }

            if(JSON.stringify(arrayTemp) != "{}"){
            	tempData['data'] = arrayTemp;
            	arr.push(tempData)
            }
        }

        $.ajaxSetup({
            async: true
        });


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



</script>
<script>
	//禁言
	function changeChatLock(type,uid) {
        var tips = (type==1)?"确认禁言该账号?备注原因：":"确认解除禁言?";
        var tips2 = (type==1)?"禁言成功":"解除禁言成功";
        var remark = '';
        if(type==1){
            remark = prompt(tips);
            if(remark){

            }else if(remark === ""){
                alert('请输入禁言原因');
                return false;
            }else{
                return false;
            }
        }
        $.post("user/chatLock", { uid: uid,remark:remark }, function(data){
            if( data == 1 ){
                alert(tips2);
                window.location.reload();
            }
        });
    }
    
    //封账号
    function suspendAccount(type,uid){
    	var msg = "";
    	if(type == 1){
    		msg = "确认封该账号?";
    	}else{
    		msg = "确认解封该账号?";
    	}
    	if( confirm(msg) ){
            $.post("user/suspendAccount", { uid: uid }, function(data){
                if( data == 1 ){
                    window.location.reload();
                    alert('操作成功');
                }else {
                    alert('操作失败');
                }
            });
        }
    }
    
</script>
