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

		});

	</script>
	<script type="text/javascript">
		$(function () {
            $(".input-group ,  .evaluate_upload ").hide();

            $("#masterAdd").bind("click",function () {
                $("#selectMasterName").click();
            })

			$("#memberAdd").bind("click",function () {
				$("#selectMemberName").click();
            })

			$("#attachment_btn").click(function () {
				$("#attachment_file").click();
            })


        })
        function insertTitle(tValue){
            var list = "${workAttachmentList}";
            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 = "1";
            console.log(file);
            var timestamp=new Date().getTime();

            var storeAs = "attachment-file/workBidingDocument/"+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);}
           /* $("#attachment_title_div").remove();
            var t1 = tValue.lastIndexOf("\\");
            if(t1 >= 0 && t1 < tValue.length){
                $("#attachment_title").text(tValue.substring(t1+1));
                $("#attachment_title").after("<div id='attachment_title_div' style='float: right'>&nbsp;&nbsp;<span id='attachment_delete' onclick='attachment_del()'style='color: red ; cursor: pointer;'>x</span></div>");
            }*/
        }
        function attachment_del() {
			$("#attachment_file").val("");
			$("#attachment_title").text("");
			$("#attachment_delete").remove();
			$("#attachment_title_div").remove();
        }

        function evaluate_upload(id){
            $("#evaluate_file_"+id).click();
		}
		function insertTitle_evaluate(tId,tValue) {
            var loadingMessage = parent.layer.load(0, {shade: [0.1,'#393d49']});
			var t1= tValue.lastIndexOf("\\");
			if(t1 >= 0 && t1 < tValue.length){
			   $("#evaluate_title_"+tId).val(tValue.substring(t1+1));
                var formData = new FormData();
                var title = $("#evaluate_title_"+tId).val();
                formData.append("file",$("#evaluate_file_"+tId)[0].files[0]);
                formData.append("title",title);
                formData.append("userId",tId);
                $.ajax({
                    url:"${ctx}/workbidingdocument/workBidingDocument/evaluateUpload",
                    type:"POST",
                    data:formData,
                    processData:false,
                    contentType:false,
                    cache:false,
                    success:function (resultData,status) {
                        if(status == 'success'){
                            var newTitle = resultData["title"];
                            var newUrl = resultData["url"];
                            $("#evaluate_a_"+tId).attr("href",newUrl).text(newTitle);
                            parent.layer.msg("上传成功！！！",{icon:6});
                            parent.layer.close(loadingMessage);
                            window.location.reload();
                        }
                    },
					error:function () {
                        parent.layer.msg("上传失败！！！",{icon:6});
                        parent.layer.close(loadingMessage);
                    }
                });

            }
            <!--此上传操作是立即执行的，上传完成后需要清除选中的文件，否则在点击确定时会再次上传-->
			$("#evaluate_file_"+tId).val("");
        }
	</script>
