<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>上传模板</title>
	<link rel="stylesheet" href="${ctx}/css/plugin/bootstrap/bootstrap.css">
	<link rel="stylesheet" href="${ctx}/js/plugin/layui/css/layui.css" media="all">
	<link rel="stylesheet" href="${ctx}/css/basic.css">
	<style type="text/css">
		html { overflow: hidden; } 
	</style>
</head>
<body class="bg-white">
	<div class="layui-left layui-tab self-style pd10">
	<table class="table" id="device">
			<tr>
				<td align="right" class="width1"></td>
				<td align="left" class="width2"><form class="form-inline ml12"
						enctype="multipart/form-data" id="uploadForm">
						<input type="file" name="file" id="inputfile">
					</form></td>
			</tr>
			<tr>
				<td></td>
				<td align="left" class="width2"><button type="button"
						id="import" class="btn btn-primary" style="margin-left:85px;font-size: 15px;">提交</button></td>
				<td></td>
			</tr>
	</table>
	</div>	
<input type="hidden" value="${sessionScope.reportIndex}" id="reportIndex"
       name="reportIndex">
<input type="hidden" value="${sessionScope.reportName}" id="reportName"
       name="reportName">
<script src="${ctx}/js/plugin/jquery/jquery.min.js"></script>
	<script src="${ctx}/js/plugin/jquery-ui/jquery-ui.js"></script>
	<script src="${ctx}/js/color.js"></script>
	<script src="${ctx}/js/plugin/layui/layer.js"></script>
	<script src="${ctx}/js/plugin/layui/layui.js"></script>
	<script src="${ctx}/js/plugin/jquery/jquery.contextMenu.js"></script>
	<script src="${ctx}/js/plugin/jquery/jquery.cleverTabs.js"></script>
	<script src="${ctx}/js/plugin/bootstrap/bootstrap-datetimepicker.js"></script>
	<script
		src="${ctx}/js/plugin/bootstrap/bootstrap-datetimepicker.zh-CN.js"></script>
	<script src="${ctx}/js/basic.js"></script>
	<script src="${ctx}/js/plugin/xss/xss.js"></script>
	<script src="${ctx}/jspJS/utils/judgeAjaxStatus.js"></script>
	<script src="${ctx}/jspJS/utils/loading.js"></script>
<script type="text/javascript">
var reportIndex = $("#reportIndex").val();
var reportName = $("#reportName").val();
reportIndex=filterXSS(reportIndex);
reportName=filterXSS(reportName);

$("#import").click(function(){
	var i;
	var uploadEventFile=$("#inputfile").val();

	/**
	 * xuyang
	 * 前端对所选文件的大小做个简单判断
	 */
	var uploadFile = document.getElementById("inputfile").files;
	//文件大小
	var size = uploadFile[0].size;
	if (Math.floor(size/1024) <= 3072){
		if(uploadEventFile == ''){
			layer.msg("请选择Doc文件，再上传！",{icon:5,time:2000},function(){
				layer.closeAll()});
		}else if(uploadEventFile.lastIndexOf(".doc")<0){//可判断以.xls和.xlsx结尾的excel
			layer.msg("只能上传Doc文件",{icon:5,time:2000},function(){
				layer.closeAll()});
		}else{
			layer.confirm('确定上传？', function(index){
				var formData = new FormData($('#uploadForm')[0]);
				formData.append("reportIndex",reportIndex);
				formData.append("reportName",reportName);
				$.ajax({
					method : "post",
					url : "/pqs9000/devicereport/updatereport",
					data :formData,
					beforeSend: function () {
						i = ityzl_SHOW_LOAD_LAYER();
					},
					success : function(data) {
						if(data.code == 200){
							layer.msg("上传成功",{icon:1,time:2000},function(){
								parent.layer.closeAll()});
							//***********关闭loading
							ityzl_CLOSE_LOAD_LAYER(i);
						} else{
							// layer.msg("上传失败,请核对文档内容!",{icon:5,time:2000},function(){
							// 	parent.layer.closeAll()});
							// //***********关闭loading
							// ityzl_CLOSE_LOAD_LAYER(i);
							layer.msg(data.message,{icon:5,time:2000},function(){
									parent.layer.closeAll()});
								//***********关闭loading
								ityzl_CLOSE_LOAD_LAYER(i);
						}
					},
					cache: false,
					contentType: false,
					processData: false
				});
			})
		}
	} else {
		layer.msg("上传失败,文件大小不超过3M!",{icon:5,time:2000},function(){
			layer.closeAll()});
	}
})
</script>
</body>
</html>