

<%@ 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(){//回调函数，在编辑和保存动作时，供openDialog调用提交表单。
            if(validateForm.form()){
                //归档附件必传限制
                  if($("#file_attachment_review tr").length==0){
                      top.layer.alert('请上传归档附件！', {icon: 0});
                      return;
                  }
                $("#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);
                    }
                }
            });

            $("#attachment_btn").click(function () {
                $("#attachment_file").click();
            });
            $("#attachment_review_btn").click(function () {
                $("#attachment_review_file").click();
            });
            laydate.render({
                elem: '#signDate',
                event: 'focus',
                type : 'date'
            });
        });

        function insertTitle(tValue){
            var files = $("#attachment_file")[0].files;            for(var i = 0;i<files.length;i++) {                var file = files[i];
            var attachmentId = "";
            var attachmentFlag = "103";
            console.log(file);
            var timestamp=new Date().getTime();

            var storeAs = "attachment-file/workStockContract/"+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,0);}
        }
        function insertTitleReview(tValue){
            var files = $("#attachment_review_file")[0].files;            for(var i = 0;i<files.length;i++) {                var file = files[i];
            var attachmentId = "";
            var attachmentFlag = "104";
            console.log(file);
            var timestamp=new Date().getTime();

            var storeAs = "attachment-file/workStockContract/"+timestamp+"/"+file['name'];
            var uploadPath="http://gangwan-app.oss-cn-hangzhou.aliyuncs.com/"+storeAs;/*将这段字符串存到数据库即可*/
            var divId = "_attachment_review";
            $("#addFile"+divId).show();
            multipartUploadWithSts(storeAs, file,attachmentId,attachmentFlag,uploadPath,divId,0);}
        }
        //选择供应商为联系人赋值
        function setLinkName(obj){
            $.ajax({
                type:'post',
                url:'${ctx}/workstockcontract/workStockContract/getLinkName',
                data:{
                    "obj":obj
                },
                success:function(data){
                    var d = JSON.parse(data);
                    $("#linkName").val(d.linkName);
                }
            })
        }
	</script>
</head>
<div class="single-form">
	<div class="container">
		<form:form id="inputForm" modelAttribute="workStockContract" action="${ctx}/workstockcontract/workStockContract/complete" method="post" class="form-horizontal">
			<form:hidden path="id"/>
			<form:hidden path="completeStatus"/>
			<sys:message content="${message}"/>
			<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 htmlEscape="false" readonly="true" class="form-control required layui-input" value="${workStockContract.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">
						<div class="input-group">
							<input htmlEscape="false" readonly="true" class="form-control required layui-input" value="${workStockContract.number}"/>
							<span class="input-group-btn">
                            <label class="form-status"><c:choose><c:when test="${not empty workStockContract.status}">${fns:getDictLabel(workStockContract.status, 'audit_state', '')}</c:when><c:otherwise>新添</c:otherwise></c:choose></label>
                         </span>
						</div>
					</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 with-icon">
						<input htmlEscape="false" readonly="true" class="form-control required layui-input" value="${workStockContract.supplier.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 required layui-input" value="${workStockContract.linkName}"/>
					</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 required layui-input" value="<fmt:formatNumber value="${workStockContract.money}" pattern="#,#00.00"/>"/>
					</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 layui-input" readonly="true" id="signDate"
							   name="signDate" value="<fmt:formatDate value="${workStockContract.signDate}" pattern="yyyy-MM-dd"/>">
					</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 layui-input" readonly="true"
							   value="${fns:getDictLabel(workStockContract.completeStatus, 'complete_status', '')}"/>
					</div>
				</div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label ">所属部门：</label>
					<div class="layui-input-block">
						<input class="form-control layui-input" readonly="true"
							   value="${workStockContract.officeName}"/>
					</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"  class="form-control ">${workStockContract.remarks}</textarea>
					</div>
				</div>
			</div>

			<div class="form-group layui-row">
				<div class="form-group-label"><h2>合同附件信息</h2></div>
				<%--<div class="layui-item nav-btns">
					<a id="attachment_btn" class="nav-btn nav-btn-add" title="添加附件"><i class="fa fa-plus"></i>&nbsp;添加附件</a>
				</div>--%>
				<div id="addFile_attachment" style="display: none" class="upload-progress">
					<span id="fileName_attachment" ></span>
					<b><span id="baifenbi_attachment" ></span></b>
					<div class="progress">
						<div id="jindutiao_attachment" class="progress-bar" style="width: 0%" aria-valuenow="0">
						</div>
					</div>
				</div>
				<input id="attachment_file" type="file" name="attachment_file" multiple="multiple" style="display: none;" onChange="if(this.value)insertTitle(this.value);"/>
				<span id="attachment_title"></span>
				<div class="layui-item layui-col-xs12" style="padding:0 16px;">
					<table id="listAttachment" class="table table-bordered table-condensed details">
						<thead>
						<tr>
							<th>文件预览</th>
							<th>上传人</th>
							<th>上传时间</th>
							<th width="180px">操作</th>
						</tr>
						</thead>
						<tbody id="file_attachment">
						<c:forEach items="${workStockContract.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 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}" type="both"/></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"><i class="fa fa-download"></i>&nbsp;下载</a>
									</div>
								</td>
							</tr>
						</c:forEach>
						</tbody>
					</table>
				</div>
			</div>

			<div class="form-group layui-row">
				<div class="form-group-label"><h2>归档附件信息</h2></div>
				<div class="layui-item nav-btns">
					<a id="attachment_review_btn" class="nav-btn nav-btn-add" title="添加附件"><i class="fa fa-plus"></i>&nbsp;添加附件</a>
				</div>
				<div id="addFile_attachment_review" style="display: none" class="upload-progress">
					<span id="fileName_attachment_review" ></span>
					<b><span id="baifenbi_attachment_review" ></span></b>
					<div class="progress">
						<div id="jindutiao_attachment_review" class="progress-bar" style="width: 0%" aria-valuenow="0">
						</div>
					</div>
				</div>
				<input id="attachment_review_file" type="file" name="attachment_file" multiple="multiple" style="display: none;" onChange="if(this.value)insertTitleReview(this.value);"/>
				<span id="attachment_review_title"></span>
				<div class="layui-item layui-col-xs12" style="padding:0 16px;">
					<table id="listAttachmentReview" class="table table-bordered table-condensed details">
						<thead>
						<tr>
							<th>文件预览</th>
							<th>上传人</th>
							<th>上传时间</th>
							<th width="180px">操作</th>
						</tr>
						</thead>
						<tbody id="file_attachment_review">
						<c:forEach items="${workStockContract.workRecordAttachments}" 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 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}" type="both"/></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"><i class="fa fa-download"></i>&nbsp;下载</a>
										<a href="javascript:void(0)" onclick="deleteFileFromAliyun(this,'${ctx}/sys/workattachment/deleteFileFromAliyun?url=${workClientAttachment.url}&id=${workClientAttachment.id}&type=2','addFile_attachment','_attachment_review')" class="op-btn op-btn-delete" ><i class="fa fa-trash"></i>&nbsp;删除</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>