</head>
<body class="hideScroll">
		<form:form id="inputForm" modelAttribute="workBidingDocument"  method="post" class="form-horizontal">
			<input type="hidden"  name="workBidProjectId" value="${workBidProject.id}" id="workBidProjectId"/>
			<input type="hidden"  name="id" value="${workBidingDocument.id}" id="id"/>
			<input type="hidden"    name="again" value="${again}">
		<sys:message content="${requestScope.message}"/>
		<table class="table table-bordered  table-condensed dataTables-example dataTable no-footer">
		   <tbody>
				<tr>
					<td class="width-15 active"><label class="pull-right">企业信息：</label></td>
					<td class="width-35">
						<textarea readonly="readonly" class="form-control">${officeintroduce}</textarea>
					</td>
				</tr>
				<tr>
					<td class="width-15 active"><label class="pull-right">项目组信息：</label></td>
					<td class="width-35">
						<div style="width: 580px; ">
							<div style="float:left;width: 80px; height: 100%; ">
								负责人
							</div>
							<div style="float:left; height: 100%; width: 500px; ">
								<div style="width: 500px; height: 100%; float: left">
									<a id="masterAdd" class="btn btn-info btn-xs" ><i class="fa fa-plus"></i> 新增负责人 </a>
								</div>
								<sys:masterselect id="selectMaster" name="projectMasterIds"
												value="${workBidProject.projectMasterIds}" labelName="projectMasterNames" labelValue="${workBidProject.projectMasterNames}"
												title="负责人" url="/sys/office/treeData?type=3" cssClass="form-control "
												notAllowSelectParent="true" checked="true"/>
								<br>
								<table id="listMasters"  style="text-align: center;width: 100%;margin-top:10px;"  class="table table-striped table-bordered table-condensed" >
									<tr>
										<td>序号</td><td>项目负责人</td><td>个人简介</td><td>评价汇总表</td><td>操作</td>
									</tr>
									<c:forEach items="${workBidProject.masterList}" var="master" varStatus="index">
										<tr>
											<td>${index.index + 1 }</td>
											<td>${master.name}</td>
											<td><span title="${master.remarks}">${fns:abbr(master.remarks, 30)}</span></td>
											<td>
												<%--<a href="${master.workattachment.url}" id="evaluate_a_${master.id}"><span title="${master.workattachment.attachmentName}">${fns:abbr(master.workattachment.attachmentName, 14)}</span></a>--%>
													<c:choose>
														<c:when test="${fn:containsIgnoreCase(master.workattachment.attachmentName,'jpg')
													  		 	or fn:containsIgnoreCase(master.workattachment.attachmentName,'png')
													   			or fn:containsIgnoreCase(master.workattachment.attachmentName,'gif')
													   			or fn:containsIgnoreCase(master.workattachment.attachmentName,'jpeg')}">
															<img src="${master.workattachment.url}" onclick="openDialogView(' ','${ctx}/sys/picturepreview/picturePreview?url=${master.workattachment.url}','860px','600px')" width="50" height="50" alt="${master.workattachment.attachmentName}"/>
														</c:when>
														<c:otherwise>
															<c:choose>
																<c:when test="${fn:containsIgnoreCase(master.workattachment.attachmentName,'pdf')}">
																	<a href="javascript:void(0)" onclick="preview('预览','${master.workattachment.url}','80%','80%','1')">
																		<span title="${master.workattachment.attachmentName}">${fns:abbr(master.workattachment.attachmentName, 30)}</span></a>
																</c:when>
																<c:otherwise>
																	<a href="javascript:void(0)" onclick="preview('预览','${master.workattachment.url}','80%','80%')">
																		<span title="${master.workattachment.attachmentName}">${fns:abbr(master.workattachment.attachmentName, 30)}</span>
																	</a>
																</c:otherwise>
															</c:choose>
														</c:otherwise>
													</c:choose>
												<div style="float: right">
													<a id="evaluate_btn_${master.id}" class="btn btn-info btn-xs" onclick="evaluate_upload('${master.id}');"><i class="fa fa-plus"></i> 上传</a>
													<input id="evaluate_file_${master.id}" name="evaluate_file_${master.id}" type="file" class="evaluate_upload" onChange="if(this.value)insertTitle_evaluate('${master.id}',this.value);">
													<span id="evaluate_title_${master.id}"></span>
												</div>
											</td>
											<td>
												<a href="${ctx}/workbidingdocument/workBidingDocument/updateMasterOfWorkBidProject?workBidProjectId=${workBidProject.id}&masterId=${master.id}" class="btn btn-danger btn-xs">删除负责人</a>
											</td>
										</tr>
									</c:forEach>
								</table>
							</div>
						</div>

						<div style="width: 580px;  ">
							<div style="float:left;width: 80px;height: 100%; ">
								负责组成员
							</div>
							<div style="float:left; height: 100%; width: 500px; ">
								<div style="width: 500px; height: 100%; float: left">
									<a id="memberAdd" class="btn btn-info btn-xs" ><i class="fa fa-plus"></i> 新增成员 </a>
								</div>
								<sys:masterselect id="selectMember" name="projectMemberIds"
												value="${workBidProject.projectMemberIds}" labelName="projectMasterNames" labelValue="${workBidProject.projectMemberNames}"
												title="负责组成员" url="/sys/office/treeData?type=3" cssClass="form-control "
												notAllowSelectParent="true" checked="true"/>
								<br>
								<table id="listMembers" style="text-align: center;width: 100%;margin-top:10px;" class="table table-striped table-bordered table-condensed" >
									<tr>
										<td>序号</td><td>项目组成员</td><td>个人简介</td><td>评价汇总表</td><td>操作</td>
									</tr>
									<c:forEach items="${workBidProject.memberList}" var="member" varStatus="index">
										<c:if test="${ not empty member }">
										<tr>
											<td>${index.index + 1}</td>
											<td>${member.name}</td>
											<td><span title="${member.remarks}">${fns:abbr(member.remarks, 30)}</span></td>
											<td>
												<%--<a href="${member.workattachment.url}" id="evaluate_a_${member.id}"><span title="${member.workattachment.attachmentName}">${fns:abbr(member.workattachment.attachmentName, 14)}</a>--%>
													<c:choose>
														<c:when test="${fn:containsIgnoreCase(member.workattachment.attachmentName,'jpg')
													  		 	or fn:containsIgnoreCase(member.workattachment.attachmentName,'png')
													   			or fn:containsIgnoreCase(member.workattachment.attachmentName,'gif')
													   			or fn:containsIgnoreCase(member.workattachment.attachmentName,'jpeg')}">
															<img src="${member.workattachment.url}" onclick="openDialogView(' ','${ctx}/sys/picturepreview/picturePreview?url=${member.workattachment.url}','860px','600px')"	 width="50" height="50" alt="${member.workattachment.attachmentName}"/>
														</c:when>
														<c:otherwise>
															<c:choose>
																<c:when test="${fn:containsIgnoreCase(member.workattachment.attachmentName,'pdf')}">
																	<a href="javascript:void(0)" onclick="preview('预览','${member.workattachment.url}','80%','80%','1')">
																	<span title="${member.workattachment.attachmentName}">${fns:abbr(member.workattachment.attachmentName, 30)}</span></a>
																</c:when>
																<c:otherwise>
																	<a href="javascript:void(0)" onclick="preview('预览','${member.workattachment.url}','80%','80%')">
																		<span title="${member.workattachment.attachmentName}">${fns:abbr(member.workattachment.attachmentName, 30)}</span>
																	</a>
																</c:otherwise>
															</c:choose>
														</c:otherwise>
													</c:choose>
												<div style="float: right">
													<a id="evaluate_btn_${member.id}" class="btn btn-info btn-xs" onclick="evaluate_upload('${member.id}')"><i class="fa fa-plus"></i> 上传</a>
													<input id="evaluate_file_${member.id}" name="evaluate_file_${member.id}" type="file" class="evaluate_upload" onChange="if(this.value)insertTitle_evaluate('${member.id}',this.value);" />
													<span id="evaluate_title_${member.id}"></span>
												</div>
											</td>
											<td>
												<a href="${ctx}/workbidingdocument/workBidingDocument/updateMemberOfWorkBidProject?workBidProjectId=${workBidProject.id}&memberId=${member.id}" class="btn btn-danger btn-xs">删除成员</a>
											</td>
										</tr>
										</c:if>
									</c:forEach>
								</table>
							</div>
						</div>
					</td>
				</tr>
				<tr>
					<td class="width-15 active"><label class="pull-right">方案编制：</label></td>
					<td class="width-35">
						<div style="width: 580px; ">
							<div style="float:left;width: 80px; height: 100%; ">
								附件
							</div>
							<div style="float:left; height: 100%; width: 500px; ">
								<div style="display: inline-block">
									<div id="addFile_attachment" style="display: none">
										<div>
											<span id="fileName_attachment" ></span>
											<b><span id="baifenbi_attachment" ></span></b>
										</div>
										<div>
											<div class="progress">
												<div id="jindutiao_attachment" class="progress-bar" style="width: 0%" aria-valuenow="0">
												</div>
											</div>
										</div>
									</div>
									<input id="attachment_file" type="file" name="attachment_file" multiple="multiple" style="display: none;" onChange="if(this.value)insertTitle(this.value);"/>
									<a id="attachment_btn" class="btn btn-info btn-xs" ><i class="fa fa-plus"></i> 添加附件</a>
									<span id="attachment_title"></span>
								</div>
								<table id="listAttachment"  style="text-align: center;width: 100%;margin-top:10px;"  class="table table-striped table-bordered table-condensed" >
									<thead>
									<tr>
										<%--<td>序号</td>--%><td>文件名</td><td>上传人</td><td>上传时间</td><td>操作</td>
									</tr>
									</thead>
									<tbody id="file_attachment">
									<c:forEach items="${workAttachmentList}" var="attachment" varStatus="index">
										<tr>
											<%--<td>${index.index + 1}</td>--%>
											<c:choose>
												<c:when test="${fn:containsIgnoreCase(attachment.attachmentName,'jpg')
													   or fn:containsIgnoreCase(attachment.attachmentName,'png')
													   or fn:containsIgnoreCase(attachment.attachmentName,'gif')
													   or fn:containsIgnoreCase(attachment.attachmentName,'jpeg')}">
													<td><img src="${attachment.url}" onclick="openDialogView(' ','${ctx}/sys/picturepreview/picturePreview?url=${attachment.url}','860px','600px')" width="50" height="50" alt="${attachment.attachmentName}"/></td>
												</c:when>
												<c:otherwise>
													<c:choose>
														<c:when test="${fn:containsIgnoreCase(attachment.attachmentName,'pdf')}">
															<td><a href="javascript:void(0)" onclick="preview('预览','${attachment.url}','80%','80%','1')">
															<span title="${attachment.attachmentName}">${fns:abbr(attachment.attachmentName, 30)}</span></a></td>
														</c:when>
														<c:otherwise>
															<td><a href="javascript:void(0)" onclick="preview('预览','${attachment.url}','80%','80%')">
																<span title="${attachment.attachmentName}">${fns:abbr(attachment.attachmentName, 30)}</span>
															</a></td>
														</c:otherwise>
													</c:choose>
												</c:otherwise>
											</c:choose>
											<td>${attachment.attachmentUser}</td>
											<td><fmt:formatDate value="${attachment.createDate}" pattern="yyyy-MM-dd"/></td>
											<td>
												<a href="javascript:location.href='${ctx}/workfullmanage/workFullManage/downLoadAttach?file='+encodeURIComponent('${attachment.url}');" class="btn btn-success btn-xs">下载</a>

												<%--<a href="${ctx}/workfullmanage/workFullManage/downLoadAttach?file=${attachment.url}" class="btn btn-success btn-xs">下载</a>--%>
												<a href="${ctx}/workbidingdocument/workBidingDocument/deleteFileFromAliyun?attachmentId=${attachment.id}&id=${workBidingDocument.id}" class="btn btn-danger btn-xs">删除</a>
											</td>
										</tr>
									</c:forEach>
									</tbody>
								</table>
							</div>
						</div>

					</td>
				</tr>
				<tr>
					<td class="width-15 active"><label class="pull-right">投标报价：</label></td>
					<td class="width-35">
						<div style="width: 580px;">
							<div style="width: 80px; height: 100%; float: left">
								报价(元)：
							</div>
							<div style="width: 500px; height: 100%; float: left">
								<form:input path="quote" htmlEscape="false"    class="form-control  number"/>
							</div>
						</div>
						<br/><br/>
						<div style="width: 580px;">
							<div style="width: 80px; height: 100%; float: left">
								备注：
							</div>
							<div style="width: 500px; height: 10%; float: left">
								<form:textarea path="remarks" htmlEscape="false"    class="form-control "/>
							</div>
						</div>

					</td>
				</tr>
		 	</tbody>
		</table>
	</form:form>
</body>
</html>