@{
    ViewBag.Title = "Form";
    Layout = "~/Views/Shared/_Form.cshtml";
}



<link href="~/Content/css/bootstrap/bootstrap-select.css" rel="stylesheet" />
<link href="~/Content/css/toastr.min.css" rel="stylesheet" />
<script src="~/Content/js/datepicker/WdatePicker.js"></script>
<script src="~/Content/js/bootstrap/bootstrap-select.min.js"></script>
<script src="~/Content/js/toastr.min.js"></script>
<script src="~/Content/js/parseForm.js"></script>


<style>
    .u-file-btn {
        position: relative;
        direction: ltr;
        height: 23px;
        overflow: hidden;
        line-height: 23px;
        margin-right: 10px;
        padding: 3px 0;
        text-align: center;
        width: 105px;
        color: black;
        background: #D0EEFF;
        border: 1px solid #99D3F5;
        border-radius: 4px;
        color: #fff;
        background-color: #1ABC9C;
        border-color: #1ABC9C;
    }

    .u-file-btn-input {
        cursor: pointer;
        text-align: right;
        z-index: 10;
        font-size: 118px; /* font-size: 118px 工作正常 */
        position: absolute;
        top: 0px;
        right: 0px;
        opacity: 0;
        filter: Alpha(opacity:0);
    }
</style>
<script type="text/javascript">
    toastr.options.positionClass = 'toast-center-center';
</script>


<form id="form1">

    <div style="padding-top: 20px;  ">

        <table class="form" style="text-align:left">
            <tr>
                <td class="formValue" colspan="2">

                    <img src="~/Content/img/Excel.png" style="width:22px;height:22px" />

                    <a href="~/ReportFile/期初导入模板.xlsx" style="color:darkblue; ">期初导入模板 </a>&nbsp;&nbsp;(支持"xls","xlsx"格式)

                </td>
            </tr>
            <tr>

                <td class="formValue" colspan="2">
                    <div class="btn-group" style="width:35px">
                        <label>年份:</label>
                    </div>
                    <div class="btn-group">
                        <input type="text" name="txt_Year" id="txt_Year" class="form-control" style="width:70px" />
                    </div>
                </td>
                <td>
                    <label id="showFileName"></label>
                </td>
            </tr>
            <tr>
                <td class="formValue" style="width:125px">
                    <div id="u-file-c" class="u-file-btn">

                        <input type="file" class="u-file-btn-input" name="files" accept=".csv, application/vnd.ms-excel, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" style="width:350px" />选择上传文件
                    </div>
                </td>
              
                <td class="formValue">
                    <a style=" width 79px" class="btn btn-primary dropdown-text" onclick="Upload()"> 导入数据 </a>
                </td>
            </tr>

            <tr>
               
                <td class="formValue">
                    <label class="radio-inline">
                        <input type="text" name="UPLoadType" id="UPLoadType" class="form-control" value="NCR数量" style="display:none;visibility:hidden" />

                    </label>
                </td>
            </tr>

        </table>



    </div>

</form>



<script>



    $(".u-file-btn").on("change", "input[type='file']", function () {
        var filePath = $(this).val();
        if (filePath.indexOf("xls") != -1 || filePath.indexOf("xlsx") != -1) {

            var arr = filePath.split('\\');
            var fileName = arr[arr.length - 1];

            document.getElementById("showFileName").innerText = fileName;
        } else {

            document.getElementById("showFileName").innerText = "";
            alert("您未上传文件,或者您上传文件类型有误!");
            return false
        }
    })

    $(function () {
        var day = new Date();
        day.setTime(day.getTime());
        var Year = day.getFullYear();
        document.getElementById("txt_Year").value = Year;
    });


    function Upload()
    {

        var form = new FormData(document.getElementById("form1"));

        $.ajax({
            url: "/WMS/HomeWork/UploadFile?" + Math.random(),
            type: "post",
            data: form,
            contentType: false,
            processData: false,
            success: function (data) {
                if (data == "true" || data == true) {
                    //alert("上传成功");
                    //layer.msg("上传成功");
                    $.modalAlertNew("WMS00014");
                    window.setTimeout(function () {
                        $.modalClose();
                    }, 2500);
                    $.currentWindow().$("#gridList").trigger("reloadGrid");
                }
                else {  
                    //alert("上传失败:" + data);
                    $.modalAlertNew("WMS00016", data);
                }
            },
            error: function (aa) {
                $.modalAlertNew("WMS00016", aa);
            }
        });



    }



</script>