<%@ 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">
        function openDialogre(title,url,width,height,target,formId){
            if(navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)){//如果是移动端，就使用自适应大小弹窗
                width='auto';
                height='auto';
            }else{//如果是PC端，根据用户设置的width和height显示。

            }
            top.layer.open({
                type: 2,
                area: [width, height],
                title: title,
                maxmin: true, //开启最大化最小化按钮
                content: url ,
                btn: ['修改','关闭'],
                yes: function(index, layero){
                    var body = top.layer.getChildFrame('body', index);
                    var iframeWin = layero.find('iframe')[0]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                    var inputForm = body.find('#inputForm');
                    var top_iframe;
                    if(target){
                        top_iframe = target;//如果指定了iframe，则在改frame中跳转
                    }else{
                        top_iframe = top.getActiveTab().attr("name");//获取当前active的tab的iframe
                    }
                    inputForm.attr("target",top_iframe);//表单提交成功后，从服务器返回的url在当前tab中展示
                    var $document = iframeWin.contentWindow.document;
                    formSubmit($document,formId,index);
                },
                cancel: function(index){
                }
            });
        }
        function formSubmit($document,inputForm,index){
            var validateForm = $($document.getElementById(inputForm)).validate({
                submitHandler: function(form){
                    loading('正在提交，请稍等...');
                    form.submit();
                },
                errorContainer: "#messageBox",
                errorPlacement: function(error, element) {
                    $($document.getElementById("#messageBox")).text("输入有误，请先更正。");
                    if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
                        error.appendTo(element.parent().parent());
                    } else {
                        error.insertAfter(element);
                    }
                }
            });
            var data  = 'error'
            if(validateForm.form()){
                $($document.getElementById(inputForm)).ajaxSubmit({
                    success:function(data) {
                        var d = data;
                        console.log(d.status);
                        console.log(d.msg);
                        if(d.status){
                            parent.layer.msg(d.msg,{icon:1});
                            var contractPrice = formatNum(d.contractPrice);
                            $("#contractPrice").val(contractPrice);
                        }else {
                            parent.layer.msg(d.msg,{icon:2});
						}
                        top.layer.close(index);
                        //location.reload();
                    }
                });
            }
        }
        //将数字转换成金额显示
        function formatNum(str){
            var newStr = "";
            var count = 0;

            if(str.indexOf(".")==-1){
                for(var i=str.length-1;i>=0;i--){
                    if(count % 3 == 0 && count != 0){
                        newStr = str.charAt(i) + "," + newStr;
                    }else{
                        newStr = str.charAt(i) + newStr;
                    }
                    count++;
                }
                str = newStr + ".00"; //自动补小数点后两位
                console.log(str)
            }
            else
            {
                for(var i = str.indexOf(".")-1;i>=0;i--){
                    if(count % 3 == 0 && count != 0){
                        newStr = str.charAt(i) + "," + newStr; //碰到3的倍数则加上“,”号
                    }else{
                        newStr = str.charAt(i) + newStr; //逐个字符相接起来
                    }
                    count++;
                }
                str = newStr + (str + "00").substr((str + "00").indexOf("."),3);
                console.log(str)
            }
            return str;
        }

    </script>
