<link rel="stylesheet" href="<?php echo base_url();?>public/js/vendor/bootstrap-datepicker/css/bootstrap-datepicker.standalone.min.css">
<script src="<?php echo base_url();?>public/js/vendor/bootstrap-datepicker/js/bootstrap-datepicker.min.js"></script>
<script src="<?php echo base_url();?>public/js/vendor/bootstrap-datepicker/locales/bootstrap-datepicker.zh-CN.min.js"></script>
<link rel="stylesheet" href="<?php echo base_url();?>public/css/imageChange.css">
<link rel="stylesheet" href="<?php echo base_url();?>public/css/style.css">

<style type="text/css">
    td,th{
        max-width: 400px;
        word-wrap: break-word;
    }

    .modal-dialog {
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
    }

    .modal-content {
        position: absolute;
        top: 0;
        bottom: 0;
        width: 100%;
        height: 60%;
    }

    .modal-body {
        overflow-y: scroll;
        position: absolute;
        top: 55px;
        bottom: 65px;
        width: 100%;
    }

    .modal-header .close {margin-right: 15px;}

    .modal-footer {
        position: absolute;
        width: 100%;
        bottom: 0;
    }

    .even{
        width: 90% !important;
        float: right!important;
    }

    .odd{
        width: 90%!important;
    }
