@extends('vip.layouts')
@section('content')
    <style>
        .layui-form-switch em {
            width: auto;
        }

        .form-span{
            position: absolute;
            right: 0px;
            top: 1px;
            height: 95%;
            border-width: 0 1px 0 0;
            width: 110px;
            color: #ffffff;
            padding: 8px 15px;
            line-height: 20px;
            border-radius: 2px 0 0 2px;
            text-align: center;
            background-color: #009688;
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
            box-sizing: border-box;
            cursor: pointer;
        }
    </style>
    <!---注单管理-->
    <div class="layui-row">
        <div class="layui-col-sm12 layui-col-md12 text" >
            <form class="layui-form layui-form-pane" action="">

                <div class="layui-form-item" pane>
                    <label class="layui-form-label">本站余额</label>
                    <div class="layui-input-block">
                        <input type="text" name="o" required="" lay-verify="required" readonly="readonly"
                               autocomplete="off" class="layui-input" id="usercash" value="￥{{ $cash }}">
                    </div>
                </div>
                <div id="balancelist"></div>
{{--                @foreach($data as $k=>$v):
                <div class="layui-form-item" pane>
                    <label class="layui-form-label">{{ $data[$k]['game_name'] }}</label>
                    <div class="layui-input-block">
                        <input type="text" name="o" required="" lay-verify="required" readonly="readonly"
                               autocomplete="off" class="layui-input" id="kyinput" value="￥{{ $data[$k]['money'] }}">
                    </div>
                    <label class="form-span" onclick="setBalance('{{ $data[$k]['game_type'] }}','{{ $localuser }}','kyinput','{{ $data[$k]['money'] }}')">取回到余额</label>
                </div>
                @endforeach--}}

            </form>
        </div>
    </div>
    <script>

        var list = []
        gameList ()
       function gameList(){
           $.ajax({
               url: '/Admin/Rgame/getGameList',
               dataType: 'json',
               data: {},
               type: 'get',
               success:function(data){
                   getGameListHtml(data)
               }
           });
       }

        /**
         * 获取游戏列表
         */
        function getGameListHtml(list) {
            var htmlstr =   '';
            $.each(list,function (x,i) {
                htmlstr +=getBalance(i)
                return htmlstr;
            })


        }
        function getBalance(gametype) {
            var html    =   ''
            var localuser   =   "{{ $localuser }}"
            $.ajax({
                url: '/Admin/Rgame/getBalance?gametype='+gametype+'&localuser='+localuser,
                dataType: 'json',
                data: {},
                type: 'get',
                success:function(data){

                      html=   '                <div class="layui-form-item" pane>\n' +
        '                    <label class="layui-form-label">'+ data.game_name+'</label>\n' +
        '                    <div class="layui-input-block">\n' +
        '                        <input type="text" name="o" required="" lay-verify="required" readonly="readonly"\n' +
        '                               autocomplete="off" class="layui-input" id="kyinput" value="'+data.money+'">\n' +
        '                    </div>\n' +
        '                    <label class="form-span" onclick="setBalance(\''+data.game_type+'\',\''+localuser+'\',kyinput,\''+data.money+'\')">取回到余额</label>\n' +
        '                </div>';

                    $('#balancelist').append(html)
                }
            });
            return 1;

        }

        //取回余额
        function setBalance(gametype, localuser, inputid, money)
        {

            if(parseInt(money) <= 0)
            {
                layer.msg('当前游戏余额为0，不能取回！');
            }
            else
            {
                var index = layer.load(1, {
                    shade: [0.5,'#000'] //0.1透明度的白色背景
                });

                $.ajax({
                    url: '/Admin/Rgame/gameTransferCreditNew',
                    dataType: 'json',
                    data: {gametype:gametype,localuser:localuser},
                    type: 'get',
                    success:function(data){

                        if(data.status == 1)
                        {
                            var usercash = parseInt({{ $cash }}) + parseInt(data.data.money);

                            $('#usercash').val(usercash.toFixed(2));



                            layer.msg('取回余额成功');
                            location.reload()
                        }
                        else
                        {
                            layer.msg(data.msg);
                        }

                        layer.close(index);
                    }
                });
            }
        }
    </script>
@endsection