<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta name="renderer" content="webkit">
    <meta name="renderer" content="ie-comp">
    <meta name="renderer" content="ie-stand">
    <meta name="csrf-token" content="{{ csrf_token() }}">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>layui在线调试</title>
    <link rel="stylesheet" href="{{ asset('frame/layui/css/layui.css') }}" media="all">
    <style>
        body {
            margin: 10px;
        }

        .demo {
            text-align: center;
            line-height: 40px;
        }

        .demo p {
            border: 1px solid #000000;
            padding: 5px 5px;
        }

        .demo input {
            width: 90%;
            height: 30px;
        }

        .tit {
            font-size: 18px;
            /*font-weight: bold;*/
        }

        .odds p {
            font-size: 0.6rem;
        }

        .menu {
            position: fixed;
            left: 0px;
            top: 20px;
            height: 500px;
            overflow: auto;
        }

        .top {
            height: 40px;
            line-height: 40px;
            padding: 0px 5px;
            font-size: 22px;
            position: fixed;
            right: 0px;
            top: 50%;
            background: #e2e2e2;
        }

        .game {
            text-align: center;
            margin-bottom: 15px;
        }

        .oneKey .layui-form-item .layui-input-inline {
            width: 100px;
        }

        .menu {
            width: 140px;
        }

        .text {
            width: 88%;
        }
    </style>
</head>
<body>


<div class="layui-row">
    <ul id="tree" class="tree-table-tree-box layui-box layui-tree">
        @foreach($gameList as $k=>$v)
            <li><a href="/admin/SixlotteryOdd/index?game={{$v['table_name']}}"><i class="layui-icon layui-tree-leaf"></i><cite>{{$v['name']}}</cite></a></li>
            
        @endforeach
    </ul>

    <div class="layui-col-sm11 layui-col-md11 text" style="float: left;">
        <h1 class="game">{{$data['name']}}</h1>
        <div class="layui-col-sm12 layui-col-md12 text oddsinfo">

        <input type="hidden" name="game" id="game" value="{{$data['game']}}">

        <div class="layui-collapse" lay-filter="test">
            <div class="layui-colla-item">
                <h2 class="layui-colla-title">赔率高级设置</h2>
                <div class="layui-colla-content layui-show">
                    <div class="oneKey"></div>
                </div>
            </div>

            <div class="layui-colla-item">
                <h2 class="layui-colla-title">赔率详细设置</h2>
                <div class="layui-colla-content">
                    <div class="demo"></div>
                </div>
            </div>
        </div>

        <p style="margin-top: 20px">
            <button class="layui-btn layui-btn-normal save" gamename="{{$game}}">保存</button>
        </p>
    </div>

    <a href="javaScript:;" class="top">TOP</a>
</div>
<div id="statusMsg" style="display: none">
     <div style="padding: 20px 100px;font-size: 22px;">共更新49条<br>成功<span  class="msg_success_num">0</span>条，失败<span class="msg_error_num">0</span>条</div>
</div>
<script type="text/javascript" src="/frame/layui/layui.js"></script>
<script src="<?php echo e(URL::asset('admin/js/jquery-1.11.3.js')); ?>" charset="utf-8"></script>
<script>
    layui.config({
        version: '1511795639295' //为了更新 js 缓存，可忽略
    });

    $.ajaxSetup({
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }
    });

    // 返回顶部
    $(document).on('click', '.top', function () {
        $('body,html').animate({scrollTop: '0px'}, 'show');
    });

