<%@ 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>PQS9300技术监督管理系统</title>
    <link rel="stylesheet" href="${ctx}/js/plugin/layui/css/layui.css">
    <link rel="stylesheet" href="${ctx}/css/plugin/bootstrap/bootstrap.min.css">
    <link rel="stylesheet" href="${ctx}/css/plugin/metroStyle/metroStyle.css">
    <link rel="stylesheet" href="${ctx}/css/basic.css">

    <style>
        .layui-form-checked[lay-skin=primary] i {
            color: #fff;
            background-color: var(--primarycolor);
            border-color: var(--primarycolor);
        }

        .layui-form-item {
            margin-bottom: 1.5px;
            height: 20px;
        }

        .layui-form-radio > i:hover, .layui-form-radioed > i {
            color: var(--primarycolor);
        }

        .layui-form-checkbox[lay-skin=primary] span {
            font-weight: normal;
            font-size: 12px;
        }

        .layui-form-checkbox[lay-skin=primary] i {
            width: 14px;
            height: 14px;
            line-height: 14px;
            border-color: #777;
        }
        .overflo{
            overflow-y: scroll;
            height: 310px
        }
    </style>
</head>
<body style="overflow-y: hidden">
<div style="padding: 1px">
    <div class="layui-tab" lay-filter="demo">
        <ul class="layui-tab-title">
            <li class="layui-this" style="width: 33%">负合类型</li>
            <li style="width: 33%">指标参数</li>
            <li style="width: 34%">监测点</li>
        </ul>
        <div class="layui-tab-content" style="padding: 0px">
            <div class="layui-tab-item layui-show">
                <%--干扰源类型--%>
                <form class="layui-form overflo" action="" id="form_1" style="padding-left: 20px">
                    <div id="loadType">

                    </div>
                </form>
            </div>
            <div class="layui-tab-item">
                <form class="layui-form overflo" action="" id="form_2" style="padding-left: 20px">
                    <div class="layui-form-item" style="text-align: right;margin-right: 10px">
                        <input type="radio" name="andor" lay-filter="andor" value="0" title="与">
                        <input type="radio" name="andor" lay-filter="andor" value="1" title="或">
                    </div>
                    <div id="targetType">

                    </div>
                </form>
            </div>
            <div class="layui-tab-item">
                <%--  监测点--%>
                <div class="overflo" id="middle_left" style="color:#333;bottom:0;">
                    <div id="search" style="margin-top: 5px">
                        <input style="width: 140px; height: 25px;margin-left: 10px" id="search_value"
                               type="text" value="" placeholder="请输入关键词" autocomplete="off"
                               oninput="valueChange(this.value)"/>
                        <button type="button" id="serchB"
                                class="btn-primary"
                                onclick="javascript: searchNode(search_value.value)"
                                style="height: 25px; width: 55px; border-radius: 4px; border: 1px solid;margin-left: 10px">
                            <a href="javascript:void(0);" class="btn-primary">搜索</a>
                        </button>
                    </div>
                    <div style="width:285px;">
                        <div id="tree" class="ztree" style="overflow:auto;margin-left: 4px;overflow-x: hidden"></div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="layer-footer"
         style="position: fixed; bottom: 0;width:100%;height:30px;text-align: center;margin-top: 1px">
        <button type="button" class="btn btn-primary" lay-submit lay-filter="config">设置</button>
    </div>
</div>

