<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <script src="https://cdn.bootcss.com/jquery/1.10.2/jquery.min.js"></script>
    <title></title>
    <link rel="stylesheet" href="../layui-v2.6.8/layui/css/layui.css" media="all">
</head>
<style>

</style>

<body>
<ul class="layui-nav layui-bg-blue" lay-bar="disabled">
    <li class="layui-nav-item layui-this" ><a href="http://localhost:8090/indexPro" >报表导入</a></li>
    <li class="layui-nav-item"><a href=""></a></li>
<!--
    <li class="layui-nav-item"><a href="http://localhost:8090/indexFault" >故障日报导入</a></li>
-->

</ul>
<div class="layui-form-item" style="height: 30px"></div>
<form id="uploadForm" enctype="multipart/form-data" class="layui-form" >


    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">区域</label>
            <div class="layui-input-block">
                <select name="departId" lay-filter="aihao" id = "departId">
                    <option value="317sc">海子井光伏</option>
                </select>
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">文件选择</label>
            <div class="layui-input-inline">
                <input id="file" type="file" name="file"  required  lay-verify="required" autocomplete="off" class="layui-input">
            </div>
        </div>

    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button id="upload" type="button" class="layui-btn layui-btn-lg layui-btn-normal" lay-submit lay-filter="uploadForm">提交</button>
        </div>
    </div>

</form>
<br>

<script src="../laydate/laydate.js"></script> <!-- 改成你的路径 -->
<script src="../layui-v2.6.8/layui/layui.js"></script>
<script src="../md5.js"></script><!-- 改成你的路径 -->
<script type="text/javascript">

    layui.use('form', function(){
        var form = layui.form;

        //监听提交
        form.on('submit(uploadForm)', function(data){
            console.log(data)
            var departId=$("#departId").val();
            var files = document.getElementById("file").files;
            //创建FormData对象
            var formdata = new FormData();
            for(var i=0;i<files.length;i++){
                console.info(files[i].name);
                formdata.append("file", files[i]);
            }
            formdata.append("departId",departId);
            console.log(file)
            $.ajax({
                type: 'post',
                url: "http://localhost:8090/report/importPro",
                data: formdata,
                cache: false,
                processData: false,
                contentType: false,
                success:function(data){
                    layer.msg(data.msg,{icon: 5})
                    location.reload();
                },
                error:function (data){
                    layer.msg("程序error",{icon: 5})
                    location.reload();
                },
            })
        });
    });

</script>
</body>
<script src="../js/jquery-3.6.0.min.js"></script>
</html>