//赔率显示
    function odds(data) {
        $.ajax({
            type: 'get',
            url: '/admin/game/sixSettings?game=sixlottery',
            data: data,
            dataType: 'json',
            success: function (json) {

                var str = '';
                var html = '';
                for (var i in json.data) {
                    if (i === 'parent') {
                        var Onekey = json.data[i];
                        html += '<div class=" ' + i + '" gametype="' + i + '">'
                        for (var t = 0; t < Onekey.length; t++) {
                            html += '<div class="layui-form-item odds" name="' + Onekey[t].name + '">';

                            var allType = Onekey[t].settings;
                            html += '<label class="layui-form-label">' + json.data.lang[Onekey[t].name] + '</label>';
                            for (var r in allType) {
                                if (r === 'multiple') {
                                    html += '<div class="layui-inline ' + r + '" settings=' + r + '>';
                                    for (var d in allType[r]) {
                                        var maxlang = json.data.lang[d];
                                        if(d=='max'){
                                            if(Onekey[t].name=='series_threetwo'){
                                                maxlang = '中二';
                                            }else if(Onekey[t].name=='series_twospecial'){
                                                maxlang = '中特';
                                            }
                                        }else if(d=='min'){
                                            if(Onekey[t].name=='series_threetwo'){
                                                maxlang = '中三';
                                            }else if(Onekey[t].name=='series_twospecial'){
                                                maxlang = '中二';
                                            }
                                        }
                                        
                                        html += '<label class="layui-form-label">' + maxlang + '</label>';
                                        html += '<div class="layui-input-inline">';
                                        html += '<input type="text" name="' + d + '" value="' + allType[r][d] + '" class="layui-input">';
                                        html += '</div>';
                                    }
                                    html += '</div>';
                                } else {
                                    var minlang = json.data.lang[r];
                                    html += '<div class="layui-inline ' + r + '" settings=' + r + '>';
                                    html += '<label class="layui-form-label">' + minlang + '</label>';
                                    html += '<div class="layui-input-inline">';
                                    html += '<input type="text" name="' + r + '" value="' + allType[r] + '" class="layui-input">';
                                    html += '</div>';
                                    html += '</div>';
                                }
                            }
                            html += '<div class="layui-inline">';
                            html += '<button class="layui-btn  voluation" gameDataType=' + Onekey[t].name + '>一键修改</button>';
                            html += ' </div>';
                            html += ' </div>';
                        }
                        html += '</div>';

                    } else if (i === 'lang') {

                    } else {
                        var data = json.data[i];
                        str += '<fieldset class="layui-elem-field layui-field-title " style="margin-top: 30px;">';
                        str += '<legend>' + json.data.lang[i] + '</legend>';
                        str += '</fieldset>';

                        str += '<ul class="layui-row layui-col-space5 ' + i + '" gametype="' + i + '">';
						var maxn = 0;
						if(i=='join_born'){
							maxn = 11;
						}else{
							maxn = data.length;
						}

                        for (var n = 0; n < maxn; n++) {
                            var current = data[n];

                            str += '<li class="layui-col-md2">';
                            str += '<p class="tit layui-bg-gray">' + json.data.lang[current.name] + '</p>';
                            str += '<div class="odds ' + current.name + '" name="' + current.name + '">';

                            for (var x in current.settings) {
                                var judge = current.settings;
                                if (x == 'cost') {
                                    str += '<div class="layui-row ' + x + '" settings=' + x + '>';
                                    for (var h = 0; h < judge.cost.length; h++) {
                                        var section = judge.cost[h];
                                        str += '<p class="layui-col-xs6">' + section.max + '-' + section.min + '</p>';
                                        str += '<p class="layui-col-xs6">';
                                        str += '<input min="' + section.min + '" max="' + section.max + '" name="' + current.name + '"  value="' + section.multiple + '"/>';
                                        str += '</p>';
                                    }
                                    str += '</div>';
                                } else if (x == 'multiple') {
                                    str += '<div class="layui-row ' + x + '" settings=' + x + '>';
                                    for (var l in judge.multiple) {
                                        var mname = json.data.lang[l];
                                        if(i=='join_born'){
                                            if(l=='max'){
                                                mname = '中';
                                            }else{
                                                mname = '不中';
                                            }
                                        }
                                        str += '<p class="layui-col-xs6">' + mname + '</p>';
                                        str += '<p class="layui-col-xs6">';
                                        str += '<input name="' + l + '"  value="' + judge.multiple[l] + '"/>'
                                        str += '</p>';
                                    }
                                    str += '</div>';
                                } else {
                                    str += '<div class="layui-row ' + x + '"settings=' + x + '>';
                                    str += '<p class="layui-col-xs6">' + json.data.lang[x] + '</p>';
                                    str += '<p class="layui-col-xs6">';
                                    str += '<input name="' + x + '" value="' + judge[x] + '"/>';
                                    str += '</p>';
                                    str += '</div>';
                                }
                            }

                            str += '</div>';

                            str += '</li>';
                        }

                        str += '</ul>';
                    }

                }

                $('.demo').html(str);
                $('.oneKey').html(html);

            },
            error: function () {
            }
        });
    }
    var game=$('#game').val();
    var  obj={game: 'sixlottery'};
    if(game==''){
        obj={game: 'sixlottery'};
    }else{
        var str='{"game": "'+game+'"}';
        obj=JSON.parse(str);
    }
    // console.log(obj);
    odds(obj);