</style>
<div class="content_wrapper">
    <div id="msg-tip"></div>
    <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/feedback">
                                        <input type="hidden" name="feedback_post" value="1"/>
                                        <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="feedback_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="feedback_etime" />
                                        </div>
                                        <span class="gap"></span>
                                        <div class="form-group">
                                            <label>用户UID: </label>
                                            <input type="text" class="form-control " value="<?php if($uid) echo $uid;?>" placeholder="用户UID" name="feedback_uid" />
                                        </div>
                                        <span class="gap"></span>
                                        <div class="form-group">
                                            <label>状态:</label>
                                            <select  name="replyStatus" id="replyStatus" class="selectpicker show-tick form-control">
                                                <?php $replyStatus = $replyStatus ?? 0;?>
                                                <option value="0">--请选择--</option>
                                                <option value="1" <?php if($replyStatus == 1) echo 'selected';?>>已回复</option>
                                                <option value="2" <?php if($replyStatus == 2) echo 'selected';?>>未回复</option>
                                            </select>
                                        </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>版本2</th>
                                                <th>描述<span style="color:red;">(第一次双击翻译，再双击还原)</span></th>
                                                <!--<th>翻译</th>-->
                                                <th>反馈类型</th>
                                                <th>反馈时间</th>
                                                <th>是否回复</th>
                                                <!--                                                <th>我的回复</th>-->
                                                <th>平台</th>
                                                <th>版本</th>
                                                <th>网络</th>
                                                <th>MAC地址</th>
                                                <th>IP</th>
                                                <th>地区</th>
                                                <th>操作</th>
                                            </tr>
                                            </thead>
                                            <tbody>
                                            <?php
                                            if(is_array($list)){
                                                foreach ($list as $key => $val) {
                                                    ?>
                                                    <tr>
                                                        <td><?php echo $val['id'];?></td>
                                                        <td><?php echo $val['user_id'] == 1 ? '无uid' : '<a target = "_blank" href="#user/index/'.$val['user_id'].'">'.$val['user_id'].'</a>';?></td>
														<td><?php echo $val['version2'];?></td>
                                                        <td><?php echo strpos($val['content'],"https://god.superant.vip/images/uploads/") !== false?'<a href="'.$val['content'].'" target="_blank"><img src="'.$val['content'].'" height="55px"></a>':'<div class="translate zh" content="'.$val['content'].'">'.$val['content'].'</div>';?></td>
                                                        <!--<td><button type="button" class="translate btn btn-primary" content="<?php echo $val['content'];?>">翻译</button></td>-->
                                                        <td><?php echo $val['type'];?></td>
                                                        <td><?php echo date('Y-m-d H:i:s', $val['created_at']);?></td>
                                                        <td><?php echo $val['have_read'] == 1 ? '<span class="label label-default">已回复</span>' : '<span class="label label-success">未回复</span>';?></td>
                                                        <!--                                                <td class="freply--><?php //echo $val['fid'];?><!--">--><?php //echo $val['freply'] ? $val['freply'] : '未回复';?><!--</td>-->
                                                        <td><?php if($val['platform'] == 'ios') {echo '苹果'; }else { echo '安卓';} ?></td>
                                                        <td><?php echo $val['version']; ?></td>
                                                        <td><?php if($val['network'] == 'wifi') {echo 'WIFI'; }elseif($val['fnetwork'] == 2) { echo '4G';}else { echo '';} ?></td>
                                                        <td><?php echo $val['mac'];?></td>
                                                        <td><?php echo $val['ip'];?></td>
                                                        <td><?php echo $val['country_code'];?></td>
                                                        <td>
                                                            <button type="button" class="btn btn-primary actionReply"  uid="<?php echo $val['user_id'];?>" >回复</button>
                                                            <!--                                                    <button type="button" class="btn btn-danger delfeedback" uid="--><?php //echo $val['user_id'];?><!--">删除</button>-->
                                                            <?php if($val['have_read'] == 0){?>
                                                                <button type="button" class="btn btn-default updateStatus" uid="<?php echo $val['user_id'];?>" >修改状态</button>
                                                            <?php }?>
                                                        </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 id="Cover_Div" onClick="hideMax()"></div>

</div>


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

<!-- 返回玩家 -->
<div class="modal fade" id="actionReply" 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 id="filefromData" class="form-horizontal" role="form" method="post" action="user/actionfeedback" data-callBack='updatefreply'>
                <input type="hidden" name="actionuid" value="" />
                <div class="modal-body" id="modalBody">
                    <div data-role="content" role="main">
                        <ul class="content-reply-box mg10" id="ulMessage">
                            <li class="odd">
                                <a class="user" href="#"><span class="user-name">奔波儿灞</span></a>
                                <div class="reply-content-box">
                                    <span class="reply-time">03-08 15：00</span>
                                    <div class="reply-content pr">
                                        <span class="arrow">&nbsp;</span>
                                        为什么小鑫的名字里有三个金呢？
                                    </div>
                                </div>
                            </li>
                            <li class="even">
                                <a class="user" href="#"><span class="user-name">灞波儿奔</span></a>
                                <div class="reply-content-box">
                                    <span class="reply-time">03-08 15：10</span>
                                    <div class="reply-content pr">
                                        <span class="arrow">&nbsp;</span>
                                        他命里缺金，所以取名叫鑫，有些人命里缺水，就取名叫淼，还有些人命里缺木就叫森。
                                    </div>
                                </div>
                            </li>
                            <li class="even">
                                <a class="user" href="#"><span class="user-name">灞波儿奔</span></a>
                                <div class="reply-content-box">
                                    <span class="reply-time">03-08 15：10</span>
                                    <div class="reply-content pr">
                                        <span class="arrow">&nbsp;</span>
                                        他命里缺金，所以取名叫鑫，有些人命里缺水，就取名叫淼，还有些人命里缺木就叫森。
                                    </div>
                                </div>
                            </li>
                            <li class="even">
                                <a class="user" href="#"><span class="user-name">灞波儿奔</span></a>
                                <div class="reply-content-box">
                                    <span class="reply-time">03-08 15：10</span>
                                    <div class="reply-content pr">
                                        <span class="arrow">&nbsp;</span>
                                        他命里缺金，所以取名叫鑫，有些人命里缺水，就取名叫淼，还有些人命里缺木就叫森。
                                    </div>
                                </div>
                            </li>
                            <li class="even">
                                <a class="user" href="#"><span class="user-name">灞波儿奔</span></a>
                                <div class="reply-content-box">
                                    <span class="reply-time">03-08 15：10</span>
                                    <div class="reply-content pr">
                                        <span class="arrow">&nbsp;</span>
                                        他命里缺金，所以取名叫鑫，有些人命里缺水，就取名叫淼，还有些人命里缺木就叫森。
                                    </div>
                                </div>
                            </li><li class="even">
                                <a class="user" href="#"><span class="user-name">灞波儿奔</span></a>
                                <div class="reply-content-box">
                                    <span class="reply-time">03-08 15：10</span>
                                    <div class="reply-content pr">
                                        <span class="arrow">&nbsp;</span>
                                        他命里缺金，所以取名叫鑫，有些人命里缺水，就取名叫淼，还有些人命里缺木就叫森。
                                    </div>
                                </div>
                            </li><li class="even">
                                <a class="user" href="#"><span class="user-name">灞波儿奔</span></a>
                                <div class="reply-content-box">
                                    <span class="reply-time">03-08 15：10</span>
                                    <div class="reply-content pr">
                                        <span class="arrow">&nbsp;</span>
                                        他命里缺金，所以取名叫鑫，有些人命里缺水，就取名叫淼，还有些人命里缺木就叫森。
                                    </div>
                                </div>
                            </li>
                            <li class="even">
                                <a class="user" href="#"><span class="user-name">灞波儿奔</span></a>
                                <div class="reply-content-box">
                                    <span class="reply-time">03-08 15：10</span>
                                    <div class="reply-content pr">
                                        <span class="arrow">&nbsp;</span>
                                        他命里缺金，所以取名叫鑫，有些人命里缺水，就取名叫淼，还有些人命里缺木就叫森。
                                    </div>
                                </div>
                            </li>
                        </ul>
                    </div>
                </div>

                <div class="modal-footer clearfix">
                    <div class="col-sm-7">
                        <textarea name="reply" id="replyContents" class="form-control" rows="1"></textarea>
                    </div>
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" onclick="commit()" class="btn btn-primary">回复</button>
                    <button type="button"  class="btn btn-primary" id="uploadImg"><i class="fa fa-plus-square"></i>上传图片</button>
                    <input type="file" name="imgfile" id="imgfile" class="imgfile hide"/>
                </div>
            </form>
        </div>
    </div>
</div>
<script src="<?php echo base_url();?>public/js/common.js"></script>
<script src="<?php echo base_url();?>public/js/md5.js"></script>
<!--<script src="--><?php //echo base_url();?><!--public/js/imageChange.js"></script>-->

<script>
    //选择日期
    $('.datetimepicker').datepicker({
        language:'zh-CN',
        format:'yyyy-mm-dd',
        zIndexOffset:906  //控制z-index
    });


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

    var msgTip = $('#msg-tip');
    //回复玩家
    $('.actionReply').click(function(){
        var uid = $(this).attr("uid");
        $("input[name='actionuid']").val(uid);
        $.ajax({
            type: 'POST',
            dataType: 'json',
            data:'user_id='+uid,
            url:'user/feedback',
            success: function(e){
                if(e.code == 1){
                    var Html ='';
                    for (var i=0;i<e.data.length;i++){
                        var temp = e.data[e.data.length-i-1]
                        var timestamp4 = new Date(temp.created_at*1000);
                        var time = timestamp4.toLocaleDateString().replace(/\//g, "-") + " " + timestamp4.toTimeString().substr(0, 8);
                        var from = (temp.orientation == 1)?'odd':'even';
                        var user_id = (temp.orientation == 1)?temp.user_id:'客服';
                        if(temp.img != null && temp.img != "null" && temp.img != ""){
                            temp.content = "<img src='"+temp.img+"' style='max-height: 300px;'>";
                        }
                        var target = (temp.orientation == 1)?'<a class="user" target="_blank" href="#user/index/'+temp.user_id+'">':'<a class="user" href="#" onclick="return false;">';
                        Html += '<li class="'+from+'">'+target+'<span class="user-name">'+user_id+'</span></a><div class="reply-content-box">'
                            +'<span class="reply-time">'+time+'</span><div class="reply-content pr"><span class="arrow">&nbsp;</span>'+temp.content+'</div></div></li>'
                    }
                    $('#ulMessage').html(Html);
                }
                setTimeout(function () {
                    $('#modalBody').scrollTop(90000)
                }, 500 )

                $('#actionReply').modal('show')
            }
        });


    });

    function commit() {
        var uid = $("input[name='actionuid']").val();
        var content = $('#replyContents').val();
        if(content == ''){
            return false;
        }
        $.ajax({
            type: 'POST',
            dataType: 'json',
            data:{
                user_id:uid,
                content:content
            },
            url:'user/actionfeedback',
            success: function(data){
                if(data.state == 1){
                    var timestamp4 = new Date();
                    var time = timestamp4.toLocaleDateString().replace(/\//g, "-") + " " + timestamp4.toTimeString().substr(0, 8);
                    var Html = '<li class="even"><a class="user" href="#" onclick="return false;"><span class="user-name">客服</span></a><div class="reply-content-box">'
                        +'<span class="reply-time">'+time+'</span><div class="reply-content pr"><span class="arrow">&nbsp;</span>'+content+'</div></div></li>'
                    $('#ulMessage').append(Html);
                    $('#modalBody').scrollTop(90000)
                    $('#replyContents').val('');
                }
            }
        });
    }


    //更新回复内容
    function updatefreply(returnData, $from){
        if( returnData.code == 1 ){
            var fid = returnData.fid;
            var reply = returnData.reply;
            $(".freply"+fid).text(reply);
            $(".freply"+fid).prev().text('已回复');
        }
    }

    $('.updateStatus').click(function () {
        if(confirm('确定修改该反馈为已回复吗?')) {
            var uid = $(this).attr("uid");
            $.ajax({
                type: 'POST',
                dataType: 'json',
                data:{
                    uid:uid
                },
                url:'user/updateFeedback',
                success: function(data){
                    if(data.ret == 0){
                        window.location.reload()
                    }else{
                        msgTip.messager().error('操作失败');
                    }
                }
            });
        }
    });

    //删除反馈
    $('.delfeedback').click(function(){
        if( confirm('确定删除该反馈吗?') ){
            var uid = $(this).attr("uid");
            $.ajax({
                type: 'POST',
                dataType: 'json',
                data:'uid='+uid,
                url:'user/delfeedback',
                success: function(e){
                    if(e.ret == 0){
                        alert('删除成功');
                        window.location.reload()
                    }else{
                        alert('删除失败');
                    }
                }
            });
        }
    });
    
    var appid = '20191016000341999';
	var key = 'HMGPtwu5zy5KJygR10Yd';
	var salt = (new Date).getTime();
	
    //翻译需要引入md5.js
    $(document).on("dblclick",".translate",function(){
    	var obj = $(this);
    	//var content = $(this).attr("content");
    	var content = $(this).text();
    	console.log(content);
    	if($(this).hasClass("zh")){
			var from = 'en';
			var to = 'zh';
			var str1 = appid + content + salt +key;
			var sign = MD5(str1);
		
	    	$.ajax({
			    url: 'https://api.fanyi.baidu.com/api/trans/vip/translate',
			    type: 'get',
			    dataType: 'jsonp',
			    data: {
			        q: content,
			        appid: appid,
			        salt: salt,
			        from: from,
			        to: to,
			        sign: sign
			    },
			    success: function (data) {
			        console.log(data);
			        obj.text(data.trans_result[0].dst);
			    } 
			});
			
			$(this).removeClass("zh");
    	}else{
    		$(this).text($(this).attr("content"));
    		$(this).addClass("zh");
    	}
    })

	
	$(document).on('click','#uploadImg',function () {
        obj = $(this);
        obj.siblings(".imgfile").click();
    });

    document.getElementById("imgfile").addEventListener("change",function () {
        var formData = new FormData(); 
        // console.log("file",formData1);
        const file = document.getElementById('imgfile');
        const fileObj = file.files[0];
        console.log("file",fileObj);
        formData.append('file', fileObj);
        $.ajax({  
	         url: '/upload/actioneUploadImgs2',  
	         type: 'POST',
	         dataType: "json",
	         data: formData, 
	         async: false,
	         cache: false,
	         contentType: false,
	         processData: false,
	         success: function (msg) {  
	            if(msg.ret == 0){
	            	$("#replyContents").val(msg.msg);
	            }else{
	            	alert("上传失败");
	            }
	         }
		});
    });
</script>

