<!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"><a href="http://localhost:8090/indexPro">报表导入</a></li>
    <li class="layui-nav-item"><a href=""></a></li>
<!--
    <li class="layui-nav-item layui-this"><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="interest" lay-filter="aihao" id = "departId">
                    <option value="185SC">山西</option>
                    <option value="131SC">太旗</option>
                </select>
            </div>
        </div>
        <!--<div class="layui-inline">
            <label class="layui-form-label">日期</label>
            <div class="layui-input-inline">
                <input type="text"  name="date" id="demoTest" required  lay-verify="required"  placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
            </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>

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

        //监听提交
        form.on('submit(uploadForm)', function(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);
            //var data = new FormData($('#uploadForm')[0]);
            console.log(file)
            $.ajax({
                type: 'post',
                url: "http://localhost:8090/report/importFault",
                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>
<!--<script type="text/javascript">

    $(function () {
        $("#upload").click(function () {
            var departId=$("#departId").val();
            var format=$("#demoTest").val();
            if (format.values == ''){
                alert("日期不能空")
            }
            console.log(departId)
            var files = document.getElementById("file").files;
            if (files.values == ''){
                alert("文件不能空")
            }
            //创建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);
            formdata.append("format",format);
            //var data = new FormData($('#uploadForm')[0]);
            console.log(file)
            $.ajax({
                type: 'post',
                url: "http://localhost:8090/report/import",
                data: formdata,
                cache: false,
                processData: false,
                contentType: false,
            }).success(function (data) {
                alert("上传成功");
            }).error(function () {
                alert("上传失败");
            });
        });
    });
</script>-->
</html>
