<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/webpage/include/taglib.jsp"%>
<html>
<head>
	<title>借款管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
        var validateForm;
        function doSubmit(obj){//回调函数，在编辑和保存动作时，供openDialog调用提交表单。
            if(validateForm.form()){
                if(obj == 2){
                    $("#flag").val("no");
                }else{
                    $("#flag").val("yes");
                }
                $("#inputForm").submit();
                return true;
            }else {
                parent.layer.msg("信息未填写完整!", {icon: 5});
            }
            return false;
        }
        $(document).ready(function() {
            validateForm = $("#inputForm").validate({
                submitHandler: function(form){
                    loading('正在提交，请稍等...');
                    form.submit();
                },
                errorContainer: "#messageBox",
                errorPlacement: function(error, element) {
                    $("#messageBox").text("输入有误，请先更正。");
                    if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
                        error.appendTo(element.parent().parent());
                    } else {
                        error.insertAfter(element);
                    }
                }
            });

             laydate.render({
				elem: '#loanDate',
                event: 'focus',
		   		type : 'date'
            	});

            $("input[name='type']").on('ifChecked', function(event){
                var radioVal = $(this).val();
                console.log(radioVal+"----------radioVal");
                if(radioVal == 2){
                    $("#projectRecordsName").attr("class","form-control layui-input required");
                    $(".type").show();
                    //  $("#bank").addClass("required");
                }else{
                    $("#projectRecordsName").attr("class","form-control layui-input");
                    $(".type").hide();
                    // $("#bankNo").removeClass("required");
                }
            });
            if("${workLoan.type}" == "2"){
                $("#ext1").iCheck('check');
                $("#projectRecordsName").attr("class","form-control layui-input required");
                $(".type").show();
            }else{
                $("#ext").iCheck('check');
                $("#projectRecordsName").attr("class","form-control layui-input");
                $(".type").hide();
            }
        });

        /*function setValuesss(obj){
            $.ajax({
                type:'post',
                url:'${ctx}/workcontractrecord/workContractRecord/getPNumberr',
                data:{
                    "obj":obj
                },
                success:function(data){
                    var d = JSON.parse(data);
                    $("#recordNum").val(d.recordNum);
                    $("#contractNum").val(d.contractNum);
                    $("#cName").val(d.cName);
                    $("#contractType").val(d.contractType);
                }
            })
        }*/


        function selectUserInfo(id) {
            $.ajax({
                type:'post',
                data:{
                    "id":id
                },
                url:'${ctx}/workregularapply/workRegularApply/userInfo',
                success:function(data){
                    setUserInfo(data);
                }
            })
        }
        function setUserInfo(obj){
            $("#officeName").val(obj.office.name);
            $("#bankCard").val(obj.bankCard);
            $("#projectRecordsId").val("");
            $("#projectRecordsName").val("");
            $("#contractPrice").val("");
            $("#contractNotRepay").val("");
            //借款人所有未还借款
        }
        function setValue(obj){
            $.ajax({
                type:'post',
                url:'${ctx}/workloan/workLoan/getProjectInfo',
                data:{
                    "obj":obj
                },
                success:function(data){
                    var d = JSON.parse(data);
                    $("#contractPrice").val(d.contractPrice);
                }
            })
        }
	</script>
