<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport"
          content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <title>终端版本管理</title>
    <link rel="stylesheet" href="${ctx}/css/plugin/bootstrap/bootstrap.min.css">
    <link rel="stylesheet" href="${ctx}/css/plugin/fontawesome/font-awesome.min.css">
    <link rel="stylesheet" href="${ctx}/css/basic.css">
    <style>
        .form-control {
            height: 22px;
            padding: 1px 5px;
            line-height: 22px;
        }
        .btn {
            padding: 1px 6px;
            font-size:12px;
        }
    </style>
</head>
<body class="container-fluid">
<div class="row">
    <%--页面头--%>
    <div class="col-sm-12 col-xs-12 mt10">
        <div class="form-inline">
            <div class="form-group">
                <label class="col-sm-2 col-xs-2 control-label" style="padding-right: 0px;padding-left: 0px">版本</label>
                <div class="col-sm-10 col-xs-10" style="padding-left: 0px;text-align: left">
                <select class="form-control" id="updateList">

                </select>
                </div>
            </div>
        </div>
    </div>
        <div class="col-xs-12 col-sm-12 mt10" >
            <div class="form-group">
                <label class="col-sm-2 col-xs-2 control-label" style="padding-right: 0px;padding-left: 0px">描述</label>
                <div class="col-sm-10 col-xs-10" style="padding-left: 0px;text-align: left">
                    <textarea id="texte" class="form-control" rows="4" readonly></textarea>
                </div>
            </div>
        </div>
</div>
<footer class="navbar-fixed-bottom">
    <div class="row">
        <div class="col-xs-12 col-sm-12 mt10" style="text-align: center">
            <div class="form-group">
                <button type="button" class="btn btn-primary" id="save">确认</button>
            </div>
        </div>

    </div>
</footer>

<script src="${ctx}/js/plugin/jquery/jquery.min.js"></script>
<script src="${ctx}/js/plugin/layui/layer.js"></script>
<script src="${ctx}/js/plugin/bootstrap/bootstrap.min.js"></script>
<script src="${ctx}/jspJS/utils/loading.js"></script>
<script src="${ctx}/jspJS/utils/judgeAjaxStatus.js"></script>
<script src="${ctx}/jspJS/utils/common.js"></script>
<script>
    var devSeries = getQueryString('devSeries')
    var edArr;
    var sendEdDate = [];
    edArr = window.parent.sendEdArr() //获取devindex
    sendEdDate = window.parent.sendEdDate()
    $(function () {
        init()

        $('body').on('change','#updateList',function () {
            var indexi2;
            var this_id = $(this).val()
            $.ajax({
                type: "get",
                url: "/pqs9900/version/getVersionTwo",
                dataType: "json",
                data: {edIndex:this_id},
                beforeSend: function () {
                    indexi2 = ityzl_SHOW_LOAD_LAYER();
                },
                success: function (data) {
                    if (data.code === 200) {
                        if(data.body!=null){
                            //初始化表格
                            $('#texte').val(data.body.edDescribe==null?'':data.body.edDescribe)
                        }
                    } else {
                        layer.msg(data.message, {icon: 2, time: 2000})

                    }
                    ityzl_CLOSE_LOAD_LAYER(indexi2);
                }
            })
        })


        $('#save').click(function () {
            let id = $('#updateList').val()
            let eddate = $("#updateList").find("option:selected").attr("eddate");
            let up = dateTo(eddate)
            if(id==null||id==''){
                layer.msg('版本号不可为空',{icon:2})
                return
            }

            if(sendEdDate.length!=0){
                var flag = true;
                for(let i=0;i<sendEdDate.length;i++){
                    let guo = dateTo(sendEdDate[i])
                    if(guo.getTime()>up){
                        flag = false;
                        break
                    }
                }
                if(!flag){
                    layer.confirm('存在装置版本低于目标版本,是否继续',function () {
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        window.parent.sendWebSocket(id,1)
                        parent.layer.close(index); //再执行关闭
                    })
                }else {
                    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                    window.parent.sendWebSocket(id,1)
                    parent.layer.close(index); //再执行关闭
                }
            }

        })

    })


    function dateTo(dateStr) {
      return  new Date(Date.parse(dateStr.replace(/-/g,"/")))
    }

    //初始化下拉版本
    function init() {
        let map ={
            devType:devSeries,
            blob:'blob',
            edList:edArr
        }
        $.ajax({
            type: "post",
            url: "/pqs9900/version/getVersionListFilterDevIndex",
            dataType: "json",
            contentType: 'application/json;charset=UTF-8',
            data: JSON.stringify(map),
            success: function (data) {
                if (data.code === 200) {
                    //初始化表格
                    let da = data.body
                    let html='';
                    if(da.length>0){
                        for(var i=0;i<da.length;i++){
                            let op ='<option eddate ="'+da[i].edDate+'" value="'+da[i].edIndex+'">'+da[i].devType+'_'+da[i].edName+'_'+da[i].edProtocol+'_'+da[i].edDate+'</option>'
                            html+=op;
                        }
                        $('#updateList').html(html)
                        $('#updateList').trigger('change')
                    }else {
                        layer.msg('暂无可升级版本!')
                    }
                } else {
                    layer.msg(data.message, {icon: 2, time: 2000})

                }
            }
        })
    }
</script>
</body>
</html>
