<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>发起投诉</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
<meta name="decorator" content="base" />
</head>
<body>
	<div class="">
		<div class="layui-card">
			<div class="layui-form layui-card-body "  lay-filter="layuiadmin-form-useradmin" id="layuiadmin-form-useradmin">
				<div class=" layui-form-item">
					<label class="layui-form-label">可请款金额:</label>
					<div class="layui-input-block">
						<input type="text" id="withdrawalAmount" required value="${site.withdrawableCash}" readonly class="layui-input">
					</div>
				</div>
				<input type="hidden" name="siteId" id="id" value="${siteId}"/>

				<div class="layui-form-item">
					<label class="layui-form-label"><i class="mark">*</i>请款金额:</label>
					<div class="layui-input-block">
						<input type="text" name="withdrawalAmount" required  lay-verify="required" placeholder="请输入金额" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label"><i class="mark">*</i>收款方式:</label>
					<div class="layui-input-block">
						<input type="radio" name="cashOutType" value="1" title="银行卡"  lay-filter="filter" checked>
						<input type="radio" name="cashOutType" value="2" title="支付宝"  lay-filter="filter">
					</div>
				</div>
				<div class="yinhangka">
					<div class="layui-form-item">
						<label class="layui-form-label"><i class="mark">*</i>开户名称:</label>
						<div class="layui-input-block">
							<input type="text" name="accountName" required  lay-verify="required"  autocomplete="off" class="layui-input" value="${rece.accountName}">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label"><i class="mark">*</i>开户银行:</label>
						<div class="layui-input-block">
							<input type="text" name="openingBank" required  lay-verify="required" autocomplete="off" class="layui-input" value="${rece.openingBank}">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label"><i class="mark">*</i>收款账号:</label>
						<div class="layui-input-block">
							<input type="text" name="accountNumber" required  lay-verify="required" autocomplete="off" class="layui-input" value="${rece.accountNumber}">
						</div>
					</div>
				</div>
				<div class="zhifuabo layui-hide">
				<div class="layui-form-item">
						<label class="layui-form-label"><i class="mark">*</i>支付宝名称:</label>
						<div class="layui-input-block">
							<input type="text" name="alipayName"  autocomplete="off" class="layui-input" value="${rece.alipayName}">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label"><i class="mark">*</i>支付宝账号:</label>
						<div class="layui-input-block">
							<input type="text" name="alipayNumber"  placeholder="请输入支付宝账号" autocomplete="off" class="layui-input" value="${rece.alipayNumber}">
						</div>
					</div>
				</div>
				<div class="layui-form-item " style="text-align: center;">
					<input type="button" class="layui-btn" lay-submit lay-filter="sureSubmit" id="sureSubmit" value="确认">
				</div>
			</div>
		</div>
	</div>

	<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>
	<script>
    var imgs="";
    //Demo
    layui.use(['form', 'upload'], function () {
        var form = layui.form,
        $ = layui.$;

        var checkOrder = false;
        form.on('submit(sureSubmit)', function (data) {
            $("#sureSubmit").attr("disabled","true");
            if(checkOrder){
                return false;
            }
            var dat = data.field;
            var cashOutType = dat.cashOutType;
            var siteId = dat.siteId;
            var withdrawalAmount = dat.withdrawalAmount;
            var accountName = dat.accountName;
            var openingBank = dat.openingBank;
            var accountNumber = dat.accountNumber;
            var alipayName = dat.alipayName;
            var alipayNumber = dat.alipayNumber;
            var keti = $("#withdrawalAmount").val();
            if(isBlank(withdrawalAmount)){
                layer.msg('请输入请款金额！', {icon:2});
                return false
            }
            if(withdrawalAmount > keti){
                layer.msg('输入金额大于可请款金额！', {icon:2});
                return false
			}
            if(cashOutType == 1){
                if(isBlank(accountName)){
                    layer.msg("请输入开户名称！");
                    return false;
                }
                if(isBlank(accountNumber)){
                    layer.msg("请输入收款账号！");
                    return false;
                }
                if(isBlank(openingBank)){
                    layer.msg("请输入开户银行！");
                    return false;
                }
            }else if(cashOutType==2){
                if(isBlank(alipayName)){
                    layer.msg("请输入支付宝名称！");
                    return false;
                }
                if(isBlank(alipayNumber)){
                    layer.msg("请输入支付宝账号！");
                    return false;
                }
            }

            checkOrder = true;
            $.ajax({
                type:"POST",
                url:"${ctx}/siteReceipt/saveSiteCashOut",
                data:{
                    cashOutType:cashOutType,
                    siteId:siteId,
                    withdrawalAmount:withdrawalAmount,
                    accountName:accountName,
                    accountNumber:accountNumber,
                    openingBank:openingBank,
                    alipayName:alipayName,
                    alipayNumber:alipayNumber
                },
                success:function(result){
                    checkOrder = false;
                    if(result.code ==200){
                        layer.closeAll()
                        parent.layer.closeAll();
                        parent.layer.msg('结账成功！', {icon:1,time:1000},function(){
						//parent.layui.table.reload('settlementList');
                        });
                    }else if(result.code == "505"){
                        layer.msg('保存失败!', {icon:2,time:1000},function(){
                            layer.closeAll()
                        });
                    }else{
                        layer.msg('保存失败,数据有误', {icon:2,time:1000});
                    }
                }
            });
        })

        form.on('radio(filter)', function(data){
           var val = data.value; //被点击的radio的value值
            if(val ==1){
                //银行卡lay-verify="required"
				var html
                $(".zhifuabo").addClass("layui-hide");
                $(".zhifuabo input").attr("lay-verify","");
                $(".yinhangka").removeClass("layui-hide");
                $(".yinhangka input").attr("lay-verify","required");
            }else if(val ==2){
                //支付宝
                $(".zhifuabo").removeClass("layui-hide");
                $(".zhifuabo input").attr("lay-verify","required");
                $(".yinhangka").addClass("layui-hide");
                $(".yinhangka input").attr("lay-verify","");

            }
        });

        function isBlank(val){
        	if(val==null || $.trim(val)=='' || val==undefined){
        		return true;
        	}
        	return false;
        }

    });
</script>
</body>
</html>
