@extends('vip.layouts')
@section('seo_title')
    {{ trans('menu.remittance') }}
@endsection
@section('content')

    <form class="layui-form" action="{{ url()->full() }}" id="submitForm" name="submitForm" method="post"
          eventType=eventAjaxForm>
        {!! csrf_field() !!}
		<label class="layui-form-label">赠送手续费</label>
		<input type="checkbox" name="checkedL" class="checkedL" onclick="checkedL()" style="vertical-align: middle; margin-right:10px;">勾选则赠送，不勾选则不赠送。同城同行汇款则不赠送<br>
        <input type="hidden" name="account_name" lay-verify="required" autocomplete="off" class="layui-input"
               value="{{$data['account_name']}}">
        <input type="hidden" name="money" lay-verify="required" autocomplete="off" class="layui-input"
               value="{{$data['money']}}">
        <input type="hidden" name="money_cash" lay-verify="required" autocomplete="off" class="layui-input"
               value="{{$data['cur_cash']}}">
        <div class="layui-form-item">
            <label class="layui-form-label">赠送比例</label>
            <div class="layui-input-block">
                <input type="text" name="point" id="point" required lay-verify="required" disabled="disabled"  autocomplete="off" class="layui-input"
                       value="0">
            </div>
        </div>
        <div class="layui-form-mid layui-word-aux">说明：如果用户充值100，比例为0.2。用户得到手续费2=100*0.002</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;
			
			$('.layui-unselect').on('click',function(){
				var check = $('.layui-form-checked').length;
				if(check==1){
					$('#point').removeAttr('disabled');
					$('.checkedL').val(1);
				}else{
					$('#point').val('0');
					$('.checkedL').val(2);
					$('#point').attr('disabled','disabled');
				}
				console.log(check);
			});
		
            $('.sub').on('click', function () {
                var name = $('input[name=account_name]').val();
                var money = $('input[name=money]').val();
                var money_cash = $('input[name=money_cash]').val();
                var point = $('input[name=point]').val();

                money = parseFloat(money);
                money_cash = parseFloat(money_cash);
                point = parseFloat(point);
                var remittance = (point / 100) * money;
                var str = '';
                str += ' <div class="layui-form-item" style="margin-top: 15px">\n' +
                    '            <label class="layui-form-label">用户名</label>\n' +
                    '            <div class="layui-input-inline">\n' +
                    '                <input type="text" class="layui-input"disabled="disabled" value="' + name + '">\n' +
                    '            </div>\n' +
                    '        </div>';
                str += ' <div class="layui-form-item" style="margin-top: 15px">\n' +
                    '            <label class="layui-form-label">赠送比例</label>\n' +
                    '            <div class="layui-input-inline">\n' +
                    '                <input type="text" class="layui-input"disabled="disabled" value="' + point + '%">\n' +
                    '            </div>\n' +
                    '        </div>';
                str += ' <div class="layui-form-item">\n' +
                    '            <label class="layui-form-label">汇款金额</label>\n' +
                    '            <div class="layui-input-inline">\n' +
                    '                <input type="text" class="layui-input" disabled="disabled" value="' + money + '">\n' +
                    '            </div>\n' +
                    '        </div>';
                str += ' <div class="layui-form-item">\n' +
                    '            <label class="layui-form-label">用户交易后余额</label>\n' +
                    '            <div class="layui-input-inline">\n' +
                    '                <input type="text" class="layui-input" disabled="disabled" value="' + (money_cash + money +remittance) + '">\n' +
                    '            </div>\n' +
                    '        </div>';
                layer.open({
                    type: 1,
                    btn: ['确定', '取消'],
                    btnAlign: 'c',
                    id: 'box',
                    content: str,
                    yes: function (index, layero) {
                        layer.close(index);
                        $('#submitForm').submit();
                    }
                });
                return false;
            });

            //监听提交
//  form.on('submit(submitForm)', function(data){
//    return true;
//  });
        });

        function cbFormSuccess(data) {
			parent.window.updateNum();
            var a = layer.alert(data.msg, {}, function () {
                //var table = window.history.go(-1);
                //执行重载 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); //再执行关闭
//				window.history.go(-1);
                window.location.href='/admin/remittance/index?status=0';
            });
        }
    </script>
@endsection