//赔率详情设置折叠
    layui.use(['element', 'layer'], function(){
      var element = layui.element;
      var layer = layui.layer;
      
      //监听折叠
      element.on('collapse(test)', function(data){
        //layer.msg('展开状态：'+ data.show);
      });
      var menu = [];
    });
    var postCount={'success':0,'fail':0};
    var postCurData=[];
    function postData(pwd,cdata,gtype) {
            var game = $('.save').attr('gamename');
              $.ajax({
                type: 'POST',
                url: '/admin/game/SetSixlotteryOddsone?game=' + game,
                data: {password:pwd,data:cdata,gametype:gtype},
                dataType: 'text',
                success: function (json) { 
                    json = JSON.parse(json);
                    if (json.status == 1) {
                        // smsg = json.msg;
                        postCount.success=postCount.success+1;
                        /*layer.open({
                            title: '系统提示',
                            type: 0,
                            id: 'layerDemo',
                            btnAlign: 'c',//按钮居中
                            content: '<div style="padding: 20px 100px;font-size: 22px;">' + json.msg + '</div>'
                        });*/
                    } else {
                        postCount.fail=postCount.fail+1;
                        //layer.msg(json.msg)
                    }
                    if(json.status==-7010001622){
                        layer.msg(json.msg);
                    }else{
                        $('.msg_success_num').html(postCount.success);
                        $('.msg_error_num').html(postCount.fail);
                        
                        if(postCurData.length>0){
                            var pdata=postCurData.pop();
                            postData(pdata.password,pdata.data,pdata.gameType);
                        }
                    }
                }
            });
        }
