<%@ 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;
		  }
	
		  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);
					}
				}
			});
		});

        function insertTitle(tValue){
            var list = "${caseInfo.workAttachments}";
            var str = (list.split('url')).length-1;
            var files = $("#attachment_file")[0].files;
            for(var i = 0;i<files.length;i++) {
                var file = files[i];
            var attachmentId = $("#id").val();
            var attachmentFlag = "76";
            console.log(file);
            var timestamp=new Date().getTime();

            var storeAs = "attachment-file/caseInfo/"+timestamp+"/"+file['name'];
            var uploadPath="http://gangwan-app.oss-cn-hangzhou.aliyuncs.com/"+storeAs;/*将这段字符串存到数据库即可*/
            var divId = "_attachment";
            $("#addFile"+divId).show();
            multipartUploadWithSts(storeAs, file,attachmentId,attachmentFlag,uploadPath,divId,str);
        }}

        function deleteFileFromAliyun(obj,deleteUrl){
            $.ajax({
                type:"post",
                url:deleteUrl,
                success:function(data){
                    if(data.str){
                        parent.layer.msg('删除成功',{icon:1});
                        $(obj).parent().parent().remove();
                    }else {
                        parent.layer.msg('删除失败',{icon:1});
                    }
                }
            });
        }

        /*-------------------分割线-------------------*/
        function addRow(list, idx, tpl, row){
            var idx1 = $("#caseBuildInfoList tr").length;
            if(list == '#caseBuildInfoList' && idx1 < 100){
                bornTemplete(list, idx, tpl, row, idx1);
            }
            var idx2 = $("#caseDesignInfoList tr").length;
            if(list == '#caseDesignInfoList' && idx2 < 100){
                bornTemplete(list, idx, tpl, row, idx2);
            }
            var idx3 = $("#caseExecuteInfoList tr").length;
            if(list == '#caseExecuteInfoList' && idx3 < 100){
                bornTemplete(list, idx, tpl, row, idx3);
            }
            var idx4 = $("#caseProjectFeatureList tr").length;
            if(list == '#caseProjectFeatureList' && idx4 < 100){
                bornTemplete(list, idx, tpl, row, idx4);
            }
            var idx5 = $("#caseNormList tr").length;
            if(list == '#caseNormList' && idx5 < 100){
                bornTemplete(list, idx, tpl, row, idx5);
            }
            var idx6 = $("#caseMaterialsList tr").length;
            if(list == '#caseMaterialsList' && idx6 < 100){
                bornTemplete(list, idx, tpl, row, idx6);
            }
        }
        function bornTemplete(list, idx, tpl, row, idx1){
            $(list).append(Mustache.render(tpl, {
                idx: idx, delBtn: true, row: row,
                order:idx1 + 1
            }));
            $(list+idx).find("select").each(function(){
                $(this).val($(this).attr("data-value"));
            });
            $(list+idx).find("input[type='checkbox'], input[type='radio']").each(function(){
                var ss = $(this).attr("data-value").split(',');
                for (var i=0; i<ss.length; i++){
                    if($(this).val() == ss[i]){
                        $(this).attr("checked","checked");
                    }
                }
            });
        }
	</script>
</head>

