<%@ 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}/css/plugin/bootstrap/bootstrap.css">
    <link rel="stylesheet"
          href="${ctx}/css/plugin/datatimepicker/bootstrap-datetimepicker.css">
    <link rel="stylesheet" href="${ctx}/js/plugin/layui/css/layui.css">
    <link rel="stylesheet"
          href="${ctx}/js/plugin/dateRangePicker/daterangepicker.css">
    <link rel="stylesheet" href="${ctx}/css/basic.css">
    <style type="text/css">
        html {
            overflow: hidden;
        }

        .layui-left {
            float: left;
        }

        .self-style {
            margin: 0px;
            position: absolute;
            left: 280px;
            top: 25px;
            bottom: 0;
            z-index: 1;
        }

        .width1 {
            width: 85px;
        !
        important
        }

        .width2 {
            width: 140px;
        !
        important
        }

        .form-control {
            height: 26px;
        !important
        }
    </style>
</head>
<body class="bg-white">
<%@include file="../include/deviceTree.jsp" %>
<%--Tab选项卡区域--%>
<div class="layui-left layui-tab self-style pd10">
    <table class="table" id="device" frame="border" rules="groups">
        <tr>
            <td align="right" class="width1">一次接线图:</td>
            <td align="left" class="width2">
                <form class="form-inline ml12"
                      enctype="multipart/form-data" id="uploadForm">
                    <input type="file" name="file" id="inputfile">
                </form>
            </td>
            <td align="left">
                <button type="button" id="importimg"
                        class="btn  themeBGColor">上传
                </button>
            </td>
        </tr>
        <tr>
            <td align="right" class="width1">报告编号:</td>
            <td align="left" class="width2"><input type="text"
                                                   name="reportNumber" id="reportNumber"></td>
            <td></td>
        </tr>
        <tr>
            <td align="right" class="width1">客户名称:</td>
            <td align="left" class="width2"><input type="text"
                                                   name="crmName" id="crmName"></td>
            <td></td>
        </tr>
        <tr>
            <td align="right" class="width1"></td>
            <td align="left" class="width2">
                <button type="button"
                        id="exportWord" class="btn  themeBGColor">生成
                </button>
            </td>
            <td></td>
        </tr>
    </table>
</div>
<%--时间区域--%>
<form class="form-inline header"
      style="float: left; margin-top: 2px; position: relative; z-index: 99">
    <%@include file="../include/time.jsp" %>
</form>

<input type="hidden" id="imgFlag" value="0">
<input type="hidden" id="lineIndex" name="lineIndex">
<input type="hidden" id="lineName" name="lineName">
<script src="${ctx}/js/plugin/bootstrap/bootstrap.min.js"></script>
<script src="${ctx}/js/plugin/layui/layui.js"></script>
<script src="${ctx}/js/plugin/dateRangePicker/moment.min.js"></script>
<script src="${ctx}/js/plugin/dateRangePicker/daterangepicker.js"></script>
<script src="${ctx}/js/plugin/bootstrap/bootstrap-datetimepicker.js"></script>
<script
        src="${ctx}/js/plugin/bootstrap/bootstrap-datetimepicker.zh-CN.js"></script>
