<%@ 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");
              }
              if(  obj == 1 && ($("#code").val() == null || $("#code").val() == '')&& $('input[name="cancleReturn"]:checked').val() == '1'){
                  //console.log(obj+ "--"+$('input[name="cancleReturn"]:checked').val());
                  top.layer.alert('请填写发票代码！', {icon: 0});
                  return;
              }
              if(  obj == 1 && ($("#number").val() == null || $("#number").val() == '') && $('input[name="cancleReturn"]:checked').val() == '1'){
                  top.layer.alert('请填写发票号！', {icon: 0});
                  return;
              }
			  $("#inputForm").submit();
			  return true;
		  }
	
		  return false;
		}
		$(document).ready(function() {

            if("${workInvoiceReturn.cancleReturn}" == "2"){
                $("#cancleReturn1").iCheck('check')
            }else{
                $("#cancleReturn").iCheck('check')
            }
            if("${workInvoiceReturn.returnType}" == "2"){
                $("#returnType1").iCheck('check')
            }else{
                $("#returnType").iCheck('check')
            }

			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: '#returnDate', //目标元素。由于laydate.js封装了一个轻量级的选择器引擎，因此elem还允许你传入class、tag但必须按照这种方式 '#id .class'
                event: 'focus', //响应事件。如果没有传入event，则按照默认的click
                type : 'date'
            });
            $('input[name="cancleReturn"]').on('ifChecked', function(event){
                disUscc(event.target.defaultValue);
            });
            disUscc($('input[name="cancleReturn"]:checked').val());

            if($("#invoiceType").val()=="专票"){
                $("#code").attr("minlength","10");
                $("#code").attr("maxlength","10");
            }else if($("#invoiceType").val()=="普票"){
                $("#code").attr("minlength","12");
                $("#code").attr("maxlength","12");
            }
		});

        function setValue(obj){
            $.ajax({
                type:'post',
                url:'${ctx}/workinvoicedetail/workInvoiceDetail/getWorkInvoice',
                data:{
                    "obj":obj
                },
                success:function(data){
                    var d = JSON.parse(data);
                    $("#cInfoName").val(d.cInfoName);
                    $("#pNumber").val(d.pNumber);
                    $("#cName").val(d.cName);
                    $("#clientName").val(d.clientName);
                    $("#leaderName").val(d.leaderName);
                    $("#officeName").val(d.officeName);
                    $("#invoiceType").val(d.invoiceType);
                    $("#invoiceCName").val(d.invoiceCName);
                    $("#orUnicode").val(d.orUnicode);
                    $("#address").val(d.address);
                    $("#telephone").val(d.telephone);
                    $("#bank").val(d.bank);
                    $("#bankNumber").val(d.bankNumber);
                    $("#startDate").val(d.startDate);
                    $("#totalMoney").val(d.totalMoney);
                    $("#tax").val(d.tax);
                    $("#taxMoney").val(d.taxMoney);
                    $("#taxRate").val(d.taxRate);
                }
            })
        }
        function disUscc(hasUscc) {
            if("1"==hasUscc){
                $("#code").removeAttr("disabled");
                $("#number").removeAttr("disabled");
                if($("#invoiceType").val()=="专票"){
                    $("#code").attr("minlength","10");
                    $("#code").attr("maxlength","10");
                }else if($("#invoiceType").val()=="普票"){
                    $("#code").attr("minlength","12");
                    $("#code").attr("maxlength","12");
                }
            }else {
                $("#code").removeAttr("minlength");
                $("#code").removeAttr("maxlength");
                //去掉校验提示
                $("#code").removeClass("error");
                $("#code-error").hide();
                $("#number").removeClass("error");
                $("#number-error").hide();
                $("#code").val("");
                $("#number").val("");
                $("#code").attr("disabled","true");
                $("#number").attr("disabled","true");

            }
        }
        function checkSame(obj){
            if(!/^\d+(\.\d{1,2})?$/.test( obj)){
                $("#number").val("");
                parent.layer.msg("请输入数字",{icon:5});
                return;
            }
            var oldValue = $("oldNumber").val();
            $.ajax({
                type:'post',
                url:'${ctx}/workinvoicedetail/workInvoiceDetail/checkSame',
                data:{
                    "number":obj,"oldNumber":oldValue
                },
                success:function(data){
                    //console.log("========data"+data);
                    if("false" == data){
                        $("#number").val("");
                        parent.layer.msg("重复的发票号，请重新输入",{icon:5});
                        return;
                    }
                }
            })
        }
        function check(obj){
            if(!/^\d+(\.\d{1,2})?$/.test( obj)){
                $("#code").val("");
                parent.layer.msg("请输入数字",{icon:5});
                return;
            }
        }
	</script>
