<%@ 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,comfirmMoney;
		$(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);
					}
				}
			});
			//获取合同金额
			if("${countFlag}" != "0"){
				$("#arrangeMoney").attr("readOnly",true);
			}else{
                $("#arrangeMoney").attr("readOnly",false);
			}
			//新增 不做处理
			if("${flag}" == "0"){

			}else{
                comfirmMoney = parseFloat("${workFullPay.confirmPayMoney}") || 0; //本次核算金额
                $('#confirmPayMoney').blur(function(){
                    var arrangeMoney = parseFloat($("#arrangeMoney").val()) || 0;
                    var totalPayMoney = parseFloat("${workFullPay.totalPayMoney}") || 0;
//					var completePerPay = $("#completePerPay").val();
                    var nowVal = parseFloat($(this).val()) || 0; //输入的值
                    if(arrangeMoney){
                        //输入的值比查出的值打  就用输入的值减去查出的值 + 累计金额 记为截至目前已经累计的金额
                        if(nowVal > comfirmMoney){
                            var conf = nowVal - comfirmMoney;
                            $("#totalPayMoney").val(totalPayMoney + conf);
                            $("#completePerPay").val(((totalPayMoney + conf) * 100 / arrangeMoney).toFixed(2))
                        }else if(nowVal < comfirmMoney){
                            var conf = comfirmMoney - nowVal;
                            $("#totalPayMoney").val(totalPayMoney - conf);
                            $("#completePerPay").val(((totalPayMoney - conf) * 100 / arrangeMoney).toFixed(2));
                        }else{
                            $("#totalPayMoney").val(totalPayMoney);
                            $("#completePerPay").val(((totalPayMoney) * 100 / arrangeMoney).toFixed(2));
                        }
                    }
                });
			}

		});
        function doSubmit(obj){//回调函数，在编辑和保存动作时，供openDialog调用提交表单。
            if(validateForm.form()){
                if(obj == 1){
                    $("#inputForm").attr("action","${ctx}/workfullmanage/workFullPay/save");
                }else{
                    $("#inputForm").attr("action","${ctx}/workfullmanage/workFullPay/store");
                }
                $("#inputForm").submit();
                return true;
            }else {
                parent.layer.msg("信息未填写完整!", {icon: 5});
            }
            return false;
        }
	</script>
</head>
<body class="hideScroll">
	<form:form id="inputForm" modelAttribute="workFullPay"  method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<input type="hidden" value="${manage_id}" name="workFullManageId" />
		<sys:message content="${message}"/>
		<table class="table table-bordered  table-condensed dataTables-example dataTable no-footer">
		   <tbody>
				<tr>
					<td class="width-15 active"><label class="pull-right"><font color="red">*</font>申请单位：</label></td>
					<td class="width-35">
						<form:input path="applyUnit" htmlEscape="false"    class="form-control required"/>
					</td>
					<td class="width-15 active"><label class="pull-right"><font color="red">*</font>付款内容：</label></td>
					<td class="width-35">
						<form:input path="payContent" htmlEscape="false"    class="form-control required"/>
					</td>
				</tr>
				<tr>
					<td class="width-15 active"><label class="pull-right"><font color="red">*</font>施工标段：</label></td>
					<td class="width-35">
						<form:input path="constructionTender" htmlEscape="false"    class="form-control required"/>
					</td>
					<td class="width-15 active"><label class="pull-right"><font color="red">*</font>本次申请金额(元)：</label></td>
					<td class="width-35">
						<form:input path="thisApplyMoney" htmlEscape="false"    class="form-control required number"/>
					</td>
				</tr>
				<tr>
					<td class="width-15 active"><label class="pull-right"><font color="red">*</font>合同金额(元)：</label></td>
					<td class="width-35">
						<form:input path="arrangeMoney" id="arrangeMoney" htmlEscape="false"  readonly="true"  class="form-control required number"/>
					</td>
					<td class="width-15 active"><label class="pull-right"><font color="red">*</font>合同最高支付金额(元)：</label></td>
					<td class="width-35">
						<form:input path="arrangePayMoney" htmlEscape="false"    class="form-control required number"/>
					</td>
				</tr>
				<tr>
					<td class="width-15 active"><label class="pull-right"><font color="red">*</font>核定支付金额(元)：</label></td>
					<td class="width-35">
						<form:input path="confirmPayMoney" id="confirmPayMoney" htmlEscape="false"     class="form-control required number"/>
					</td>
					<td class="width-15 active"><label class="pull-right"><font color="red">*</font>累计付款金额(元)：</label></td>
					<td class="width-35">
						<form:input path="totalPayMoney" id="totalPayMoney" htmlEscape="false"  readonly="true"   class="form-control"/>
					</td>
				</tr>
				<tr>
					<td class="width-15 active"><label class="pull-right"><font color="red">*</font>完成工程产值：</label></td>
					<td class="width-35">
						<form:input path="completeEngeerValue" htmlEscape="false"    class="form-control required"/>
					</td>
					<td class="width-15 active"><label class="pull-right"><font color="red">*</font>完成合同付款比例(%)：</label></td>
					<td class="width-35">
						<form:input path="completePerPay" id="completePerPay" htmlEscape="false" readonly="true"   class="form-control"/>
					</td>
				</tr>
				<tr>
					<td class="width-15 active"><label class="pull-right"><font color="red">*</font>完成进度(%)：</label></td>
					<td class="width-35">
						<form:input path="completeProcess" htmlEscape="false"    class="form-control required number"/>
					</td>
				</tr>
				<tr>
					<td class="width-15 active"><label class="pull-right">备注信息：</label></td>
					<td class="width-35" colspan="3">
						<form:textarea path="remarks" htmlEscape="false" rows="4"    class="form-control "/>
					</td>
				</tr>
			</tbody>
		</table>
	</form:form>
	<%--<div style="height: 60px;"></div>--%>
	<%--<div class="" style="position:fixed; bottom:0;background: #ffffff;width: 100%;height: 50px;">--%>
		<%--<button onclick="closelayer()" class="btn btn-white btn-sm pull-right m-r m-t-sm">&nbsp;关闭&nbsp;</button>--%>
		<%--<button onclick="doSubmit(2)" class="btn btn-white btn-sm pull-right m-r m-t-sm">&nbsp;暂存&nbsp;</button>--%>
		<%--<button onclick="doSubmit(1)" class="btn btn-info btn-sm pull-right m-r m-t-sm">&nbsp;提交&nbsp;</button>--%>
	<%--</div>--%>
</body>
</html>