<script src="${ctx}/jspJS/utils/judgeAjaxStatus.js"></script>
<script src="${ctx}/jspJS/utils/timeControl.js"></script>
<script src="${ctx}/jspJS/utils/loading.js"></script>
<script src="${ctx}/js/basic.js"></script>
<script type="text/javascript">
    $("#importimg").click(
        function () {
            var i;
            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("请选择图片！", {
                        icon: 5,
                        time: 2000
                    }, function () {
                        layer.closeAll()
                    });
                } else if (uploadEventFile.toLowerCase().lastIndexOf(".jpg") < 0
                    && uploadEventFile.toLowerCase().lastIndexOf(".png") < 0) {
                    layer.msg("只能上传图片文件", {
                        icon: 5,
                        time: 2000
                    }, function () {
                        layer.closeAll()
                    });
                } else {
                    layer.confirm('确定上传？', function (index) {
                        var formData = new FormData($('#uploadForm')[0]);
                        $.ajax({
                            method: "post",
                            url: "/pqs9000/exportmodel/importImg",
                            data: formData,
                            async: false,
                            cache: false,
                            contentType: false,
                            processData: false,
                            success: function (data) {
                                if (data == "namefail") {
                                    layer.msg("上传失败！请选择图片文件", {
                                        icon: 5,
                                        time: 2000
                                    })
                                } else if (data == "fail") {
                                    layer.msg("上传失败！请重新选择图片文件", {
                                        icon: 5,
                                        time: 2000
                                    })
                                } else if (data == "sizefail") {
                                    layer.msg("上传失败,图片大小超过3M!", {
                                        icon: 5,
                                        time: 2000
                                    })
                                } else {
                                    layer.msg("上传成功!", {
                                        icon: 1,
                                        time: 2000
                                    }, function () {
                                        $("#imgFlag").val("1");
                                    })
                                }
                            }
                        })
                    })
                }
            }else {
                layer.msg("上传失败,文件大小超过3M!",{icon:5,time:2000},function(){
                    layer.closeAll()});
            }
        })

    $("#exportWord").click(function () {
        var tips, picdefult;
        var uploadEventFile = $("#imgFlag").val();
        if (uploadEventFile == "0") {
            tips = '将使用默认一次接线图,确定生成?';
            picdefult = '1';
        } else {
            tips = '确定生成?';
            picdefult = '0';
        }
        var pointNode = getTreeSelected(2);
        var startTime = $("#startTime").val();
        var endTime = $("#endTime").val();
        var lineIndex = $("#lineIndex").val();
        var name = $("#lineName").val();
        var reportNumber = $("#reportNumber").val();
        var crmName = $("#crmName").val();
        if(lineIndex == null || lineIndex == ''){
            layer.msg("请选择监测点",{icon:2})
            return
        }
        layer.confirm(tips, function (index) {
            var idea;
            idea = ityzl_SHOW_LOAD_LAYER();
            $.ajax({
                method: "post",
                url: "/pqs9000/exportmodel/exportModel",
                data: {
                    startTime: startTime,
                    endTime: endTime,
                    lineIndex: lineIndex,
                    name: name,
                    reportNumber: reportNumber,
                    crmName: crmName,
                    picdefault: picdefult
                },
                dataType: 'text',
                async: false,
                success: function (data) {
                    if (data == "pathfail") {
                        layer.msg("生成失败,模板路径错误!", {
                            icon: 5,
                            time: 2000
                        }, function () {
                            parent.layer.closeAll()
                        });
                        //***********关闭loading
                        ityzl_CLOSE_LOAD_LAYER(i);
                    } else if (data == "readerror") {
                        layer.msg("服务器无法打开WORD模板!", {
                            icon: 5,
                            time: 2000
                        }, function () {
                            parent.layer.closeAll()
                        });
                        //***********关闭loading
                        ityzl_CLOSE_LOAD_LAYER(i);
                    } else if (data == "filefail") {
                        layer.msg("生成失败,上传图片文件有误!", {
                            icon: 5,
                            time: 2000
                        }, function () {
                            parent.layer.closeAll()
                        });
                        //***********关闭loading
                        ityzl_CLOSE_LOAD_LAYER(i);
                    } else if (data == "exportworld") {
                        layer.msg("生成失败,数据有误!", {
                            icon: 5,
                            time: 2000
                        }, function () {
                            parent.layer.closeAll()
                        });
                        //***********关闭loading
                        ityzl_CLOSE_LOAD_LAYER(i);
                    } else {
                        layer.msg("生成成功!", {
                            icon: 1,
                            time: 2000
                        }, function () {
                            self.location.href = "/pqs9000/exportmodel/downloadModel";
                        });
                    }
                    //***********关闭loading
                    ityzl_CLOSE_LOAD_LAYER(idea);
                }
            });
        })
    })
</script>
</body>
</html>