<body >
<div class="single-form">
	<div class="container">
		<form:form id="inputForm" modelAttribute="caseInfo" action="${ctx}/caseinfo/caseInfo/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}"/>
			<c:set var="status" value="${caseInfo.act.status}" />

			<div class="form-group layui-row first lw7">
				<div class="form-group-label"><h2>基础信息</h2></div>
				<div class="layui-item layui-col-sm12">
					<label class="layui-form-label"><span class="require-item">*</span>案例类别：</label>
					<div class="layui-input-block">
						<input htmlEscape="false"  class="form-control layui-input required" readonly="true" value="${caseInfo.caseCategory.name}"/>
					</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"  class="form-control layui-input required" readonly="true" value="${caseInfo.name}"/>
					</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"  class="form-control layui-input required" readonly="true" value="<fmt:formatDate value="${caseInfo.startDate}" pattern="yyyy-MM-dd"/>"/>
					</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"  class="form-control layui-input required" readonly="true" value="${fns:getDictLabel(caseInfo.source,'case_source','')}"/>
					</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"  class="form-control layui-input required" readonly="true" value="${caseInfo.area.name}"/>
					</div>
				</div>
				<div class="layui-item layui-col-sm12">
					<label class="layui-form-label double-line">所属项目：</label>
					<div class="layui-input-block">
						<input htmlEscape="false"  class="form-control layui-input required" readonly="true" value="<c:choose><c:when test="${caseInfo.ext eq 0}">${caseInfo.project.projectName}</c:when><c:otherwise>${caseInfo.contractName}</c:otherwise></c:choose>"/>
					</div>
				</div>
				<div class="layui-item layui-col-sm12">
					<label class="layui-form-label">设计单位：</label>
					<div class="layui-input-block">
						<table id="bankinfo2" class="table table-bordered table-condensed details">
							<thead>
							<tr>
								<th width="40">序号</th>
								<th >单位名称</th>
								<th width="120"class="">联系人名称</th>
								<th width="170">联系方式</th>
								<th width="170">邮箱</th>
							</tr>
							</thead>
							<tbody id="caseDesignInfoList">
							<c:forEach items="${caseInfo.caseDesignInfoList}" var="buyDetails" varStatus="status">
								<tr>
									<td>${status.index + 1}</td>
									<td title="${buyDetails.name}">${buyDetails.name}</td>
									<td>${buyDetails.linkedman}</td>
									<td>${buyDetails.mobile}</td>
									<td>${buyDetails.email}</td>
								</tr>
							</c:forEach>
							<c:if test="${linkManSize == 0}">
								<tr>
									<td colspan="8">暂无数据</td>
								</tr>
							</c:if>
							</tbody>
						</table>
					</div>
				</div>
				<div class="layui-item layui-col-sm12">
					<label class="layui-form-label">建设单位：</label>
					<div class="layui-input-block">
						<table id="bankinfo" class="table table-bordered table-condensed details">
							<thead>
							<tr>
								<th width="40">序号</th>
								<th >单位名称</th>
								<th width="120"class="">联系人名称</th>
								<th width="170">联系方式</th>
								<th width="170">邮箱</th>
							</tr>
							</thead>
							<tbody id="caseBuildInfoList">
							<c:forEach items="${caseInfo.caseBuildInfoList}" var="buyDetails" varStatus="status">
								<tr>
									<td>${status.index + 1}</td>
									<td title="${buyDetails.name}">${buyDetails.name}</td>
									<td>${buyDetails.linkedman}</td>
									<td>${buyDetails.mobile}</td>
									<td>${buyDetails.email}</td>
								</tr>
							</c:forEach>
							<c:if test="${linkManSize == 0}">
								<tr>
									<td colspan="8">暂无数据</td>
								</tr>
							</c:if>
							</tbody>
						</table>
					</div>
				</div>
				<div class="layui-item layui-col-sm12">
					<label class="layui-form-label">施工单位：</label>
					<div class="layui-input-block">
						<table id="bankinfo3" class="table table-bordered table-condensed details">
							<thead>
							<tr>
								<th width="40">序号</th>
								<th >单位名称</th>
								<th width="120"class="">联系人名称</th>
								<th width="170">联系方式</th>
								<th width="170">邮箱</th>
							</tr>
							</thead>
							<tbody id="caseExecuteInfoList">
							<c:forEach items="${caseInfo.caseExecuteInfoList}" var="buyDetails" varStatus="status">
								<tr>
									<td>${status.index + 1}</td>
									<td title="${buyDetails.name}">${buyDetails.name}</td>
									<td>${buyDetails.linkedman}</td>
									<td>${buyDetails.mobile}</td>
									<td>${buyDetails.email}</td>
								</tr>
							</c:forEach>
							<c:if test="${linkManSize == 0}">
								<tr>
									<td colspan="8">暂无数据</td>
								</tr>
							</c:if>
							</tbody>
						</table>
					</div>
				</div>
				<div class="layui-item layui-col-sm6 with-textarea">
					<label class="layui-form-label"><span class="require-item">*</span>项目特征：</label>
					<div class="layui-input-block">
						<textarea readonly="true" htmlEscape="false" rows="4" maxlength="2000" class="form-control ">${caseInfo.peculiarity}</textarea>
					</div>
				</div>
				<div class="layui-item layui-col-sm6 with-textarea">
					<label class="layui-form-label">案例特性：</label>
					<div class="layui-input-block">
						<textarea readonly="true"  htmlEscape="false" rows="4"   maxlength="2000" class="form-control ">${caseInfo.feature}</textarea>
					</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"    class="form-control number layui-input" value="${caseInfo.price}"/>
					</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" class="form-control required layui-input" value="${caseInfo.unit}"/>
					</div>
				</div>

				<div class="layui-item layui-col-sm12">
					<label class="layui-form-label double-line">材料消耗量指标：</label>
					<div class="layui-input-block">
						<table id="bankinfo4" class="table table-bordered table-condensed details">
							<thead>
							<tr>
								<th width="40">序号</th>
								<th width="">名称</th>
								<th width="220">型号</th>
								<th width="110">单位消耗量</th>
								<th width="90">单位</th>
								<th width="100">合价</th>
								<th width="90">比重</th>
							</tr>
							</thead>
							<tbody id="caseMaterialsNormList">
							<c:forEach items="${caseInfo.caseMaterialsNormList}" var="buyDetails" varStatus="status">
								<tr>
									<td>${status.index + 1}</td>
									<td title="${buyDetails.name}">${buyDetails.name}</td>
									<td>${buyDetails.type}</td>
									<td>${buyDetails.unitContent}</td>
									<td>${buyDetails.unit}</td>
									<td>${buyDetails.allPrice}</td>
									<td>${buyDetails.proportion}</td>
								</tr>
							</c:forEach>
							<c:if test="${linkManSize == 0}">
								<tr>
									<td colspan="8">暂无数据</td>
								</tr>
							</c:if>
							</tbody>
						</table>
					</div>
				</div>
				<div class="layui-item layui-col-sm12">
					<label class="layui-form-label double-line">机械消耗量指标：</label>
					<div class="layui-input-block">
						<table id="bankinfo5" class="table table-bordered table-condensed details">
							<thead>
							<tr>
								<th width="40">序号</th>
								<th width="">名称</th>
								<th width="220">型号</th>
								<th width="110">单位消耗量</th>
								<th width="90">单位</th>
								<th width="100">合价</th>
								<th width="90">比重</th>
							</tr>
							</thead>
							<tbody id="caseMechanicalNormList">
							<c:forEach items="${caseInfo.caseMechanicalNormList}" var="buyDetails" varStatus="status">
								<tr>
									<td>${status.index + 1}</td>
									<td title="${buyDetails.name}">${buyDetails.name}</td>
									<td>${buyDetails.type}</td>
									<td>${buyDetails.unitContent}</td>
									<td>${buyDetails.unit}</td>
									<td>${buyDetails.allPrice}</td>
									<td>${buyDetails.proportion}</td>
								</tr>
							</c:forEach>
							<c:if test="${linkManSize == 0}">
								<tr>
									<td colspan="8">暂无数据</td>
								</tr>
							</c:if>
							</tbody>
						</table>
					</div>
				</div>
				<div class="layui-item layui-col-sm12">
					<label class="layui-form-label double-line">人工消耗量指标：</label>
					<div class="layui-input-block">
						<table id="bankinfo6" class="table table-bordered table-condensed details">
							<thead>
							<tr>
								<th width="40">序号</th>
								<th width="">名称</th>
								<th width="220">型号</th>
								<th width="110">单位消耗量</th>
								<th width="90">单位</th>
								<th width="100">合价</th>
								<th width="90">比重</th>
							</tr>
							</thead>
							<tbody id="casePeopleNormList">
							<c:forEach items="${caseInfo.casePeopleNormList}" var="buyDetails" varStatus="status">
								<tr>
									<td>${status.index + 1}</td>
									<td title="${buyDetails.name}">${buyDetails.name}</td>
									<td>${buyDetails.type}</td>
									<td>${buyDetails.unitContent}</td>
									<td>${buyDetails.unit}</td>
									<td>${buyDetails.allPrice}</td>
									<td>${buyDetails.proportion}</td>
								</tr>
							</c:forEach>
							<c:if test="${linkManSize == 0}">
								<tr>
									<td colspan="8">暂无数据</td>
								</tr>
							</c:if>
							</tbody>
						</table>
					</div>
				</div>

				<div class="layui-item layui-col-sm12">
					<label class="layui-form-label double-line">主要材料单价：</label>
					<div class="layui-input-block">
						<table id="contentTable" class="table table-bordered table-condensed details">
							<thead>
							<tr>
								<th>材料名称</th>
								<th width="100px">规格型号</th>
								<th width="60px">单位</th>
								<th width="90px">材料含税价</th>
								<th width="90px">材料除税价</th>
								<th width="90px">价格取用日期</th>
								<th width="80px">税率</th>
								<th width="80px">材质</th>
								<th>品牌</th>
							</tr>
							</thead>
							<tbody id="workAccountList">
							<c:forEach items="${caseInfo.caseMaterialsList}" var="caseMaterials" varStatus="status">
								<tr id="index${status.index}">
									<td class="hide">${caseMaterials.id}</td>
									<td>
										<a title="${caseMaterials.name}" href="javascript:void(0)" onclick="openDialogView('查看材料单信息', '${ctx}/casematerials/caseMaterials/form?id=${caseMaterials.id}&tabId=1','90%','90%')">
												${caseMaterials.name}
										</a>
									</td>
									<td title="${caseMaterials.specification}">${caseMaterials.specification}</td>
									<td title="${caseMaterials.calculateUnit}">${caseMaterials.calculateUnit}</td>
									<td title="${caseMaterials.taxPrice}">${caseMaterials.taxPrice}</td>
									<td title="${caseMaterials.price}">${caseMaterials.price}</td>
									<td ><fmt:formatDate value="${caseMaterials.useDate}" pattern="yyyy-MM-dd"/></td>
									<td class="hide">${fns:getDictLabel(caseMaterials.source, 'caseM_source', '')}</td>
									<td title="${caseMaterials.tax}">${caseMaterials.tax}</td>
									<td title="${caseMaterials.material}">${caseMaterials.material}</td>
									<td title="${caseMaterials.brand}">${caseMaterials.brand}</td>
									<td class="hide">${caseMaterials.pp}</td>
									<td class="hide">${caseMaterials.area.name}</td>
								</tr>
							</c:forEach>
							</tbody>
						</table>
					</div>
				</div>
				<div class="layui-item layui-col-sm12 with-textarea">
					<label class="layui-form-label double-line">偏差分析/记录/其他情况：</label>
					<div class="layui-input-block">
						<textarea  htmlEscape="false" rows="4"    class="form-control ">${caseInfo.record}</textarea>
					</div>
				</div>
				<div class="form-group layui-row">
					<div class="layui-item layui-col-sm12">
						<label class="layui-form-label">案例类型：</label>
						<div class="layui-input-block">
							<input type="radio" value="1" class="i-checks" id="shareStatus" name="shareStatus" onclick="display(this.value)">
							<label>一般案例</label>
							<input type="radio" value="2" class="i-checks" id="shareStatus2" name="shareStatus" onclick="display(this.value)" >
							<label>典型案例</label>
						</div>
					</div>
				</div>
			</div>


			<div class="form-group layui-row">
				<div class="form-group-label"><h2>附件信息</h2></div>
				<div class="layui-item layui-col-xs12" style="padding:0 16px;">
					<table id="upTable" class="table table-bordered table-condensed details">
						<thead>
						<tr>
								<%-- <th>序号</th>--%>
							<th>文件</th>
							<th>上传人</th>
							<th>上传时间</th>
							<th width="150px">操作</th>
						</tr>
						</thead>
						<tbody id="file_attachment">
						<c:forEach items="${caseInfo.workAttachments}" varStatus="status" var="workClientAttachment">
							<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 class="attention-info" href="javascript:void(0)" onclick="preview('预览','${workClientAttachment.url}','90%','90%','1')">${workClientAttachment.attachmentName}</a></td>
											</c:when>
											<c:otherwise>
												<td><a class="attention-info" href="javascript:void(0)" onclick="preview('预览','${workClientAttachment.url}','90%','90%')">${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" >
										<a href="javascript:location.href='${ctx}/workfullmanage/workFullManage/downLoadAttach?file='+encodeURIComponent(encodeURIComponent('${workClientAttachment.url}'));" class="op-btn op-btn-download">下载</a>

											<%--<a href="${ctx}/caseinfo/caseInfo/downLoadAttach?file=${workClientAttachment.url}" class="btn btn-success btn-xs">下载</a>--%>
											<%--<a href="${workClientAttachment.url}" class="btn btn-info btn-xs">下载</a>--%>
											<%--<a href="${ctx}/caseinfo/caseInfo/deleteFileFromAliyun?attachmentId=${workClientAttachment.id}&id=${caseInfo.id}">删除</a>--%>
									</div>
								</td>
							</tr>
						</c:forEach>
						</tbody>
					</table>
				</div>
			</div>
			<div class="form-group layui-row lw8">
				<div class="form-group-label"><h2>审批意见</h2></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" class="form-control" rows="4" maxlength="127" />
						<input type="file" name="upload_files" style="display: none;">
					</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="${caseInfo.act.procInsId}"/>
					<act:histoicFlow procInsId="${caseInfo.act.procInsId}"/>
				</div>
			</div>
			<div class="form-group layui-row page-end"></div>
		</form:form>
	</div>
</div>
</body>
</html>