//修改赔率
    $(function () {
        var height = document.documentElement.clientHeight;
        $('.menu').css({height: (height - 30)});
        //一键修改

        $(document).on('click', '.voluation', function () {
            var gameType=$(this).attr('gamedatatype');
            //获取该按钮前的几个值
            var div=$('div[name='+gameType+']');
            var back=$(div).find('input[name=back]').val();
            var max=$(div).find('input[name=max]').val();
            var min=$(div).find('input[name=min]').val();
//            var ul=$('ul[gametype='+gameType+'] input[name=back]');
            $('ul[gametype='+gameType+'] input[name=back]').val(back);
            $('ul[gametype='+gameType+'] input[name=max]').val(max);
            $('ul[gametype='+gameType+'] input[name=min]').val(min);
            layer.alert('一键设置完毕，请保存');
            return;

            /*layer.prompt({
                title: '二级密码',
                formType: 1,
            },function(q, index, elem){
                //alert(value); //得到value

                var obj = {};
                var n = $("*[gametype]");
                var game = $('.save').attr('gamename');
                console.log(n);
                $(n).each(function () {
                    var gameType = $(this).attr('gametype');
                    console.log(gameType);
                    obj[gameType] = []

                    var oneData = $(this).find('.odds');

                    $(oneData).each(function () {
                        var data = {};
                        var name = $(this).attr('name');
                        data.name = name;

                        var backs = $(this).find('.back').find('input[name=back]').val();
                        data.settings = {};

                        var n = {}
                        if (backs !== undefined) {
                            n.back = backs;
                        }
                        //                n.multiple = {}
                        var c = {}
                        $(this).find('.multiple').find('input').each(function () {
                            var na = $(this).attr('name');
                            var val = $(this).val();
                            c[na] = val;
                        });

                        var cost = [];
                        $(this).find('.cost').find('input').each(function () {
                            var min = $(this).attr('min');
                            var max = $(this).attr('max');
                            var val = $(this).val();

                            var f = {
                                min: min,
                                max: max,
                                multiple: val
                            }
                            cost.push(f)
                        });
                        n.multiple = c;
                        data.settings = n;

                        if (cost.length !== 0) {
                            data.settings['cost'] = cost;
                        } else {

                        }

                        obj[gameType].push(data)
                    });

                });

                $.ajax({
                    type: 'POST',
                    url: '/admin/game/setSettings?game=' + game,
                    data: {password:value,data: obj},
                    dataType: 'json',
                    success: function (json) {
                        if (json.status === 1) {
                            layer.open({
                                title: '系统提示',
                                type: 0,
                                id: 'layerDemo',
                                btnAlign: 'c',//按钮居中
                                content: '<div style="padding: 20px 100px;font-size: 22px;">' + json.msg + '</div>'
                            });
                        } else {
                            layer.msg(json.msg)
                        }
                    }
                });

                layer.close(index);
            });*/

        });



        $(document).on('click', '.save', function () {
            postCount={'success':0,'fail':0};
            postCurData=[];
            layer.prompt({
                title: '二级密码',
                formType: 1,
            },function(value, index, elem){
                //alert(value); //得到value

                var obj = {};
                var objdatas = {};
                var objdatae = {};
                var flag = 1;
                var exetime = 100;
                var smsg = '成功';
                var n = $("*[gametype]");
                var game = $('.save').attr('gamename');
                $(n).each(function () {
                    var curdata = {};
                    var gameType = $(this).attr('gametype');
                    if(gameType!='1150'&&gameType!='1199'&&gameType!='series_three'&&gameType!='series_two'&&gameType!='series_specialmix'&&gameType!='series_four'&&gameType!='selfselect_fivelose'&&gameType!='selfselect_sixlose'&&gameType!='selfselect_sevenlose'&&gameType!='selfselect_eightlose'&&gameType!='selfselect_ninelose'&&gameType!='selfselect_tenlose'&&gameType!='selfselect_elevenlose'&&gameType!='selfselect_twelvelose'){
                         obj[gameType] = []
                    }

                    var oneData = $(this).find('.odds');

                    $(oneData).each(function () {
                        var data = {};
                        var name = $(this).attr('name');
                        data.name = name;
                        if(name=='special_code_a'){
                            flag++;
                        }
                        var backs = $(this).find('.back').find('input[name=back]').val();
                        data.settings = {};

                        var n = {}
                        if (backs !== undefined) {
                            n.back = backs;
                        }
                        //                n.multiple = {}
                        var c = {}
                        $(this).find('.multiple').find('input').each(function () {
                            var na = $(this).attr('name');
                            var val = $(this).val();
                            c[na] = val;
                        });

                        var cost = [];
                        $(this).find('.cost').find('input').each(function () {
                            var min = $(this).attr('min');
                            var max = $(this).attr('max');
                            var val = $(this).val();

                            var f = {
                                min: min,
                                max: max,
                                multiple: val
                            }
                            cost.push(f)
                        });
                        n.multiple = c;
                        data.settings = n;

                        if (cost.length !== 0) {
                            data.settings['cost'] = cost;
                        } else {

                        }
                        if(gameType!='1150'&&gameType!='1199'&&gameType!='series_three'&&gameType!='series_two'&&gameType!='series_specialmix'&&gameType!='series_four'&&gameType!='selfselect_fivelose'&&gameType!='selfselect_sixlose'&&gameType!='selfselect_sevenlose'&&gameType!='selfselect_eightlose'&&gameType!='selfselect_ninelose'&&gameType!='selfselect_tenlose'&&gameType!='selfselect_elevenlose'&&gameType!='selfselect_twelvelose'){
                            /*if(name=='special_code_a' && flag<25){
                                obj[gameType].push(data)
                            }else{
                                obj[gameType].push(data)
                            }*/
                            obj[gameType].push(data)
                        }
                    });
                    curdata = JSON.stringify( obj[gameType] );
                    if(gameType=='special_code_a'){
                        curdata = curdata.replace(/special_code_a/g, '1');
                    }
                    postCurData.push({'password':value,'data':curdata,'gameType':gameType});
                });
                 var pdata=postCurData.pop();
                if(postCurData.length>0){
                    postData(pdata.password,pdata.data,pdata.gameType);
                }
                setTimeout(function() {
                    layer.open({
                        title: '系统提示',
                        type: 0,
                        id: 'layerDemo',
                        btnAlign: 'c',//按钮居中
                        content:'<div style="padding: 20px 100px;font-size: 22px;">共更新49条：<br>成功<span  class="msg_success_num">0</span>条，失败<span class="msg_error_num">0</span>条</div>',
                    });
                }, exetime);
                layer.close(index);
            });

        })

    });
    //输入限制，只能输入数字含小数
    $('body .oddsinfo').on('keyup','input',function () {
        $(this).val($(this).val().replace(/[^0-9.]/g,''));
    })

</script>
</body>
</html>
