@extends('vip.layouts')
@section('content')

    <form class="layui-form" action="{{ url()->full() }}" id="submitForm" name="submitForm" method="post"
          eventType="eventAjaxForm" lay-filter="submitForm">
        {!! csrf_field() !!}

        <div class="layui-form-item">
            <label class="layui-form-label" style="width: 200px;">代理名&nbsp;</label>
            <div class="layui-input-inline">
                <input type="text" id="agent_name" name="agent_name" required lay-verify="required" placeholder="" autocomplete="off"
                       class="layui-input" value="{{isset($data['agent_user'])?$data['agent_user']:''}}" readonly="readonly">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label" style="width: 200px;">代理等级&nbsp;</label>
            <div class="layui-input-inline">
                <input type="text" name="phone" required lay-verify="required" placeholder="" autocomplete="off"
                class="layui-input" value="{{isset($data['grade'])?$data['grade']:''}}" disabled="disabled">
            </div>
        </div>

        {{--<div class="layui-form-item">--}}
            {{--<label class="layui-form-label" style="width: 200px;">代理类型&nbsp;</label>--}}
            {{--<div class="layui-input-inline">--}}
                {{--<input type="text" name="phone" required lay-verify="required" placeholder="" autocomplete="off"--}}
                       {{--class="layui-input" value="{{isset($data['type'])?$data['type']:''}}" disabled="disabled">--}}
            {{--</div>--}}
        {{--</div>--}}


        <div class="layui-form-item">
            <label class="layui-form-label" style="width: 200px;">个人分成比例（百分比）&nbsp;</label>
            <div class="layui-input-inline">
                <input type="text" name="ratio"  id="ratio"required lay-verify="required" placeholder="" autocomplete="off"
                       class="layui-input" value="{{isset($data['ratio'])?$data['ratio']:''}}" readonly="readonly">
            </div>
            <div class="layui-input-inline">
                <a class="layui-btn layui-btn-normal" href="/admin/Agent/selfRatio?id={{$data['id']}}">修改结算比例</a>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label" style="width: 200px;">结算开始时间</label>
            <div class="layui-input-inline">
                <input type="text" name="star_time" id="star_time" placeholder=" - " lay-verify=""
                       autocomplete="off" class="layui-input test-item" eventType=event-query
                       value="{{trans('status.default_time.seven_day')}}">
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">结束时间</label>
                <div class="layui-input-inline">
                    <input type="text" name="end_time" id="end_time" placeholder=" - " lay-verify=""
                           autocomplete="off" class="layui-input test-item" eventType=event-query
                           value="{{trans('status.default_time.etime')}}">
                </div>
            </div>
            <input type="button" class="layui-btn layui-btn-warm" onclick="sumMoney()" value="计算金额">
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label" style="width: 200px;">所选时间流水&nbsp;</label>
            <div class="layui-input-inline">
                <input type="text" name="water" required lay-verify="required" placeholder="" autocomplete="off"
                       class="layui-input" value="0" readonly="readonly">
            </div>
            <div class="layui-input-inline">
                <span style="color: red">*若个人分成比例未0则按默认的等级分成比例计算</span>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label" style="width: 200px;">所选时间盈利&nbsp;</label>
            <div class="layui-input-inline">
                <input type="text" name="profit" required lay-verify="required" placeholder="" autocomplete="off"
                       class="layui-input" value="0" readonly="readonly">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label" style="width: 200px;">结算金额<font color="red"> (流水*分成比例)</font></label>
            <div class="layui-input-inline">
                <input type="text" name="getMoney" required lay-verify="required" placeholder="" autocomplete="off"
                       class="layui-input" value="0">
            </div>
            <div class="layui-form-mid layui-word-aux">*系统自动计算的结算金额，也可以手动编辑结算金额</div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label" style="width: 200px;">结算方式</label>
            <div class="layui-input-block">
                <input type="radio" name="type" lay-filter="test" value="1" title="结算到代理" checked>
                <input type="radio" name="type" lay-filter="test" value="2" title="结算到用户" >
            </div>
            <div class="layui-form-mid layui-word-aux">*结算到用户将结算金额直接结算到代理得到用户账号</div>
        </div>

        <div class="layui-form-item" id="select_show" style="display: none">
            <label class="layui-form-label" style="width: 200px;">结算理由</label>
            <div class="layui-input-inline">
                <input type="text" name="reason" placeholder="" autocomplete="off"
                       class="layui-input" value="">
            </div>
            <div class="layui-form-mid layui-word-aux">*结算到用户的理由</div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn sub" lay-submit lay-filter="submitForm">确认</button>
            </div>
        </div>
    </form>

    <script>
        //Demo
        layui.use(['form'], function () {
            var form = layui.form;
        //监听提交
        form.on('submit(submitForm)', function (data) {
            return true;
        });
//        function cbFormSuccess(data) {
//            layer.msg(data.msg);
//            var table = window.parent.tab;
//            //执行重载
//            table.reload({
//                page: {
//                    curr: 1 //重新从第 1 页开始
//                }
//                , where: {
//                    account: $("#account_name", parent.document).val(),
//                    sureblur: $('.layui-form-switch', parent.document).text(),
//                }
//            });
//            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
//            parent.layer.close(index); //再执行关闭
//        }
            form.on('radio(test)', function (data) {
                if (data.value == 1) {
                    $('#select_show').hide();
                } else {
                    $('#select_show').show();
                }
            });
        });
        layui.use('laydate', function(){
            var laydate = layui.laydate;
            lay('.test-item').each(function(){
                laydate.render({
                    elem: this
                    ,type: 'date'
                    ,trigger: 'click'
                    ,btns:['now']
                    ,done: function(value, date){
                        $('.lay-btn-diy').click();
                    }
                });
            });
        });
//        //默认隐藏
//        var type = $('input[name="type"]:checked').val();
//        if (type == 2) {
//            $('#select_show').hide();
//        }
        //
        function sumMoney() {
            var str_time=$('#star_time').val();
            var end_time=$('#end_time').val();
            var agent_name=$('#agent_name').val();
            var ratio=$('#ratio').val();
            console.log(agent_name);
            if(str_time==''||end_time==''){
                layer.msg('请选择计算时间');
            }
            $.ajax({
                url:'/admin/agent/SumMoney',
                type:'post',
                dataType:'json',
                data:{str_time:str_time,end_time:end_time,agent_name:agent_name,ratio:ratio},
                success:function (data) {
                    layer.msg(data.msg);
                    console.log(data);
                    var val=data.data;
                    $('input[name="water"]').val(val.money);
                    $('input[name="profit"]').val(val.profit);
                    $('input[name="getMoney"]').val(val.profit);
                }
            });
        }
    </script>
@endsection