</body>
<script src="${ctx}/js/plugin/jquery/jquery.min.js"></script>
<script src="${ctx}/jspJS/utils/judgeAjaxStatus.js"></script>
<script src="${ctx}/js/plugin/layui/layui.js"></script>
<script src="${ctx}/js/plugin/ztree/jquery.ztree.core.js"></script>
<script src="${ctx}/js/plugin/ztree/jquery.ztree.excheck.js"></script>
<script src="${ctx}/js/plugin/ztree/jquery.ztree.exhide.js"></script>
<script src="${ctx}/jspJS/utils/strategyTrees.js"></script>
<script src="${ctx}/jspJS/utils/loading.js"></script>
<script>
    layui.use(['laypage', 'layer', 'table', 'form', 'element'], function () {
        var layer = layui.layer //弹层
            , form = layui.form //表单
            , element = layui.element

        var operation = 0  //与或

        var wfIndex = getQueryString('wfIndex');

        var loadtype = '<div class="layui-form-item"><input type="checkbox" name="load" value="{1}" lay-skin="primary" lay-filter="fuheType" title="{2}"{3}></div>'
        var targettype = '<div class="layui-form-item"><input type="checkbox" name="target" value="{1}" lay-skin="primary" lay-filter="targetType" title="{2}"{3}></div>' //指标类型



        initTarget()
        initLoad()
        andOr()

        function initTarget() {
            $.ajax({
                type: 'POST',
                dataType: "json",
                url: '/pqs9300/strategy/targetType',
                data: {wfIndex: wfIndex, type: 1},
                success: function (data) {
                    if (data.code == 200) {
                        $('#targetType').empty()
                        var da = data.body
                        var html2 = ''
                        if (da.length != 0) {
                            da.sort(function (a, b) {
                                return a.dicName.localeCompare(b.dicName, "zh");
                            })

                            for (var i = 0; i < da.length; i++) {
                                html2 += targettype.replace("{1}", da[i].dicIndex)
                                    .replace("{2}", da[i].dicName)
                                    .replace("{3}", da[i].isCheck == 1 ? 'checked' : '')
                            }

                            $('#targetType').append(html2)
                            form.render()
                        }
                    } else {
                        layer.msg(data.message, {icon: 2})
                    }

                },
                error: function () {
                    layer.msg('未知错误', {icon: 2})
                }
            });


        }

        //干扰源类型
        function initLoad() {
            $.ajax({
                type: 'POST',
                dataType: "json",
                url: '/pqs9300/strategy/targetType',
                data: {wfIndex: wfIndex, type: 0},

                success: function (data) {
                    if (data.code == 200) {
                        $('#loadType').empty()
                        var da = data.body
                        var html = ''
                        if (da.length != 0) {
                            da.sort(function (a, b) {
                                return a.dicName.localeCompare(b.dicName, "zh");
                            })
                            for (var i = 0; i < da.length; i++) {
                                html += loadtype.replace("{1}", da[i].dicIndex)
                                    .replace("{2}", da[i].dicName)
                                    .replace("{3}", da[i].isCheck == 1 ? 'checked' : '')
                            }

                            $('#loadType').append(html)
                            form.render()
                        }
                    } else {
                        layer.msg(data.message, {icon: 2})
                    }

                },
                error: function () {
                    layer.msg('未知错误', {icon: 2})
                }
            });
        }

        //与或逻辑展示
        function andOr() {
            $.ajax({
                type: 'GET',
                dataType: "json",
                url: '/pqs9300/strategy/getEarlyWarnById',
                contentType: 'application/json;charset=UTF-8',
                data: {wfIndex: wfIndex},
                success: function (data) {
                    if (data.code == 200) {
                        let da = data.body
                        $("input[name=andor][value='0']").attr("checked", da.operation == 0 ? true : false);
                        $("input[name=andor][value='1']").attr("checked", da.operation == 1 ? true : false);
                        form.render()
                    } else {
                        layer.msg(data.message, {icon: 2})
                    }

                },
                error: function () {
                    layer.msg('未知错误', {icon: 2})
                }
            });
        }

        //逻辑监听
        form.on('radio(andor)', function (data) {
            operation = data.value
        });
        form.on('submit(config)', function (data) {
            let arr = []
            var larr = getTreeCheckBoxData()

            $("input:checkbox[name='load']:checked").each(function() {
                let load = {wfIndex:wfIndex,wfassIndex:$(this).val(),type:0}
                arr.push(load)
            })
            $("input:checkbox[name='target']:checked").each(function() {
                let target = {wfIndex:wfIndex,wfassIndex:$(this).val(),type:1}
                arr.push(target)
            })
            for (var i = 0; i < larr.length; i++) {
                let obj = {wfIndex: wfIndex, wfassIndex: larr[i].nodeIndex, type: 2}
                arr.push(obj)
            }
            $.ajax({
                type: 'POST',
                dataType: "json",
                contentType: 'application/json;charset=UTF-8',
                url: '/pqs9300/strategy/addEarlyWarnAss',
                data: JSON.stringify({wfIndex: wfIndex, state: operation, list: arr}),
                beforeSend: function () {
                    i = ityzl_SHOW_LOAD_LAYER()
                },
                success: function (data) {
                    if (data.code == 200) {
                        initLoad()
                        initTarget()
                        andOr()
                        refreshTreeCheckBox(1)
                        layer.msg(data.message, {icon: 1})
                    } else {
                        layer.msg(data.message, {icon: 2})
                    }
                    CLOSE_LOAD_LAYER(i)
                },
                error: function () {
                    layer.msg('未知错误', {icon: 2})
                }
            });


        });

        function ityzl_SHOW_LOAD_LAYER() {
            return layer.msg('正在设置...', {
                icon: 16,
                shade: [0.5, '#f5f5f5'],
                scrollbar: false,
                area: '200px',
                time: 100000
            });
        }

        function CLOSE_LOAD_LAYER(index) {
            layer.close(index);
        }

        /**
         * 获取url参数
         * @param name 参数名
         * @returns 值
         */
        function getQueryString(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
            var result = window.location.search.substr(1).match(reg);
            return result ? decodeURIComponent(result[2]) : '';
        }


    })


    //获取设备书选择的监测点id对象
    function getTreeCheckBoxData() {
        return getTreeSelected(1);
    }

</script>
</html>
