<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:set var="path" value="${pageContext.request.contextPath}"/>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<style>
    .loading {
        width: 160px;
        height: 56px;
        position: absolute;
        top: 50%;
        left: 50%;
        line-height: 56px;
        color: #fff;
        padding-left: 60px;
        font-size: 15px;
        background: #000;
        opacity: 0.7;
        z-index: 9999;
        -moz-border-radius: 20px;
        -webkit-border-radius: 20px;
        border-radius: 20px;
        filter: progid:DXImageTransform.Microsoft.Alpha(opacity=70);
    }
</style>
<!--导入加载-->
<div id="loadingModel" class="modal fade" data-keyboard="false"
     data-backdrop="static" data-role="dialog"
     aria-labelledby="myModalLabel" aria-hidden="true">
    <div id="loading" class="loading">加载中。。。</div>
</div>
<script>
    //导入按钮
    function uploadBtn() {
        $("#myModalLabel3").text('上传');
        $('#myModal3').modal('show')
    }

    //导入excel
    //url:导入请求的相对路径，exportFileName：导出出错数据的关键字
    function uploadCostList() {
        var fileDir = $("#upfile").val();
        var suffix = fileDir.substr(fileDir.lastIndexOf("."));
        if ("" == fileDir) {
            toastr.warning("选择需要导入的压缩包文件!")
            return false;
        }
        if (".zip" != suffix) {
            toastr.warning("文件格式有误!选择zip格式的文件导入!")
            return false;
        }
        $("#form1").attr('disabled', 'disabled');
        $('#loadingModel').modal('show');
        $("#loading").css("background", "url(" + path + "/static/img/load.gif) no-repeat 10px 50%");
        $('#myModal3').modal('hide');
        $('#form1').ajaxSubmit({
            type: 'POST',
            url: path + '/commom/uploadCostList',
            dataType: 'text',//服务器返回的数据类型 可选XML ,Json jsonp script html text等
            data: {upfile: $("#upfile").val()},
            error: function () {
                $("#form1").removeAttr('disabled');
                toastr.warning("上传文件出错!")
            },
            success: function (data) {

                $('#loadingModel').modal('hide');
                var dataObj = eval("(" + data + ")");

                if (dataObj.code == 0) {
                    var dataExcel = dataObj.data;
                    toastr.success("费用清单上传成功");
                    if (dataExcel != null && dataExcel.workBookKey != null && dataExcel.workBookKey != '') {
                        var exportFileName = "费用清单";
                        window.location.href = path + "/exportWrongExcel1?fileName=" + exportFileName + "&workBookKey=" + dataExcel.workBookKey;
                    }
                } else {
                    toastr.error("费用清单上传失败");
                }

                $("#upfile").val("");
                $("#form1").removeAttr('disabled');

            }
        });
    }
</script>