</head>
<body>
<div class="single-form view-form">
	<div class="container">
	<form:form id="inputForm" modelAttribute="workContractInfo"  method="post" class="form-horizontal">
		<form:hidden path="id"/>

		<div class="tabs-container">
			<div class="layui-tab" id="tabDiv">
				<ul class="layui-tab-title" >
					<li class="active"><a data-toggle="tab" href="#tab-11"  aria-expanded="true">合同信息</a></li>

				</ul>
			</div>
			<%--<ul class="nav nav-tabs">--%>
				<%--<li class="active"><a data-toggle="tab" href="#tab-11"  aria-expanded="true">合同信息</a>--%>
				<%--</li>--%>
				<%--<li class=""><a data-toggle="tab" href="#tab-22"  aria-expanded="false">合同评审信息</a>--%>
				<%--</li>--%>
			<%--</ul>--%>
			<div class="tab-content">
				<div id="tab-11" class="tab-pane active">
					<div class="form-group layui-row first lw9">
						<div class="form-group-label"><h2>项目合同信息</h2></div>
						<c:if test="${workContractInfo.ext == 0}">
							<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="投标项目"/>
								</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="${workContractInfo.contractNum}"/>
										<span class="input-group-btn">
											<label class="form-status"><c:choose><c:when test="${ empty workContractInfo.contractState}">新添</c:when><c:otherwise>${fns:getDictLabel(workContractInfo.contractState, 'audit_completion_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="${workContractInfo.project.projectName}"/>
								</div>
							</div>
						</c:if>
						<c:if test="${workContractInfo.ext != 0}">
							<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="非投标项目"/>
								</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="${workContractInfo.contractNum}"/>
										<span class="input-group-btn">
											<label class="form-status"><c:choose><c:when test="${ empty workContractInfo.contractState}">新添</c:when><c:otherwise>${fns:getDictLabel(workContractInfo.contractState, 'audit_completion_state','')}</c:otherwise>	</c:choose></label>
										</span>
									</div>
								</div>
							</div>
						</c:if>

						<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="${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="${workContractInfo.totalContractName}"/>
							</div>
						</div>

						<div class="layui-item layui-col-sm6">
							<label class="layui-form-label lw9">所属部门：</label>
							<div class="layui-input-block">
								<input htmlEscape="false"  readonly="true" class="form-control layui-input" value="${workContractInfo.chargeCompanyName}"/>
							</div>
						</div>
						<div class="layui-item layui-col-sm6">
							<label class="layui-form-label double-line"><span class="require-item">*</span>合 同 金 额 (元)预计金额：</label>
							<div class="layui-input-block">
								<input htmlEscape="false" id="contractPrice" readonly="true" class="form-control layui-input" value="<fmt:formatNumber value="${workContractInfo.contractPrice}" pattern="#,#00.00"/>"/>
							</div>
							<shiro:hasPermission name="workcontractinfo:workContractInfo:contractPrice">
								<c:if test="${fns:getUser().office.id eq workContractInfo.officeId && workContractInfo.contractState < 10}">
									<a onclick="openDialogre('修改合同金额', '${ctx}/workcontractinfo/workContractInfo/formContractPrice?id=${workContractInfo.id}','50%','300px',false,'inputForm')", class="nav-btn nav-btn-add" style="margin-right: 0px;top:0px;right:16px;position: absolute;height:40px;line-height: 40px;"><i class="fa fa-edit"></i> 修改</a>
								</c:if>
							</shiro:hasPermission>
						</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="${fns:getMainDictLabel(workContractInfo.contractType, 'contract_type', '')}"/>
							</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="${workContractInfo.client.name}"/>
							</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:formatDate value="${workContractInfo.contractDate}" 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="<fmt:formatDate value="${workContractInfo.effectiveDate}" pattern="yyyy年MM月dd日" type="date" dateStyle="full"/>"/>
							</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="${workContractInfo.closingDate}" pattern="yyyy年MM月dd日" type="date" dateStyle="full"/>"/>
							</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="${workContractInfo.anotherContractNum}"/>
							</div>
						</div>
						<div class="layui-item layui-col-sm6">
							<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="${workContractInfo.investmentAmount}" pattern="#,#00.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="${fns:getDictLabel(workContractInfo.recordState, 'record_state','')}"/>
							</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="${fns:getMainDictLabel(workContractInfo.contractTypeDoc, 'contract_info_type', '')}"/>
							</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="${workContractInfo.createDate}" pattern="yyyy年MM月dd日" type="date" dateStyle="full"/>"/>
							</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" maxlength="1000" class="form-control" >${workContractInfo.summaryPayment}</textarea>
							</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" maxlength="1000" class="form-control" >${workContractInfo.contractSpecial}</textarea>
							</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" maxlength="1000" class="form-control" >${workContractInfo.contractTypeDoc}</textarea>
							</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" maxlength="1000" class="form-control" >${workContractInfo.remarks}</textarea>
							</div>
						</div>
						<c:if test="${not empty workContractInfo.alterInfo.reason}">
							<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" maxlength="1000" class="form-control" >${workContractInfo.alterInfo.reason}</textarea>
								</div>
							</div>
						</c:if>
						<c:if test="${not empty workContractInfo.contractCategory}">
							<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" maxlength="1000" class="form-control" >${workContractInfo.contractCategory}</textarea>
								</div>
							</div>
						</c:if>
					</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="contentTable4" class="table table-bordered table-condensed no-bottom-margin details">
								<thead>
								<tr>
									<%--<th width="10%">序号</th>--%>
									<th width="30%">委托方名称</th>
									<th width="20%">客户性质</th>
									<th width="20%">所属行业</th>
									<th width="30%">所属地区</th>
								</tr>
								</thead>
								<tbody id="workClientInfoList">
								<c:if test="${not empty workContractInfo.workClientInfoList}">
									<c:forEach items="${workContractInfo.workClientInfoList}" var="casePeopleNorm" varStatus="index">
										<tr id="workClientInfoList${index.index}">
											<td class="hide">
													<%--<input id="workClientInfoList${index.index}_id" name="workClientInfoList[${index.index}].id" type="hidden" value="${casePeopleNorm.id}"/>--%>
											</td>
											<%--<td>--%>
													<%--${index.index + 1}--%>
											<%--</td>--%>
												<%--${fns:getDictLabel(workAccount.financialSubjectss, 'not_project_reimbursement', '')}--%>
											<td>
													<%--<input id="workClientInfoList${index.index}_name" name="workClientInfoList[${index.index}].name" type="text" value="${casePeopleNorm.name}" readonly="true"   class="form-control "/>--%>
													${casePeopleNorm.name}
											</td>
											<td>
													<%--<form:select id="workClientInfoList${index.index}_companyType" path="workClientInfoList[${index.index}].companyType" disabled="true" readonly="true" class="form-control">
                                                        <form:option value="" label=""/>
                                                        <form:options items="${fns:getMainDictList('company_type')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
                                                    </form:select>--%>
													${fns:getMainDictLabel(casePeopleNorm.companyType, 'company_type', '')}
											</td>
											<td>
													<%--<form:select id="workClientInfoList${index.index}_companyIndustry" path="workClientInfoList[${index.index}].companyIndustry" disabled="true" readonly="true" class="form-control">
                                                        <form:option value="" label=""/>
                                                        <form:options items="${fns:getMainDictList('company_industry')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
                                                    </form:select>--%>
													${fns:getMainDictLabel(casePeopleNorm.companyIndustry, 'company_industry', '')}
											</td>
											<td>
													<%--<input id="workClientInfoList${index.index}_area" name="workClientInfoList[${index.index}].area.name" type="text" value="${casePeopleNorm.area.name}"  readonly="true"  class="form-control "/>--%>
													${casePeopleNorm.area.name}
											</td>
										</tr>
									</c:forEach>
								</c:if>
								</tbody>
							</table>
						</div>
					</div>
					<c:if test="${workContractInfo.contractState eq '5'}">
						<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="contentTable3" class="table table-bordered table-condensed details">
									<thead>
									<tr>
										<th><span class="require-item">*</span>发票代码</th>
										<th><span class="require-item">*</span>发票号</th>
										<th><span class="require-item">*</span>价税合计</th>
										<th><span class="require-item">*</span>税率</th>
										<th><span class="require-item">*</span>金额</th>
										<th><span class="require-item">*</span>税额</th>
										<th><span class="require-item">*</span>累计登记金额</th>
										<th><span class="require-item">*</span>发票状态</th><%--正常--%>
										<th><span class="require-item">*</span>被退标记</th>
										<th><span class="require-item">*</span>被退票号</th>
										<th><span class="require-item">*</span>开票日期</th>
									</tr>
									</thead>
									<tbody id="workAccountList">
									<c:if test="${not empty workContractInfo.invoiceDetails}">
										<c:forEach items="${workContractInfo.invoiceDetails}" var="workAccount" varStatus="index">
											<tr id="workAccountList${index.index}">
												<td title="${workAccount.code}">
														${workAccount.code}
												</td>
												<td title="${workAccount.number}">
														${workAccount.number}
												</td>

												<td title="<fmt:formatNumber value="${workAccount.totalMoney}" pattern="#,#00.00"/>">
													<fmt:formatNumber value="${workAccount.totalMoney}" pattern="#,#00.00"/>
												</td>
												<td title="${workAccount.tax}">
														${workAccount.tax}
												</td>
												<td title="<fmt:formatNumber value="${workAccount.taxMoney}" pattern="#,#00.00"/>">
													<fmt:formatNumber value="${workAccount.taxMoney}" pattern="#,#00.00"/>
												</td>
												<td title="<fmt:formatNumber value="${workAccount.taxRate}" pattern="#,#00.00"/>">
													<fmt:formatNumber value="${workAccount.taxRate}" pattern="#,#00.00"/>
												</td>
												<td title="<fmt:formatNumber value="${workAccount.incomeMoney}" pattern="#,#00.00"/>">
													<fmt:formatNumber value="${workAccount.incomeMoney}" pattern="#,#00.00"/>
												</td>
												<td title="${workAccount.state}">
														${workAccount.state}
												</td>
												<td title="${workAccount.backSign}">
														${workAccount.backSign}
												</td>
												<td title="${workAccount.backNumber}">
														${workAccount.backNumber}
												</td>
												<td title="<fmt:formatDate value="${workInvoice.invoiceDate}" pattern="yyyy-MM-dd"/>">
													<fmt:formatDate value="${workInvoice.invoiceDate}" pattern="yyyy-MM-dd"/>
												</td>
											</tr>
										</c:forEach>
									</c:if>
									</tbody>
								</table>
							</div>
						</div>
					</c:if>
					<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 no-bottom-margin details">
								<thead>
								<tr>

									<th>文件</th>
									<th>上传人</th>
									<th>上传时间</th>
									<th width="180px">操作</th>
								</tr>
								</thead>
								<tbody>
								<c:choose>
									<c:when test="${not empty workContractInfo.workAttachments}">
									<c:forEach items="${workContractInfo.workAttachments}" var="workClientAttachment" varStatus="status">
									<tr>
											<%--<td>${status.index + 1}</td>--%>
										<c:choose>
											<c:when test="${fn:containsIgnoreCase(workClientAttachment.attachmentName,'jpg')
																   or fn:containsIgnoreCase(workClientAttachment.attachmentName,'png')
																   or fn:containsIgnoreCase(workClientAttachment.attachmentName,'gif')
																   or fn:containsIgnoreCase(workClientAttachment.attachmentName,'bmp')
																   or fn:containsIgnoreCase(workClientAttachment.attachmentName,'jpeg')}">
												<td><img src="${workClientAttachment.url}" width="50" height="50" onclick="openDialogView('预览','${ctx}/sys/picturepreview/picturePreview?url=${workClientAttachment.url}','90%','90%')" alt="${workClientAttachment.attachmentName}">
											</c:when>
											<c:otherwise>
												<c:choose>
													<c:when test="${fn:containsIgnoreCase(workClientAttachment.attachmentName,'pdf')}">
														<td><a href="javascript:void(0)" onclick="preview('预览','${workClientAttachment.url}','95%','95%','1')">${workClientAttachment.attachmentName}</a></td>
													</c:when>
													<c:otherwise>
														<td><a href="javascript:void(0)" onclick="preview('预览','${workClientAttachment.url}','95%','95%')">${workClientAttachment.attachmentName}</a></td>
													</c:otherwise>
												</c:choose>
											</c:otherwise>
										</c:choose>
										<td>${workClientAttachment.createBy.name}</td>
										<td><fmt:formatDate value="${workClientAttachment.createDate}" pattern="yyyy-MM-dd"/></td>
										<td  class="op-td">
											<div class="op-btn-box" >
                                                <c:set var="signflag" value="${fns:getSysParam('sign_flag',fns:getUser())}"/>
                                                <c:choose>
                                                    <c:when test="${fn:containsIgnoreCase(workClientAttachment.attachmentName,'pdf')
                                                           or fn:containsIgnoreCase(workClientAttachment.attachmentName,'doc')
                                                           or fn:containsIgnoreCase(workClientAttachment.attachmentName,'docx')
                                                           or fn:containsIgnoreCase(workClientAttachment.attachmentName,'xls')
                                                           or fn:containsIgnoreCase(workClientAttachment.attachmentName,'xlsx')
                                                           or fn:containsIgnoreCase(workClientAttachment.attachmentName,'ppt')
                                                           or fn:containsIgnoreCase(workClientAttachment.attachmentName,'pptx')}">
                                                        <a href="javascript:void(0);" onclick="openDialogView('查看电子签章信息', '${ctx}/isignature/iSignatureDocument/form?recordId=${workClientAttachment.id}','95%', '95%')" class="op-btn op-btn-view" ><i class="fa fa-search-plus"></i> 查看</a>
                                                        <c:choose>
                                                            <c:when test="${signflag == '是'}">
                                                                <a href="javascript:location.href='${ctx}/isignature/iSignatureDocument/download?recordId=${workClientAttachment.id}'" class="op-btn op-btn-download"><i class="fa fa-download"></i>&nbsp;下载</a>
                                                            </c:when>
                                                            <c:otherwise>
                                                                <a href="javascript:location.href='${ctx}/workcontractinfo/workContractInfo/downLoadAttach?file='+encodeURIComponent('${workClientAttachment.url}');" class="op-btn op-btn-download"><i class="fa fa-download"></i>&nbsp;下载</a>
                                                            </c:otherwise>
                                                        </c:choose>
                                                    </c:when>
                                                    <c:otherwise>
                                                        <a href="javascript:location.href='${ctx}/workcontractinfo/workContractInfo/downLoadAttach?file='+encodeURIComponent('${workClientAttachment.url}');" class="op-btn op-btn-download"><i class="fa fa-download"></i>&nbsp;下载</a>
                                                    </c:otherwise>
                                                </c:choose>
											</div>
										</td>
									</tr>
									</c:forEach>
									</c:when>
									<c:otherwise>
									<tr>
										<td colspan="4" align="center">暂无数据</td>
									</tr>
									</c:otherwise>
								</c:choose>
								</tbody>
							</table>
						</div>
					</div>
				</div>

		</div>
		</div>

	</form:form>
	</div>
</div>
</body>
</html>