</head>
<body >
<div class="single-form">
	<div class="container">
		<form:form id="inputForm" modelAttribute="workInvoiceReturn" action="${ctx}/workinvoicereturn/workInvoiceReturn/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 lw12">
				<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">
						<input htmlEscape="false" readonly="true"   class="form-control layui-input" value="${workInvoiceReturn.invoiceDetail.number}"/>
					</div>
				</div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label">退票申请编号：</label>
					<div class="layui-input-block">
						<div class="input-group">
							<input htmlEscape="false" readonly="true"   class="form-control layui-input" value="${workInvoiceReturn.returnNumber}"/>
							<span class="input-group-btn">
							<label class="form-status"><c:choose><c:when test="${ empty workInvoiceReturn.status}">新添</c:when><c:otherwise>${fns:getDictLabel(workInvoiceReturn.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">
						<input htmlEscape="false"  readonly="true" class="form-control layui-input" value="${workInvoiceReturn.invoiceDetail.workInvoice.project.projectName}"/>
					</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="${workInvoiceReturn.invoiceDetail.workInvoice.project.projectId}"/>
					</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="${workInvoiceReturn.invoiceDetail.workInvoice.project.workContractInfo.name}"/>
					</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="${workInvoiceReturn.invoiceDetail.workInvoice.office.name}"/>
					</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="${workInvoiceReturn.invoiceDetail.workInvoice.project.workContractInfo.client.name}"/>
					</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="${workInvoiceReturn.invoiceDetail.workInvoice.project.leaderNameStr}"/>
					</div>
				</div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label">发票类型：</label>
						<div class="layui-input-block">
							<input id="invoiceType" htmlEscape="false"  readonly="true" class="form-control layui-input" value="<c:choose><c:when test="${workInvoiceReturn.invoiceDetail.workInvoice.invoiceType eq '1'}">专票</c:when><c:when test="${workInvoiceReturn.invoiceDetail.workInvoice.invoiceType eq '2'}">普票</c:when></c:choose>"/>
						</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="${workInvoiceReturn.invoiceDetail.workInvoice.client.name}"/>
					</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="${workInvoiceReturn.invoiceDetail.workInvoice.orUnicode}"/>
					</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="${workInvoiceReturn.invoiceDetail.workInvoice.address}"/>
					</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="${workInvoiceReturn.invoiceDetail.workInvoice.telephone}"/>
					</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="${workInvoiceReturn.invoiceDetail.workInvoice.bank}"/>
					</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="${workInvoiceReturn.invoiceDetail.workInvoice.bankNumber}"/>
					</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:formatDate value="${workInvoiceReturn.invoiceDetail.workInvoice.invoiceDate}" pattern="yyyy年MM月dd日"/>"/>
					</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="${workInvoiceReturn.invoiceDetail.totalMoney}"/>
					</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="${workInvoiceReturn.invoiceDetail.tax}"/>
					</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="${workInvoiceReturn.invoiceDetail.taxMoney}"/>
					</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="${workInvoiceReturn.invoiceDetail.taxRate}"/>
					</div>
				</div>
				<div class="layui-item layui-col-sm12 with-textarea">
					<label class="layui-form-label"><span class="require-item">*</span>退票原因：</label>
					<div class="layui-input-block">
						<textarea htmlEscape="false" rows="4" readonly="true"    class="form-control required">${workInvoiceReturn.reason}</textarea>
					</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="act.comment" htmlEscape="false" rows="5"   maxlength="20" class="form-control"/>
					</div>
				</div>
			</div>

			<div class="form-group layui-row first lw16">
				<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">
						<input type="radio" class="i-checks" name="cancleReturn" checked id="cancleReturn" value="1">
						<label for="cancleReturn">退票</label>
						<input type="radio" class="i-checks" name="cancleReturn" id="cancleReturn1" value="2">
						<label for="cancleReturn1">作废</label>
					</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="returnType" checked id="returnType" value="1">
						<label for="returnType">是</label>
						<input type="radio" class="i-checks" name="returnType" id="returnType1" value="2">
						<label for="returnType1">否</label>
					</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 id ="code" path="code" htmlEscape="false" onchange="check(this.value)" 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 id ="number" path="number" htmlEscape="false" class="form-control required layui-input"/>--%>

						<input id="number" name="number" onchange="checkSame(this.value)" type="text" htmlEscape="false" minlength="8" maxlength="8" value="${workInvoiceReturn.number}" class="form-control number layui-input"/>
						<input type="hidden" id="oldNumber" value="${workInvoiceReturn.number}"/>
					</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 id ="uname" path="uname" htmlEscape="false"  readonly="true" class="form-control required 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 class="form-control layer-date reuired laydate-icon layui-input laydate-icondate required" id="returnDate" name="returnDate" value="<fmt:formatDate
							value="${workInvoiceReturn.returnDate}" pattern="yyyy-MM-dd"/>">
					</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" >
                    <act:flowChart procInsId="${workInvoiceReturn.act.procInsId}"/>
                    <act:histoicFlow procInsId="${workInvoiceReturn.act.procInsId}" />
                </div>
            </div>

			<div class="form-group layui-row page-end"></div>
		</form:form>
	</div>
</div>
</body>
</html>