<%@ 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(){
            $("#attachment_btn").click(function () {
                $("#attachment_file").click();
            });
            var oneSize = $(".oneTab").size();
            for(var i = 0;i < oneSize;i++){
                var hei = $(".oneTab:eq("+i+")").parent().height();
                $(".oneTab:eq("+i+")").css("height",hei)
                    .css("vertical-align","middle")
                    .css("line-height",hei+"px")
            }
            $("img").not(".upload_ico").each(function () {
                var num = 1 ;
                $(this).click(function () {
                    var flag = num%2;
                    if(flag == 1){
                        $(this).css("width","90%");
                        $(this).css("height","90%");
                        num++;
                    }else if(flag ==0){
                        $(this).css("width","50px");
                        $(this).css("height","50px");
                        num++;
                    }
                })
            });
        })
		var validateForm;
		function doSubmit(){//回调函数，在编辑和保存动作时，供openDialog调用提交表单。
		  if(validateForm.form()){
			  $("#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);
					}
				}
			});
			
					laydate.render({
			            elem: '#startDate', //目标元素。由于laydate.js封装了一个轻量级的选择器引擎，因此elem还允许你传入class、tag但必须按照这种方式 '#id .class'
			            event: 'focus' //响应事件。如果没有传入event，则按照默认的click
			        });
					laydate.render({
			            elem: '#endDate', //目标元素。由于laydate.js封装了一个轻量级的选择器引擎，因此elem还允许你传入class、tag但必须按照这种方式 '#id .class'
			            event: 'focus' //响应事件。如果没有传入event，则按照默认的click
			        });
		});

        function insertTitle(tValue){
            var list = "${caseInfo.workAttachments}";
            var size = (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,size);
        }}

       /* function openBill(title,url,width,height,target,formId,eleId){
            var frameIndex = parent.layer.getFrameIndex(window.name);
            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+"?index="+frameIndex ,
                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;

                    if(formId){
                        formSubmit($document,formId,eleId,index);
                    }else{
                        getSelectedItem($document,eleId,index)
                    }
                },
                cancel: function(index){
                }
            });
        }*/
        /*-------------------分割线-------------------*/
        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");
                    }
                }
            });
        }
        /*function delRow(obj, prefix){
            var id = $(prefix+"_id");
            var delFlag = $(prefix+"_delFlag");
            if (id.val() == ""){
                $(obj).parent().parent().remove();
            }else if(delFlag.val() == "0"){
                delFlag.val("1");
                $(obj).html("&divide;").attr("title", "撤回删除");
                $(obj).parent().parent().addClass("error");
                $(obj).parent().parent().addClass("hide");
            }else if(delFlag.val() == "1"){
                delFlag.val("0");
                $(obj).html("&times;").attr("title", "删除");
                $(obj).parent().parent().removeClass("error");
            }
            var idx1 = $("#caseBuildInfoList tr").length; //tr 总数
            for(var i = 0;i < idx1;i++){
                $("#caseBuildInfoList tr").eq(i).find("td").eq(1).html(i + 1);
            }
            var idx2 = $("#caseDesignInfoList tr").length; //tr 总数
            for(var i = 0;i < idx2;i++){
                $("#caseDesignInfoList tr").eq(i).find("td").eq(1).html(i + 1);
            }
            var idx3 = $("#caseExecuteInfoList tr").length; //tr 总数
            for(var i = 0;i < idx3;i++){
                $("#caseExecuteInfoList tr").eq(i).find("td").eq(1).html(i + 1);
            }
            var idx4 = $("#caseProjectFeatureList tr").length; //tr 总数
            for(var i = 0;i < idx4;i++){
                $("#caseProjectFeatureList tr").eq(i).find("td").eq(1).html(i + 1);
            }
            var idx5 = $("#caseNormList tr").length; //tr 总数
            for(var i = 0;i < idx5;i++){
                $("#caseNormList tr").eq(i).find("td").eq(1).html(i + 1);
            }
            var idx6 = $("#caseMaterialsList tr").length; //tr 总数
            for(var i = 0;i < idx6;i++){
                $("#caseMaterialsList tr").eq(i).find("td").eq(1).html(i + 1);
            }
        }*/
	</script>
</head>
<body>
<div class="single-form">
	<div class="container view-form">
		<form:form id="inputForm" modelAttribute="caseInfo" action="${ctx}/caseinfo/caseInfo/save" method="post" class="form-horizontal">
		<form:hidden path="id"/>

			<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" readonly="true" 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" readonly="true" 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"    readonly="true" class="form-control ">${caseInfo.record}</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" 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 page-end"></div>
		</form:form>
	</div>
</div>
</body>
</html>