<extend name="Public/base"/>

<block name="body">
<link rel="stylesheet" href="__CSS__/select2.min.css" type="text/css" />
<script type="text/javascript" src="__JS__/bootstrap.min.js"></script>
<script type="text/javascript" src="__JS__/select2.min.js"></script>
    <!-- 标题栏 -->
    <div class="main-place">
        <span class="main-placetitle">位置</span>
        <ul class="main-placeul">
            <li><a href="{:U('Game/lists')}">开发者</a></li>
            <li><a href="{:U('Game/lists')}">游戏管理</a></li>
            <li><a href="#">{$meta_title}</a></li>
        </ul>
        <div class="question">
            <i class="question_mark">?</i>
            <ul class="question_content">
                <li class="question_title">功能以及数据相关说明</li>
                <li class="question_list">
                    <span class="">{$meta_title}</span>
                    <span class="">开发者平台运营游戏的列表以及游戏的相关信息参数配置等</span>
                </li>
            </ul>
        </div>
    </div>
	<div class="cf top_nav_list">
		<div class="fl button_list">
		<empty name="model.extend">
			<div class="tools">
				<a class="" href="{:U('addGame?model='.$model['id'])}"><span class="button_icon button_icon1"></span>新增</a>
                 <a class=" ajax-post " target-form="ids" url="{:U("set_status",array("status"=>1,"msg_type"=>5,"field"=>"apply_status"))}"><span class="button_icon button_icon9"></span>审核</a>
                <a class=" ajax-post " target-form="ids" url="{:U("set_status",array("status"=>2,"msg_type"=>8,"field"=>"apply_status"))}"><span class="button_icon button_icon5"></span>驳回</a>
				<a class="ajax-post confirm " target-form="ids" url="{:U('delGame?model='.$model['id'])}"><span class="button_icon button_icon2"></span>删除</a>
            </div>
		</empty>
		</div>
		<!-- 高级搜索 -->
		<div class="jssearch fr cf search_list" style="margin-bottom:-15px;">
            <!--游戏类型搜索END-->
            <div class="input-list input-list-game search_label_rehab">
                <label>游戏名称:</label>
                <select id="game_id" name="game_name" class="select_gallery" >
                    <option value="">请选择游戏</option>
                    <volist name=":get_game_list()" id="vo">
                        <option game-id="{$vo.id}" value="{$vo.game_name}">{$vo.game_name}</option>
                    </volist>
                </select>   
            </div>
            <div class="input-list input-list-platform">
            <label>运营平台:</label>
                <select id="sdk_version1" name="sdk_version1" >
                    <option value="">请选择</option>
                    <volist name=":get_systems_list()" id="vo">
                    <gt name="key" value="0">
                    <option <if condition="$Thinkphp.get.sdk_version eq $key"> selected </if> value="{$key}">{$vo}</option>
                    </gt>
                    </volist>
                    <input type="hidden" id="sdk_version" name="sdk_version" value="{:I('sdk_version')}">
                </select>  
            </div>
            <div class="input-list">
                <a class="sch-btn" href="javascript:;" id="search" url="{:U('Developers/game','model='.$model['name'],false)}">搜索</a>
            </div>
		</div>
	</div>


    <!-- 数据列表 -->
    <div class="data_list data_game_list">
        <div class="">
            <table>
                <!-- 表头 -->
                <thead>
                    <tr>
                        <th>
                            <input class="check-all" type="checkbox">
                        </th>
                        <th >编号</th>
                        <th >排序</th>
                        <th >图标</th>
                        <th >游戏名称</th>
                        <th >游戏来源</th>
                        <th >游戏类型</th>
                        <th >开放类型</th>
                        <th >显示状态</th>
                        <th>审核状态</th>
                        <th>接入状态</th>
                        <th>创建时间</th>
                        <th >运营平台</th>
                        <th >关联游戏</th>
                        <th >操作</th>
                    </tr>
                </thead>

                <!-- 列表 -->
                <tbody>
                <empty name="list_data" >
	                <tr>
	                	<td colspan="15" class="text-center">aOh! 暂时还没有内容!</td>
	                </tr>
                <else />
                    <volist name="list_data" id="data">
                        <tr>
                            <td><input class="ids" type="checkbox" value="{$data['id']}" name="ids[]"></td>
                             <td>{$data.id}</td>
                            <td>{$data.sort}</td>
                            <td class="data_icon"><img src="{$data.pic_path}" /></td>
                            <td>{$data.game_name}</td>
                            <td>{:get_developer_name($data['developers'])}</td>
                            <td>{:get_game_type_name($data['game_type_id'])}</td>
                            <td>{:get_one_opentype_name($data['category'])}</td>
                            <td><if condition="$data.game_status eq 0"><span style="color: red ">不显示</span><else/>显示</if></td>
                            <td>{:get_info_status($data['apply_status'],5)}</td>
                            <td>
                                <a href="javascript:;"  onclick="changeGameStatus(this,{$data.id})"><if condition="$data.game_status eq 1">上线<elseif condition="($data.game_status eq 0) and ($data.apply_status eq 1)"/>下线<else/>对接中</if></a>
                            </td>
                            <td>{$data.create_time|date="Y-m-d h:i:s",###}</td>
                            <td class="">            
                                {:get_systems_name($data['sdk_version'])}
                            </td>
                            <td>
                            <if condition="get_relation_game($data['id'],$data['relation_game_id']) eq false"><a href="{:U('relation',array('id'=>$data['id']))}">点击关联</a>
                            <elseif condition="get_relation_game($data['id'],$data['relation_game_id']) eq true" /><span style="color: orange">已关联</span>
                            <else/>
                            <span style="color: red">该游戏关联数据错误</span>
                            </if>
                            </td>
                            <td>
                            <a href="{:U('Developers/gameEdit?id='.$data['id'])}">编辑</a>
                            <a href="{:U('Game/del?ids='.$data['id'])}" class="confirm ajax-get">删除</a>
                            <if condition="UID eq 1"><a href="javascript:void(0);" data-game_id="{$data.id}" data-game_name="{$data.game_name}"  data-game_appid="{$data.game_appid}"  class="duij">对接参数</a></if>
                                <a href="{:U('developers/source',['game_id'=>$data['id']])}" class="">原包</a>
                            </td>
                        </tr>
                    </volist>
                    </empty>
                </tbody>
            </table>
        </div>
    </div>
    <div class="page">
        {$_page|default=''}
    </div>
</block>

<block name="script">
<script src="__STATIC__/layer/layer.js"></script>
<script>

<volist name=":I('get.')" id="vo">
    Think.setValue('{$key}',"{$vo}");
</volist>
$(".select_gallery").select2();
</script>
<script type="text/javascript">
//导航高亮
highlight_subnav('{:U('developers/game')}');
function changeGameStatus(that,game_id){
    if(that.innerHTML=="下线") {
        //上线
        $.ajax({
            url: "{:U('set_status')}",
            type:"POST",
            dataType: 'json',
            data: {ids:game_id,status:1,field:"game_status"},
            success:function(data){
                if(data.status==1){
                    layer.msg("上线成功", {icon: 1});
                    location.reload();
                }else{
                    layer.msg("上线失败", {icon: 2});
                }
            },
            error:function(){
                layer.msg("错误", {icon: 2,})
            }
        })
    }else if(that.innerHTML=="上线"){

        //下线
        $.ajax({
            url: "{:U('set_status')}",
            type:"POST",
            dataType: 'json',
            data: {ids:game_id,status:0,field:"game_status"},
            success:function(data){
                if(data.status==1){
                    layer.msg("下线成功", {icon: 1});
                    location.reload();
                }else{
                    layer.msg("下线失败", {icon: 1});
                }
            },
            error:function(){
                layer.msg("错误", {icon: 2,})
            }
        })
    }else{
        layer.msg("请先审核",{icon:7});
    }
}
$(function(){

    $('.cooperwrap').hover(function(){
        $(this).find('.nav-list').removeClass('hidden');
    },function(){
        $(this).find('.nav-list').addClass('hidden');
    });

    $('.cooperwrap .nav-list li').find('a').each(function(){
        var that = $(this).closest('.cooperwrap'),top = $(this).closest('.cooperation');
        $(this).click(function(){
            var text = $(this).text(),val=$(this).attr('value');
            that.find('.sort-txt').text(text).attr('data',val);
            that.find('.nav-list').addClass('hidden');

            var ratio = top.siblings('.ratio').find('span').text(),
                price = top.siblings('.price').find('span').text(),
                ids = top.siblings('.allch').find('.ids'),money=0;
            val = ids.data('val')+text+','+ratio+','+price+',';
            ids.attr('value',val);
            if (text == 'CPS') {
                money = (ratio * top.siblings('.recharge').text())/100;
            } else {
                money = price * top.siblings('.number').text();
            }
            if (isNaN(money)) {money=0;}
            top.siblings('.money').text(money);
        })
    });

    $('.cpbtn').on('click',function() {
        var that = this,placeholder = $(that).data('notice'),cp = $.trim($(that).data('coom'));
        html = '<div class="noticemsg " >';
        html += '<div class="noticemain"><div class="noticeinput"><input placeholder="'+placeholder+'" type="text" class="txt" ></div>'
        html += '<div class="noticebtn cpn"><a href="javascript:;">确定</a></div></div></div>';
        $('body').append(html);
        $('.noticebtn a').on('click',function() {
            var val = $.trim($('.noticeinput input').val()),closeste = $(that).closest('.cp');
            if (val) {
                if (!/^\d+(\.\d{1})?$/.test(val)) {pop('请输入正确的数字');return false;}
                $(that).siblings('span').text(val);
                var money=0,cooperation = $.trim(closeste.siblings('.cooperation').find('.sort-txt').text());

                if (cooperation === cp) {
                    money = val * closeste.siblings('.'+(cp.toLowerCase())).text();
                }
                if (cp == 'CPS') {
                    money=money/100;
                    ratio = val;
                    price = closeste.siblings('.price').find('span').text();
                } else {
                    ratio = closeste.siblings('.ratio').find('span').text();
                    price = val;
                }
                if (isNaN(money)) {money=0;}
                closeste.siblings('.money').text(money);

                ids = closeste.siblings('.allch').find('.ids');
                val = ids.data('val')+cooperation+','+ratio+','+price+',';
                ids.attr('value',val);
            }
            $(this).closest('.noticemsg').remove();
        });
        $('.noticeinput input').keyup(function(event) {
            if (event.keyCode == 13) {
                $('.noticebtn a').click();
            }
        });
    });

    $('.confirmbtn').on('click',function() {
        var that = $(this),closeste = that.closest('.op'),
            cooperation = $.trim(closeste.siblings('.cooperation').find('.sort-txt').text()),
            ratio = closeste.siblings('.ratio').find('span').text(),
            price = closeste.siblings('.price').find('span').text(),
            url =  $(this).data('val'),index = url.lastIndexOf('.html');
        if (index > 0)
            url = url.substring(0,index)+'/cooperation/'+cooperation+'/cps_ratio/'+ratio+'/cpa_price/'+price+'.html';
        else
            url = url+'/cooperation/'+cooperation+'/cps_ratio/'+ratio+'/cpa_price/'+price+'.html';
        $(this).siblings('.settlementbtn').attr('url',url).click();
    });
	//搜索功能
	$("#search").click(function(){
		var url = $(this).attr('url');
        var query  = $('.jssearch').find('input').serialize();
        query  += "&"+$('.jssearch').find('select').serialize();
        query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g,'');
        query = query.replace(/^&/g,'');
        if( url.indexOf('?')>0 ){
            url += '&' + query;
        }else{
            url += '?' + query;
        }
		window.location.href = url;
	});

    //回车自动提交
    $('.jssearch').find('input').keyup(function(event){
        if(event.keyCode===13){
            $("#search").click();
        }
    });

    $(".duij").click(function() {
        var game_id=$(this).data("game_id");
        var game_name=$(this).data("game_name");
        var game_appid=$(this).data("game_appid");
        $.ajax({
            url: "{:U('get_game_set')}",
            type:"POST",
            dataType: 'json',
            data: {game_id:game_id},
            success:function(data){
                if(data.status==1){
                    if(data.data.game_key==""||data.data.access_key==""){
                         layer.msg("游戏key未设置或者访问秘钥未设置", {icon: 2,})
                    }else{
                        layer.open({
                          type: 1,
                          skin: 'layui-layer-demo', //样式类名
                          closeBtn: 0, //不显示关闭按钮
                          anim: 2,
                          area: ['320px', '240px'], //宽高
                          shadeClose: true, //开启遮罩关闭
                          content: "游戏ID:&nbsp&nbsp"+game_id+"<br/>"+"游戏名称:&nbsp&nbsp"+game_name+"<br/>"+"游戏appid:&nbsp&nbsp"+game_appid+"<br/>渠道ID:&nbsp&nbsp0<br/>渠道名称:&nbsp&nbsp自然注册<br/>游戏key:&nbsp&nbsp"+data.data.game_key+"<br/>"+"游戏访问密钥:&nbsp&nbsp"+data.data.access_key
                        });
                        
                    }
                }
            },
            error:function(){
              layer.msg("错误", {icon: 2,})
            }
        })

    });
    //点击排序
    $('.list_sort').click(function(){
        var url = $(this).attr('url');
        var ids = $('.ids:checked');
        var param = '';
        if(ids.length > 0){
            var str = new Array();
            ids.each(function(){
                str.push($(this).val());
            });
            param = str.join(',');
        }

        if(url != undefined && url != ''){
            
            window.location.href = url.replace(".html","") + '/ids/' + param;
        }
    });
})
</script>
<script>
    $('.side-sub-menu').eq(0).show();
    
</script>
</block>