<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: HuaJunD
  Date: 2018/10/24
  Time: 11:41
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<html>
<head>
    <title>内部定值的控制字修改</title>
    <link rel="stylesheet" href="${ctx}/css/plugin/bootstrap/bootstrap.min.css">
    <link rel="stylesheet" href="${ctx}/css/plugin/jquery/jquery-ui.css">
    <link rel="stylesheet" href="${ctx}/css/plugin/datatimepicker/bootstrap-datetimepicker.css">
    <link rel="stylesheet" href="${ctx}/css/plugin/metroStyle/metroStyle.css">
    <link rel="stylesheet" href="${ctx}/css/basic.css">
    <link rel="stylesheet" href="${ctx}/css/plugin/datatables/datatables.bootstrap.css">
    <style type="text/css">
        body, html, #allmap {
            width: 100%;
            height: 100%;
            overflow: hidden;
            margin: 0;
            font-family: "微软雅黑";
            background-color: #F9F9F9 !important;
        }

        .dg-sub b.red {

            border-bottom: solid 1px #98af9f;
            font-weight: bold;
        }

        .dg-sub b {
            padding: 2px 5px;
            color: #666;
            font-weight: normal;
        }

        @media screen and (min-width: 1000px) and (max-width: 1400px) and (max-height: 500px) {
            #tj {
                min-height: 500px;
            }
        }

        .nav > li > a {
            padding: 3px 15px;
        }

        ul {
            padding: 0 2px;
            border: 1px solid #696969;
            border-radius: 4px;
        }

        .btn {
            padding: 0px 5px;
        }
    </style>
</head>
<body>
<table id="dzId" class="table table-striped table-bordered  no-footer width100 f12">
    <thead>
    <tr role="row">
        <th></th>
        <th>控制字描述</th>
    </tr>
    </thead>
</table>
<%--用于修改定值--%>
<div style="text-align: center">
    <button type="button" id="right"
            class="btn themeBGColor  ml5 f12" onclick="show()">确定
    </button>
    <button type="button" id="close"
            class="btn themeBGColor  ml5 f12">取消
    </button>
