<%@ 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}/js/plugin/layui/css/layui.css" media="all">
	<link rel="stylesheet" href="${ctx}/css/plugin/amazeui/amazeui.css" media="all">
	<link rel="stylesheet" href="${ctx}/css/basic.css">
	<style type="text/css">
		html { overflow: hidden; } 
	</style>
</head>
<body class="bg-white">
	<form class="form-inline ml12" enctype="multipart/form-data" id="uploadForm">
		<label class="form-group" for="inputfile">文件输入:</label>
		<div class="form-group" style="margin-left: 10%;padding-top: 10px;padding-bottom: 10px;">
        	<input type="file" name="file" id="inputfile" accept="application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet">
        </div>
        <button type="button" id="importdev" class="btn  themeBGColor  mr15" style="margin-left: 10%;">
			<i class="glyphicon glyphicon-import"></i>导入
		</button>
	</form>
		
<script src="${ctx}/js/plugin/jquery.min.js"></script>
<script src="${ctx}/js/plugin/bootstrap/bootstrap-datetimepicker.min.js"></script>
<script src="${ctx}/js/plugin/bootstrap/bootstrap-datetimepicker.zh-CN.js"></script>
<script src="${ctx}/js/plugin/layui/layer.js"></script>
<script src="${ctx}/jspJS/utils/loading.js"></script>
<script src="${ctx}/js/basic.js"></script>
<script src="${ctx}/jspJS/utils/judgeAjaxStatus.js"></script>
<script type="text/javascript">
$("#importdev").click(function(){
	var i;
	var tips;
	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("请选择Excel文件，再上传！",{icon:5,time:2000},function(){
				layer.closeAll()});
		}else if(uploadEventFile.lastIndexOf(".xls")<0 && uploadEventFile.lastIndexOf(".xlsx")<0){//可判断以.xls和.xlsx结尾的excel
			layer.msg("只能上传Excel文件",{icon:5,time:2000},function(){
				layer.closeAll()});
		}else{
			layer.confirm('确定导入？', function(index){
				var formData = new FormData($('#uploadForm')[0]);
				$.ajax({
					method : "post",
					url : "/pqs9900/device/importDev",
					data :formData,
					async:false,
					beforeSend: function () {
						i = ityzl_SHOW_LOAD_LAYER();
					},
					success : function(data) {
						if(data.code == 200){
							tips = data.body;
							layer.msg("上传成功",{icon:1,time:2000},function(){
								parent.layer.closeAll();
							});
							//***********关闭loading
							ityzl_CLOSE_LOAD_LAYER(i);
						} else{
							tips = "上传失败!";
							layer.msg(data.message,{icon:5,time:2000},function(){
								parent.layer.closeAll()
							});
							//***********关闭loading
							ityzl_CLOSE_LOAD_LAYER(i);
						}
						parent.document.getElementById("tips").value=tips;
					},
					cache: false,
					contentType: false,
					processData: false
				});
			})
		}
	} else {
		layer.msg("上传失败,文件大小不超过3M!",{icon:5,time:2000},function(){
			layer.closeAll()});
	}
})
</script>
</body>
</html>