</head>
<body>
<div class="single-form">
	<div class="container">
		<form:form id="inputForm" modelAttribute="workLoan" action="${ctx}/workloan/workLoan/saveAudit" method="post" class="form-horizontal">
			<form:hidden path="id"/>
			<form:hidden path="home"/>
			<form:hidden path="act.taskId"/>
			<form:hidden path="act.taskName"/>
			<form:hidden path="act.taskDefKey"/>
			<form:hidden path="act.procInsId"/>
			<form:hidden path="act.procDefId"/>
			<form:hidden id="flag" path="act.flag"/>
			<div class="form-group layui-row first lw8">
				<div class="form-group-label"><h2>基础信息</h2></div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label"><span class="require-item">*</span>借款人：</label>
						<div class="layui-input-block with-icon">
							<div class="input-group">
								<sys:gridSelectUserRship id="sId" name="workStaffBasicInfo.id" value="${workLoan.workStaffBasicInfo.id}" labelName="workStaffBasicInfo.name" labelValue="${workLoan.workStaffBasicInfo.name}"
														 title="用户" url="${ctx}/sys/office/gridSelectUser" cssClass="form-control required layui-input" isAll="true" type="2"  isSingle="true"></sys:gridSelectUserRship>
							</div>
						</div>
				</div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label"><span class="require-item">*</span>借款编号：</label>
					<div class="layui-input-block">
						<div class="input-group">
							<form:input id="num" path="num" htmlEscape="false"   readonly="true" class="form-control layui-input"/>
							<span class="input-group-btn">
								<label class="form-status"><c:choose><c:when test="${ empty workLoan.status}">新添</c:when><c:otherwise>${fns:getDictLabel(workLoan.status, 'audit_state','')}</c:otherwise>	</c:choose></label>
							</span>
						</div>
					</div>
				</div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label">所属部门：</label>
					<div class="layui-input-block">
						<form:input id="officeName" path="workStaffBasicInfo.office.name" htmlEscape="false" readonly="true" class="form-control  layui-input"/>
					</div>
				</div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label">银行卡号：</label>
					<div class="layui-input-block">
						<form:input id="bankCard" path="workStaffBasicInfo.bankCard" htmlEscape="false" readonly="true" class="form-control  layui-input"/>
					</div>
				</div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label"><span class="require-item">*</span>借款类型：</label>
					<div class="layui-input-block">
						<input type="radio" class="i-checks" name="type" checked id="ext" value="1">
						<label for="ext">行政借款</label>
						<input type="radio" class="i-checks" name="type" id="ext1" value="2">
						<label for="ext1">项目借款</label>
					</div>
				</div>
				<div class="layui-item layui-col-sm6 type">
					<label class="layui-form-label">借款项目：</label>
					<div class="layui-input-block with-icon">
						<sys:gridloanproject url="${ctx}/workloan/workLoan/selectproject" id="projectRecords" name="projectRecords.id"  value="${workLoan.projectRecords.id}"  title="选择项目" labelName="projectRecords.projectName"
												   labelValue="${workLoan.projectRecords.projectName}" cssClass="form-control layui-input" fieldLabels="工程" fieldKeys="projectName" searchLabel="工程名称" searchKey="projectName" ></sys:gridloanproject>
					</div>
				</div>
				<div class="layui-item layui-col-sm6 type">
					<label class="layui-form-label">合同金额：</label>
					<div class="layui-input-block">
						<form:input id="contractPrice" path="projectRecords.workContractInfo.contractPrice" htmlEscape="false"  readonly="true"  class="form-control number layui-input"/>
					</div>
				</div>
				<div class="layui-item layui-col-sm6 type">
					<label class="layui-form-label double-line">合同未还款累计：</label>
					<div class="layui-input-block">
						<form:input id="contractNotRepay" path="contractNotRepay" htmlEscape="false"  readonly="true"  class="form-control number layui-input"/>
					</div>
				</div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label"><span class="require-item">*</span>借款金额：</label>
					<div class="layui-input-block">
						<form:input path="money" htmlEscape="false"    class="form-control number required layui-input"/>
					</div>
				</div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label">未还借款累计：</label>
					<div class="layui-input-block">
						<form:input path="notRepay" htmlEscape="false"  readonly="true"  class="form-control number layui-input"/>
					</div>
				</div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label">申请人：</label>
					<div class="layui-input-block">
						<form:input path="createBy.name" htmlEscape="false"  readonly="true"  class="form-control  layui-input"/>
					</div>
				</div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label"><span class="require-item">*</span>借款日期：</label>
					<div class="layui-input-block">
						<input id="loanDate" name="loanDate" type="text" class="laydate-icondate form-control layer-date layui-input laydate-icon required"
							   value="<fmt:formatDate value="${workLoan.loanDate}" pattern="yyyy-MM-dd"/>"/>
						</input>
					</div>
				</div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label">还款金额：</label>
					<div class="layui-input-block">
						<form:input path="repay" htmlEscape="false"  readonly="true"  class="form-control number layui-input"/>
					</div>
				</div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label">还款状态：</label>
					<div class="layui-input-block">
						<input id="repayState" htmlEscape="false" readonly="true" class="form-control  layui-input" value="${fns:getDictLabel(workLoan.repayState, 'repay_state','')}"/>
						<input name="repayState"  htmlEscape="false" type="hidden" class="form-control  layui-input" value="${workLoan.repayState}"/>
					</div>
				</div>
				<div class="layui-item layui-col-sm12  with-textarea">
					<label class="layui-form-label">备注：</label>
					<div class="layui-input-block">
						<form:textarea path="remarks" htmlEscape="false" rows="4" maxlength="255"   class="form-control "/>
					</div>
				</div>
			</div>
			<div class="form-group layui-row page-end"></div>
		</form:form>
	</div>
</div>
</body>
</html>