</div>
<input type="hidden" value="${sessionScope.pvIndex}" id="pvIndex">
</body>
<script src="${ctx}/js/plugin/jquery/jquery.min.js"></script>
<script src="${ctx}/js/plugin/bootstrap/bootstrap.min.js"></script>
<script src="${ctx}/js/plugin/layui/layer.js"></script>
<script src="${ctx}/js/plugin/jquery/jquery.contextMenu.js"></script>
<script src="${ctx}/js/plugin/jquery/jquery.cleverTabs.js"></script>
<script src="${ctx}/js/plugin/ztree/jquery.ztree.core.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/timeControl.js"></script>
<script src="${ctx}/js/plugin/datatables/datatables.jquery.js"></script>
<script src="${ctx}/js/plugin/datatables/datatables.bootstrap.js"></script>
<script src="${ctx}/js/plugin/xss/xss.js"></script>
<script src="${ctx}/jspJS/utils/loading.js"></script>
<script src="${ctx}/jspJS/utils/judgeAjaxStatus.js"></script>
<script src="${ctx}/js/color.js"></script>
<script type="text/javascript">
    var dataTable = [];
    var rn = 0;
    var y = "";
    var rows = 0;
    var jsonPro = "";
    var info;
    var isFalse = parent.chooseState();
    var describe = parent.getDe();
    var isUpdate = parent.$("#isUpdate").val();
    $(function () {
        var pvIndex = $("#pvIndex").val();
        pvIndex = filterXSS(pvIndex);
        rows = parent.$("#row").val();
        if(isUpdate == 0){
            document.getElementById("right").style.display="none";
        }
        getdata(pvIndex);
    })
    $("#close").click(function () {
        parent.layer.closeAll();
    })

    function getdata(pvIndex) {
        var len = $(document.body).height()-70;
        $.ajax({
            type: "POST",
            url: "/pqs9900/protectcw/getAll",
            dataType: "text",
            data: {
                pvIndex: pvIndex
            },
            beforeSend: function () {
                idea = ityzl_SHOW_LOAD_LAYER();
            },
            success: function (data) {
                info = $.parseJSON(data);
                if(info.body==null){
                    dataTable = $("#dzId").DataTable();
                    dataTable.clear().draw();
                    dataTable = $('#dzId').DataTable({
                        order: [],
                        columnDefs: [
                            {
                                orderable: false,
                                targets: [0, 1]
                            }
                        ],
                        data: info.body,
                        columns: [
                            {
                                width: "10%", data: "flag",
                                render: function (data, type, full, meta) {
                                    if(isUpdate == 0){
                                        if (describe == "接线方式选择" && meta.row == 15) {
                                            return "<input type ='checkbox' name='test' " +
                                                " class='icheckbox_minimal' id='flg" + meta.row +
                                                "' value='1'   checked='checked' disabled = 'disabled' >";
                                        } else if (data == "1") {
                                            return "<input type ='checkbox' name='test' " +
                                                " class='icheckbox_minimal' id='flg" + meta.row +
                                                "' value='1'   checked='checked' disabled = 'disabled' >";
                                        } else {
                                            return "<input type ='checkbox' id='flg" + meta.row + "' " +
                                                "name='test' class='icheckbox_minimal' value='0' disabled = 'disabled' >";
                                        }
                                    }else {
                                        if (describe == "接线方式选择" && meta.row == 15) {
                                            return "<input type ='checkbox' name='test' " +
                                                " class='icheckbox_minimal' id='flg" + meta.row +
                                                "' value='1'   checked='checked' disabled >";
                                        } else if (data == "1") {
                                            return "<input type ='checkbox' name='test' " +
                                                " class='icheckbox_minimal' id='flg" + meta.row +
                                                "' value='1'   checked='checked'  >";
                                        } else {
                                            return "<input type ='checkbox' id='flg" + meta.row + "' " +
                                                "name='test' class='icheckbox_minimal' value='0' >";
                                        }
                                    }
                                }
                            },
                            {
                                width: "90%", data: "describe",
                                render: function (data, type, full, meta) {
                                    return data;
                                }
                            },
                        ],
                        info: false,
                        scrollY: len,
                        paging: false,
                        destroy: true,
                        searching: true,
                        dom: 'rtip',
                        language: {
                            url: '/pqs9900/json/chine.json',
                            "sEmptyTable": "没有内容"
                        },
                    });
                    //***********关闭loading
                    ityzl_CLOSE_LOAD_LAYER(idea);
                }else {
                    rn = info.body.length;
                    dataTable = $("#dzId").DataTable();
                    dataTable.clear().draw();
                    dataTable = $('#dzId').DataTable({
                        order: [],
                        columnDefs: [
                            {
                                orderable: false,
                                targets: [0, 1]
                            }
                        ],
                        data: info.body,
                        columns: [
                            {
                                width: "10%", data: "flag",
                                render: function (data, type, full, meta) {
                                    if(isUpdate == 0){
                                        if (describe == "接线方式选择" && meta.row == 15) {
                                            return "<input type ='checkbox' name='test' " +
                                                " class='icheckbox_minimal' id='flg" + meta.row +
                                                "' value='1'   checked='checked' disabled = 'disabled' >";
                                        } else if (data == "1") {
                                            return "<input type ='checkbox' name='test' " +
                                                " class='icheckbox_minimal' id='flg" + meta.row +
                                                "' value='1'   checked='checked' disabled = 'disabled' >";
                                        } else {
                                            return "<input type ='checkbox' id='flg" + meta.row + "' " +
                                                "name='test' class='icheckbox_minimal' value='0' disabled = 'disabled' >";
                                        }
                                    }else {
                                        if (describe == "接线方式选择" && meta.row == 15) {
                                            return "<input type ='checkbox' name='test' " +
                                                " class='icheckbox_minimal' id='flg" + meta.row +
                                                "' value='1'   checked='checked' disabled >";
                                        } else if (data == "1") {
                                            return "<input type ='checkbox' name='test' " +
                                                " class='icheckbox_minimal' id='flg" + meta.row +
                                                "' value='1'   checked='checked'  >";
                                        } else {
                                            return "<input type ='checkbox' id='flg" + meta.row + "' " +
                                                "name='test' class='icheckbox_minimal' value='0' >";
                                        }
                                    }
                                }
                            },
                            {
                                width: "90%", data: "describe",
                                render: function (data, type, full, meta) {
                                    return data;
                                }
                            },
                        ],
                        info: false,
                        scrollY: len,
                        paging: false,
                        destroy: true,
                        searching: true,
                        dom: 'rtip',
                        language: {
                            url: '/pqs9900/json/chine.json',
                            "sEmptyTable": "没有内容"
                        },
                    });
                    //***********关闭loading
                    ityzl_CLOSE_LOAD_LAYER(idea);
                }

            }
        });
    }

    function show() {
        y = "";
        for (var i = 0; i < rn; i++) {
            var big = document.getElementById("flg" + i + "");
            if (big.checked) {
                y += 1;
                $("#flg" + i + "").val(1)
            } else {
                y += 0;
                $("#flg" + i + "").val(0)
            }
            if (i == rn - 1) {
                jsonPro += "{\n" +
                    "\t\t\t\t\"type_num\": \"" + info.body[i].typeNum + "\",\n" +
                    "\t\t\t\t\"bit0\": \"" + info.body[i].bit0 + "\",\n" +
                    "\t\t\t\t\"bit1\": \"" + info.body[i].bit1 + "\",\n" +
                    "\t\t\t\t\"describe\": \"" + info.body[i].describe + "\",\n" +
                    "\t\t\t\t\"flag\": \"" + $("#flg" + i + "").val() + "\"\n" +
                    "\t\t\t}";
            } else {
                jsonPro += "{\n" +
                    "\t\t\t\t\"type_num\": \"" + info.body[i].typeNum + "\",\n" +
                    "\t\t\t\t\"bit0\": \"" + info.body[i].bit0 + "\",\n" +
                    "\t\t\t\t\"bit1\": \"" + info.body[i].bit1 + "\",\n" +
                    "\t\t\t\t\"describe\": \"" + info.body[i].describe + "\",\n" +
                    "\t\t\t\t\"flag\": \"" + $("#flg" + i + "").val() + "\"\n" +
                    "\t\t\t},"
            }
        }
        window.parent.jsonProp = jsonPro;
        var nameArr = y.split('');
        var result = [];
        var resultStr = '';
        for (var i = 0, l = nameArr.length; i < l; i++) {
            result.unshift(nameArr[i]);

        }
        for (var i = 0, l = result.length; i < l; i++) {
            resultStr += result[i];
        }
        var dz = (Array(4).join('0') + (parseInt(resultStr, 2).toString(16)).toUpperCase()).slice(-4)
        parent.$("#valDz" + rows + "").val(dz);
        parent.$("#valDz" + rows + "")[0].style.border="1px solid red";
        parent.layer.closeAll();
    }
</script>
</html>
