<%@ 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 == 1){
                    $('#flag').val('yes');
                }else{
                    $('#flag').val('no');
                }
                $("#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);
                    }
                }
            });


            $("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");
                    // $("#bankNo").removeClass("required");
                    $(".type").hide();
                }
            });
            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);
            //借款人所有未还借款
        }
        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 view-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"/>
			<sys:message content="${message}"/>
			<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">
								<input htmlEscape="false"   readonly="true" class="form-control layui-input" value="${workLoan.workStaffBasicInfo.name}"/>
							</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">
							<input  htmlEscape="false"   readonly="true" class="form-control layui-input" value="${workLoan.num}"/>
							<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  htmlEscape="false"   readonly="true" class="form-control layui-input" value="${fns:getDictLabel(workLoan.type, 'loan_type','')}"/>
					</div>
				</div>
				<div class="layui-item layui-col-sm6 type">
					<label class="layui-form-label">借款项目：</label>
					<div class="layui-input-block with-icon">
						<input  htmlEscape="false" readonly="true" class="form-control layui-input" value="${workLoan.projectRecords.projectName}"/>
					</div>
				</div>
				<div class="layui-item layui-col-sm6 type">
					<label class="layui-form-label">合同金额：</label>
					<div class="layui-input-block">
						<input  htmlEscape="false" readonly="true" class="form-control layui-input" value="<fmt:formatNumber value="${workLoan.projectRecords.workContractInfo.contractPrice}" pattern="#,#0.00"/>"/>
					</div>
				</div>
				<div class="layui-item layui-col-sm6 type">
					<label class="layui-form-label double-line">合同未还款累计：</label>
					<div class="layui-input-block">
						<input  htmlEscape="false" readonly="true" class="form-control layui-input" value="<fmt:formatNumber value="${workLoan.contractNotRepay}" pattern="#,#0.00"/>"/>
					</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  htmlEscape="false" readonly="true" class="form-control layui-input" value="<fmt:formatNumber value="${workLoan.money}" pattern="#,#0.00"/>"/>
					</div>
				</div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label">未还借款累计：</label>
					<div class="layui-input-block">
						<input  htmlEscape="false" readonly="true" class="form-control layui-input" value="<fmt:formatNumber value="${workLoan.notRepay}" pattern="#,#0.00"/>"/>
					</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  type="text" readonly="true"   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">
						<input  htmlEscape="false" readonly="true" class="form-control layui-input" value="<fmt:formatNumber value="${workLoan.repay}" pattern="#,#0.00"/>"/>
					</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','')}"/>
					</div>
				</div>
				<div class="layui-item layui-col-sm12  with-textarea">
					<label class="layui-form-label">备注：</label>
					<div class="layui-input-block">
						<textarea  htmlEscape="false" rows="4" readonly="true"    class="form-control ">${workLoan.remarks}</textarea>
					</div>
				</div>
			</div>
			<div class="form-group layui-row">
				<div class="form-group-label"><h2>发票明细</h2></div>
				<div class="layui-item layui-col-xs12 form-table-container">
					<table id="contentTable" class="table table-bordered table-condensed details">
						<thead>
						<tr>
							<th width="30%">还款来源</th>
							<th width="18%">还款日期</th>
							<th width="18%">还款金额</th>
							<th width="18%">报销编号</th>
						</tr>
						</thead>
						<tbody id="workAccountList">
						<c:if test="${not empty workLoan.workRepays}">
							<c:forEach items="${workLoan.workRepays}" var="workRepay" varStatus="index">
								<tr id="workRepayList${index.index}">
									<td title="${fns:getDictLabel(workRepay.source, 'repay_source','')}">
											${fns:getDictLabel(workRepay.source, 'repay_source','')}
									</td>
									<td title="<fmt:formatDate value="${workRepay.repayDate}" pattern="yyyy-MM-dd"/>">
										<fmt:formatDate value="${workRepay.repayDate}" pattern="yyyy-MM-dd"/>
									</td>

									<td title="<fmt:formatNumber value="${workRepay.money}" pattern="#,#0.00"/>">
										<fmt:formatNumber value="${workRepay.money}" pattern="#,#0.00"/>
									</td>
									<td title="">
											${workRepay.workReimbursement.number}
									</td>
								</tr>
							</c:forEach>
						</c:if>
						</tbody>
					</table>
				</div>
			</div>
			<div class="form-group layui-row page-end"></div>
		</form:form>
	</div>
</div>
</body>
</html>