var path = window.location.href;// 获取界面路径
var ismult, color;
var phasicType = [];
var valueTypeName;
var valueType = "1";
var dataTailNum = 0;
var dataTailData = [];
/*******************************************************************************
 * z-tree控件基本参数设置
 ******************************************************************************/
var settingRight = {
    check: {
        enable: true,
        chkStyle: "radio",
        radioType: "all"
    },
    data: {
        simpleData: {
            enable: true
        }
    },
    callback: {
        beforeExpand: beforeExpand,
        beforeCheck: beforeCheck,
        onExpand: onExpand,
        onClick: onClick,
        onCheck: checkTarget,
    }
};
var loading;// 用于页面的loading
var bcheck = false;// 监测点选中状态
var lineIndex;// 所选中监测点
var num = 1;// 用于判断节点
// tree节点选中之前进行判断
var className = "dark";
var isType = true;//是否含有星型接线
function beforeCheck(treeId, treeNode) {
    className = (className === "dark" ? "" : "dark");
    return (treeNode.doCheck !== false);
}

var pttype = window.parent.pttypes;
// tree展开前处理事件
var curExpandNode = null;
// 用于判断检测点的个数
var pointNum = 1;


function beforeExpand(treeId, treeNode) {
    var pNode = curExpandNode ? curExpandNode.getParentNode() : null;
    var treeNodeP = treeNode.parentTId ? treeNode.getParentNode() : null;
    var zTree1 = $.fn.zTree.getZTreeObj("target");
    for (var i = 0, l = !treeNodeP ? 0 : treeNodeP.children.length; i < l; i++) {
        if (treeNode !== treeNodeP.children[i]) {
            zTree1.expandNode(treeNodeP.children[i], false);
        }
    }
    while (pNode) {
        if (pNode === treeNode) {
            break;
        }
        pNode = pNode.getParentNode();
    }
    if (!pNode) {
        singlePath(treeNode);
    }
}

//获取主题颜色
function getThemeColor() {
    $.ajax({
        type: "POST",
        url: "/pqs9000/theme/getThemeInfo",
        async: false,
        dataType: 'json',
        success: function (data) {
            color = data.body.value;
        }
    })
}

// 改变设备树状态
function changeState(b) {
    bcheck = b;
    var zTree = $.fn.zTree.getZTreeObj("target");
    zTree.checkAllNodes(false);
    disabledNode(false);
    //只查询一个监测点一个指标
    var node = zTree.getNodeByParam("id", 11);
    zTree.checkNode(node, true, true);
    nodes = [];
    checkTarget();
}

// 重新绘制tree内容 只展开一个tree根节点添加该事件
function singlePath(newNode) {
    if (newNode === curExpandNode)
        return;
    var zTree1 = $.fn.zTree.getZTreeObj("target"), rootNodes, tmpRoot, tmpTId, i, j, n;
    if (!curExpandNode) {
        tmpRoot = newNode;
        while (tmpRoot) {
            tmpTId = tmpRoot.tId;
            tmpRoot = tmpRoot.getParentNode();
        }
        rootNodes = zTree1.getNodes();
        for (i = 0, j = rootNodes.length; i < j; i++) {
            n = rootNodes[i];
            if (n.tId != tmpTId) {
                zTree1.expandNode(n, false);
            }
        }
    } else if (curExpandNode && curExpandNode.open) {
        if (newNode.parentTId === curExpandNode.parentTId) {
            zTree1.expandNode(curExpandNode, false);
        } else {
            var newParents = [];
            while (newNode) {
                newNode = newNode.getParentNode();
                if (newNode === curExpandNode) {
                    newParents = null;
                    break;
                } else if (newNode) {
                    newParents.push(newNode);
                }
            }
            if (newParents != null) {
                var oldNode = curExpandNode;
                var oldParents = [];
                while (oldNode) {
                    oldNode = oldNode.getParentNode();
                    if (oldNode) {
                        oldParents.push(oldNode);
                    }
                }
                if (newParents.length > 0) {
                    zTree1.expandNode(oldParents[Math.abs(oldParents.length
                        - newParents.length) - 1], false);
                } else {
                    zTree1.expandNode(oldParents[oldParents.length - 1], false);
                }
            }
        }
    }
    curExpandNode = newNode;
}

// 回调函数，展开tree节点
function onExpand(event, treeId, treeNode) {
    curExpandNode = treeNode;
}

// 回调函数，点击tree展开节点
function onClick(e, treeId, treeNode) {
    var zTree1 = $.fn.zTree.getZTreeObj("target");
    zTree1.expandNode(treeNode, null, null, null, true);
}

// 获取选中的监测点信息
function splitName(num) {
    var data;
    var name = new Array();
    if (num == 1) {
        data = parent.getTreeSelected(2);
    } else {
        data = parent.getTreeSelected(1);
    }
    for (var i = 0; i < data.length; i++) {
        name[i] = data[i].name;
    }
    pointNum = data.length;
    return name;
}

/*******************************************************************************
 * 获取查询指标 计算tree选中的节点，for循环去除计算父节点在内
 ******************************************************************************/
var checkCount = 1, totalcount = 2, nodes = '', node = null;

function checkTarget() {
    var zTree1 = $.fn.zTree.getZTreeObj("target");
    checkCount = zTree1.getCheckedNodes(true).length;
    node = zTree1.getCheckedNodes(true);
    totalcount = checkCount;
    nodes = '';
    var k = 0;
    for (var i = 0; i < totalcount; i++) {
        if (node[i].pId == null) {
            checkCount--;
        } else {
            if (!bcheck) {
                if (k < 3) {
                    nodes += node[i].id + ',';
                } else {
                    zTree1.checkNode(node[i], false, true);
                }
            } else {
                if (k < 1) {
                    nodes += node[i].id + ',';
                } else {
                    zTree1.checkNode(node[i], false, true);
                }
            }
            k++;
        }
    }
    if (k == 1) {

        document.getElementById('harmonicSelect').style.display = 'none';
        document.getElementById('choo').options.length = 0;
        switch (parseInt(nodes)) {
            case 11:
                $("#typeName").html("有功电能:");
                document.getElementById('choo').options.add(new Option('正向有功电能', 1));
                document.getElementById('choo').options.add(new Option('反向有功电能', 2));
                document.getElementById('choo').options.add(new Option('组合有功电能', 3));
                break;
            case 111:
                $("#typeName").html("三相总有功电能:");
                document.getElementById('choo').options.add(new Option('三相总正向有功电能', 1));
                document.getElementById('choo').options.add(new Option('三相总反向有功电能', 2));
                document.getElementById('choo').options.add(new Option('三相总组合有功电能', 3));
                break;
            case 12:
                $("#typeName").html("无功电能:");
                document.getElementById('choo').options.add(new Option('I象限无功电能', 1));
                document.getElementById('choo').options.add(new Option('II象限无功电能', 2));
                document.getElementById('choo').options.add(new Option('III象限无功电能', 3));
                document.getElementById('choo').options.add(new Option('IV象限无功电能', 4));
                document.getElementById('choo').options.add(new Option('组合1无功电能', 5));
                document.getElementById('choo').options.add(new Option('组合2无功电能', 6));
                break;
            case 121:
                $("#typeName").html("三相总无功电能:");
                document.getElementById('choo').options.add(new Option('三相总I象限无功电能', 1));
                document.getElementById('choo').options.add(new Option('三相总II象限无功电能', 2));
                document.getElementById('choo').options.add(new Option('三相总III象限无功电能', 3));
                document.getElementById('choo').options.add(new Option('三相总IV象限无功电能', 4));
                document.getElementById('choo').options.add(new Option('三相总组合1无功电能', 5));
                document.getElementById('choo').options.add(new Option('三相总组合2无功电能', 6));
                break;
            case 13:
                $("#typeName").html("视在电能:");
                document.getElementById('choo').options.add(new Option('正向视在电能', 1));
                document.getElementById('choo').options.add(new Option('反向视在电能', 2));
                break;
            case 131:
                $("#typeName").html("三相总视在电能:");
                document.getElementById('choo').options.add(new Option('三相总正向视在电能', 1));
                document.getElementById('choo').options.add(new Option('三相总反向视在电能', 2));
                break;
            case 14:
                $("#typeName").html("基波有功电能:");
                document.getElementById('choo').options.add(new Option('正向基波有功电能', 1));
                document.getElementById('choo').options.add(new Option('反向基波有功电能', 2));
                document.getElementById('choo').options.add(new Option('组合基波有功电能', 3));
                break;
            case 141:
                $("#typeName").html("三相总基波有功电能:");
                document.getElementById('choo').options.add(new Option('三相总正向基波有功电能', 1));
                document.getElementById('choo').options.add(new Option('三相总反向基波有功电能', 2));
                document.getElementById('choo').options.add(new Option('三相总组合基波有功电能', 3));
                break;
            case 15:
                $("#typeName").html("基波无功电能:");
                document.getElementById('choo').options.add(new Option('I象限基波无功电能', 1));
                document.getElementById('choo').options.add(new Option('II象限基波无功电能', 2));
                document.getElementById('choo').options.add(new Option('III象限基波无功电能', 3));
                document.getElementById('choo').options.add(new Option('IV象限基波无功电能', 4));
                document.getElementById('choo').options.add(new Option('组合1基波无功电能', 5));
                document.getElementById('choo').options.add(new Option('组合2基波无功电能', 6));
                break;
            case 151:
                $("#typeName").html("三相总基波无功电能:");
                document.getElementById('choo').options.add(new Option('三相总I象限基波无功电能', 1));
                document.getElementById('choo').options.add(new Option('三相总II象限基波无功电能', 2));
                document.getElementById('choo').options.add(new Option('三相总III象限基波无功电能', 3));
                document.getElementById('choo').options.add(new Option('三相总IV象限基波无功电能', 4));
                document.getElementById('choo').options.add(new Option('三相总组合1基波无功电能', 5));
                document.getElementById('choo').options.add(new Option('三相总组合2基波无功电能', 6));
                break;
            case 16:
                $("#typeName").html("总谐波有功电能:");
                document.getElementById('choo').options.add(new Option('正向总谐波有功电能', 1));
                document.getElementById('choo').options.add(new Option('反向总谐波有功电能', 2));
                document.getElementById('choo').options.add(new Option('组合总谐波有功电能', 3));
                break;
            case 161:
                $("#typeName").html("三相总谐波有功电能:");
                document.getElementById('choo').options.add(new Option('三相正向总谐波有功电能', 1));
                document.getElementById('choo').options.add(new Option('三相反向总谐波有功电能', 2));
                document.getElementById('choo').options.add(new Option('三相组合总谐波有功电能', 3));
                break;
            case 17:
                $("#typeName").html("总谐波无功电能:");
                document.getElementById('choo').options.add(new Option('I象限总谐波无功电能', 1));
                document.getElementById('choo').options.add(new Option('II象限总谐波无功电能', 2));
                document.getElementById('choo').options.add(new Option('III象限总谐波无功电能', 3));
                document.getElementById('choo').options.add(new Option('IV象限总谐波无功电能', 4));
                document.getElementById('choo').options.add(new Option('组合1总谐波无功电能', 5));
                document.getElementById('choo').options.add(new Option('组合2总谐波无功电能', 6));
                break;
            case 171:
                $("#typeName").html("三相总谐波无功电能:");
                document.getElementById('choo').options.add(new Option('三相I象限总谐波无功电能', 1));
                document.getElementById('choo').options.add(new Option('三相II象限总谐波无功电能', 2));
                document.getElementById('choo').options.add(new Option('三相III象限总谐波无功电能', 3));
                document.getElementById('choo').options.add(new Option('三相IV象限总谐波无功电能', 4));
                document.getElementById('choo').options.add(new Option('三相组合1总谐波无功电能', 5));
                document.getElementById('choo').options.add(new Option('三相组合2总谐波无功电能', 6));
                break;
            case 21:
                $("#typeName").html("谐波有功电能:");
                document.getElementById('choo').options.add(new Option('正向谐波有功电能', 1));
                document.getElementById('choo').options.add(new Option('反向谐波有功电能', 2));
                document.getElementById('harmonicSelect').style.display = 'inline';
                break;
            case 22:
                $("#typeName").html("谐波无功电能:");
                document.getElementById('choo').options.add(new Option('I象限谐波无功电能', 1));
                document.getElementById('choo').options.add(new Option('II象限谐波无功电能', 2));
                document.getElementById('choo').options.add(new Option('III象限谐波无功电能', 3));
                document.getElementById('choo').options.add(new Option('IV象限谐波无功电能', 4));
                document.getElementById('harmonicSelect').style.display = 'inline';
                break;
            case 31:
                $("#typeName").html("有功需量:");
                document.getElementById('choo').options.add(new Option('正向有功需量', 1));
                document.getElementById('choo').options.add(new Option('反向有功需量', 2));
                document.getElementById('choo').options.add(new Option('组合有功需量', 3));
                break;
            case 32:
                $("#typeName").html("无功需量:");
                document.getElementById('choo').options.add(new Option('I象限无功需量', 1));
                document.getElementById('choo').options.add(new Option('II象限无功需量', 2));
                document.getElementById('choo').options.add(new Option('III象限无功需量', 3));
                document.getElementById('choo').options.add(new Option('IV象限无功需量', 4));
                document.getElementById('choo').options.add(new Option('组合1无功需量', 5));
                document.getElementById('choo').options.add(new Option('组合2无功需量', 6));
                break;
        }
        valueType = "1";
    }
    if (nodes != '') {
        nodes = nodes.substring(0, nodes.lastIndexOf(','));
    }
    if (!bcheck) {
        if (k > 3) {
            layer.msg('最多选择3个指标');
        }
    } else {
        if (k > 1) {
            layer.msg('最多选择1个指标');
        }
    }

}

//重新获取数据
function checkTargetFush() {
    var zTree1 = $.fn.zTree.getZTreeObj("target");
    checkCount = zTree1.getCheckedNodes(true).length;
    node = zTree1.getCheckedNodes(true);
    totalcount = checkCount;
    nodes = '';
    var k = 0;
    for (var i = 0; i < totalcount; i++) {
        if (node[i].pId == null) {
            checkCount--;
        } else {
            if (!bcheck) {
                if (k < 3) {
                    nodes += node[i].id + ',';
                } else {
                    zTree1.checkNode(node[i], false, true);
                }
            } else {
                if (k < 1) {
                    nodes += node[i].id + ',';
                } else {
                    zTree1.checkNode(node[i], false, true);
                }
            }
            k++;
        }
    }
    if (nodes != '') {
        nodes = nodes.substring(0, nodes.lastIndexOf(','));
    }
    if (!bcheck) {
        if (k > 3) {
            layer.msg('最多选择3个指标');
        }
    } else {
        if (k > 1) {
            layer.msg('最多选择1个指标');
        }
    }

    // if (!bcheck) {
    //     if (checkCount >= 3) {
    //         disabledNode(true);
    //     } else {
    //         disabledNode(false);
    //     }
    // } else {
    //     if (checkCount >= 1) {
    //         disabledNode(true);
    //     } else {
    //         disabledNode(false);
    //     }
    // }
}

// init method one
$(document).ready(function () {
    getThemeColor();
    deleteOption();
    if (path.indexOf("plate") != -1) {
        var numd = splitTree(num);
        getPttype(numd)
        changeState(false);
    } else {
        if (parent.pttype == 0) {
            $.fn.zTree.init($("#target"), settingRight, zNodes);
            isType = true;
        } else {
            $.fn.zTree.init($("#target"), settingRight, zNodes);
            isType = false;
        }
    }
    addOptions();
    loading = ityzl_SHOW_LOAD_LAYER();
    queryAndShowData();
    var o = document.getElementById("float-news").offsetHeight;
    document.getElementById("target").style.height = o - 70;
});

function getPttype(point) {
    var list = new Object();
    list.point = point;
    var aoData = new Array();
    aoData.push(list)
    $.ajax({
        type: 'POST',
        async: false,
        url: '/pqs9000/device/getPttype',
        data: {
            obj: JSON.stringify(aoData)
        },
        success: function (data) {
            if (data.indexOf(0) != -1) {
                $.fn.zTree.init($("#target"), settingRight, zNodes);
                isType = true;
            } else {
                $.fn.zTree.init($("#target"), settingRight, zNodes);
                isType = false;
            }
        }
    })
}

/*******************************************************************************
 * 给下拉框初始化数据
 ******************************************************************************/
function addOptions() {
    $("#harmonicId").empty();
    for (var i = 1; i < 51; i++) {
        document.getElementById('harmonicId').options.add(new Option(i + '次', i));
    }
}


// 根据检测点id获取监测点名称
function getName(index) {
    for (var i = 0; i < totalcount; i++) {
        if (node[i].id == index) {
            return ' ' + node[i].name;
        }
    }
    return ' ';
}

// 根据条件设置tree节点状态 可用/不可用
function disabledNode(e) {
    var zTree1 = $.fn.zTree.getZTreeObj("target"), l = zTree1
        .getCheckedNodes(false).length, nodes = zTree1
        .getCheckedNodes(false);
    nodeAll = zTree1.getNodes();
    m = zTree1.getNodes().length;
    if (e) {
        for (var i = 0; i < l; i++) {
            zTree1.setChkDisabled(nodes[i], e, false, false);
        }
    } else {
        for (var i = 0; i < m; i++) {
            zTree1.setChkDisabled(nodeAll[i], e, false, true);
        }
    }
}

/*******************************************************************************
 * 获取选中的监测点信息
 ******************************************************************************/
function splitTree(num) {
    var data;
    var index = '';
    if (num == 1) {
        data = parent.getTreeSelected(2);
    } else {
        data = parent.getTreeSelected(1);
    }
    for (var i = 0; i < data.length; i++) {
        index += data[i].nodeIndex + ',';
    }
    if (index != '') {
        index = index.substring(0, index.lastIndexOf(','));
    }
    return index;
}

var height = $(window).height();
var Obj_Limit = [];// 存当限值数组
var obj_ZjCf = [];// 存放暂降触发点数据
var obj_History = [];// 存放历史数据(一次查询更新一次)
var splitObj_History = [];// 临时存放历史数据（分段查询更新一次）
var yevent_value = [];// 最小值
var events = [];// 所有暂降事件汇总
var series_Data = [];// 展示数据
var series_Nav = [];// 导航栏
var colo = [];// 颜色
var titleName = null;// 图形标题名称
var objdata = [];
var tr = 0;

/*******************************************************************************
 * 点击查询按钮
 ******************************************************************************/
var obj_Search;// 查询条件汇总

/*******************************************************************************
 * 谐波次数切换刷新页面结果
 ******************************************************************************/

function harmonicState(value) {
    loading = ityzl_SHOW_LOAD_LAYER();
    harmonic = value;
    queryAndShowData();
}

/*******************************************************************************
 * 切换各个指标的详细刷新页面结果
 ******************************************************************************/
function targetState(type) {
    valueType = type;
    loading = ityzl_SHOW_LOAD_LAYER();
    tr = 1;
    queryAndShowData();
}

/***
 * 切换数据展示
 */
function getDatail(type) {
    dataTailNum = type;
    containData();
}

$("#query").click(function () {
    loading = ityzl_SHOW_LOAD_LAYER();
    // 查询和展示
    queryAndShowData();
})

function deleteOption() {
    $("#interval option[value='年份']").remove();
    $("#interval option[value='季度']").remove();
}

/*******************************************************************************
 * 查询和数据展示 1、获取监测点和指标信息 2、判断查询时间是否合理 3、定义界面的布局 4、控制界面是否显示
 ******************************************************************************/
function queryAndShowData() {
    // 实例化参数，确保每次查询重置
    InstantiationParameter();
    // 控制查询框_不可用
    controlSearch(true);
    // 查询条件汇总
    obj_Search = new Object();
    // 1、判断监测点和指标信息
    if (checkPointandtarget()) {
        // 2、时间判断
        if (CheckDateTime()) {
            // 所有查询条件
            var aoData = new Array();
            aoData.push(obj_Search);
            // 3、限值获取
            // 4、控制界面
            controlwindow();
            // 5、分割时间进行查询
            spitTime();
        } else {
            controlSearch(false);
        }
    }

}

/*******************************************************************************
 * 实例化参数
 ******************************************************************************/
function InstantiationParameter() {
    // 参数初始化
    Obj_Limit = [];
    obj_History = [];
    splitObj_History = [];
    yevent_value = [];// 最小值
    events = [];// 所有暂降事件汇总
    series_Data = [];// 展示数据
    series_Nav = [];// 导航栏
    colo = [];// 颜色
    titleName = null;// 图形标题名称
    objdata = [];
}

/*******************************************************************************
 * 关闭查询字段 blFlag ：true，false
 ******************************************************************************/
function controlSearch(blFlag) {
    document.getElementById("query").disabled = blFlag;
    document.getElementById("choo").disabled = blFlag;
    document.getElementById("harmonicId").disabled = blFlag;
    document.getElementById("interval").disabled = blFlag;
}

/*******************************************************************************
 * 1、检查监测点和指标信息
 ******************************************************************************/
var harmonic = '1';

function checkPointandtarget() {
    var result = true;// 默认选择监测点和指标是符合的
    checkTargetFush();// 获取选中查询指标
    if (obj_Search != null) {
        //获取数据展示方式
        obj_Search.dataTail = $("#dataTail").val();
        // 获取指标类型
        obj_Search.valueType = valueType;
        // 所选中监测点lineindex集合
        if (path.indexOf("plate") != -1) {
            obj_Search.point = splitTree(num);
        } else {
            obj_Search.point = window.parent.document
                .getElementById("lineIndex").value;

        }
        // 所选中指标集合
        obj_Search.condition = nodes;
        // 如果有谐波电压或者谐波电流则增加一项属性
        if (obj_Search.condition.indexOf('21') > -1
            || obj_Search.condition.indexOf('22') > -1) {
            obj_Search.harmonic = harmonic;
        }
        // 展示图形个数，默认是一个
        obj_Search.historynum = 1;
    }

    if (obj_Search.point.length == 0) {
        layer.msg("请至少选择一个监测点!");
        controlSearch(false)
        result = false;
    }
    if (obj_Search.condition.length == 0) {
        layer.msg("请至少选择一个指标查询!");
        controlSearch(false)
        result = false;
    }
    return result;
}

/*******************************************************************************
 * 2、检查时间段确认
 ******************************************************************************/
function CheckDateTime() {
    var result = true;// 默认时间是负荷的
    var startTime = $("#startTime").val() + ' 00:00:00';// 起始时间
    var endTime = $("#endTime").val() + ' 23:59:59';// 结束时间

    if (!compareTime(startTime, endTime)) {
        layer.msg("时间设置错误,开始时间大于结束时间!");
        result = false;
    }
    if (obj_Search != null) {
        obj_Search.startTime = startTime;
        obj_Search.endTime = endTime;
        obj_Search.endAllTime = endTime;// 总结束时间
    }
    return result;
}

/*******************************************************************************
 * 4、界面控制 获取界面有效区域的大小 获取界面主要元素（画图区域）
 ******************************************************************************/
var picHeight = 0;// 界面有效区域大小
var width = 0;// 界面有效区域宽度
var container1, container2, container3, point;// 界面元素
function controlwindow() {
    var height = $("body").height();
    picHeight = height - 26;
    width = $("body").width();
    $("#echartId").css("width", width - 5);
    $("#echartId").css("maxHeight", picHeight);
    container1 = document.getElementById('container1');// 获得元素
    point = document.getElementById('point');
    $("#point").css("height", picHeight);
    $("#imgs").css("height", picHeight - 27)
}

/*******************************************************************************
 * 5、分段查询控制 xhday:分割时间（默认3天） 情况1：假如时间差小于分割时间，则一次查找好 情况2：假如时间差大于分割时间，则分批次查询
 ******************************************************************************/
var spitDays = 0;// 所选时间差：天
var xhcs = 0;// 分割查询次数，默认是0次表示不需要进行查询
var realxhcs = 0;// 实际需要循环次数
var pointmsg = 1;// 监测点个数
function spitTime() {
    // 取绝对值
    spitDays = daysBetween(obj_Search.startTime, obj_Search.endTime);
    // 初始化循环次数（默认一次就能查询结束）
    xhcs = 0;
    realxhcs = Math.ceil(spitDays / xhdays);
    /***************************************************************************
     * 需要进行多次查询 需要重组时间
     **************************************************************************/
    if (realxhcs > 1) {
        obj_Search.endTime = dateAddDays(obj_Search.startTime, xhdays);
    }
    // 所有查询条件
    var aoData = new Array();
    aoData.push(obj_Search);
    getData(aoData);
}

/*******************************************************************************
 * 6、数据查询 *** aoData **** 所有查询条件
 ******************************************************************************/
function getData(aoData) {
    if (path.indexOf("plate") != -1) {
        var name = splitName(num);// 所选择的监测点
    } else {
        var name = window.parent.document.getElementById("lineName").value;
    }
    $.ajax({
        type: 'POST',
        async: true,
        url: '/pqs9000/plate/getPlateResult',
        data: {
            obj: JSON.stringify(aoData)
        },
        error: function (data) {
            layer.msg("未获取到历史数据", {
                icon: 5,
                time: 3000
            });
            controlSearch(false);
        },
        success: function (data) {
            analysisData(data);// 数据解析
            xhcs++;// 没查询一次则增加一个查询
            /*******************************************************************
             * 画图过滤代码 xhcs ==1 则执行画图操作 xhcs==realxhcs则表示所有数据取完毕，此时需要判断是否有数据 xhcs<realxhcs
             * 则执行更新图形操作
             ******************************************************************/
            if (xhcs == 1 && realxhcs == 0) {
                controlChart();// 控制界面图形展示
                drawCharts();
                isData();
                /***************************************************************
                 * 循环次数跟时间2间隔一样，则表示该所选的时间段小于时间间隔 则需要判断是否有数据，以及停止滚动条
                 **************************************************************/
                // todo
            } else if (xhcs == 1 && realxhcs == 1) {
                controlChart();// 控制界面图形展示
                drawCharts();
                isData();
            } else if (xhcs == 1 && realxhcs != 1) {
                controlChart();// 控制界面图形展示
                drawCharts();
            } else if (xhcs < (realxhcs)) {
                controlChart();// 控制界面图形展示
                updateCharts();
            } else if (xhcs == realxhcs) {
                controlChart();// 控制界面图形展示
                // 更新图形
                drawCharts();
                updateCharts();
                controlSearch(false);
                isData();
                ityzl_CLOSE_LOAD_LAYER(loading);// 关闭loading
            }
        }
    })
}

/*******************************************************************************
 * 7、控制界面图形展示
 ******************************************************************************/
function controlChart() {
    container1.style.display = "block";
    point.style.display = "none";
    $("#container1").css("height", picHeight);
}

/*******************************************************************************
 * 8、解析数据 *** data **** 返回数据
 ******************************************************************************/
// 暂降触发点最小值,对比所有的最小值，取ABC三项最小值
function analysisData(data) {
    var tmpData;// 根据图
    // 数据解析
    // 定义obj存储数据
    var tmpObj_Data = [];
    // 数据源获取定义
    tmpData = data.data;
    // 开始解析数据

    var avr = [], bvr = [], cvr = [], fvr = [];
    var tmpTime;// 获取时间
    var tmpObj_Limit = null;
    // 单检测点情况
    tmpObj_Limit = Obj_Limit[0];
    dataTailData[0] = [];
    if (tmpData.length > 0) {
        var targetId = obj_Search.condition.split(",");
        if (targetId[0] == 111 || targetId[0] == 121 || targetId[0] == 131 || targetId[0] == 141 || targetId[0] == 151
            || targetId[0] == 161 || targetId[0] == 171) {
            // 数据解析
            for (var i = 0; i < tmpData.length; i++) {
                tmpTime = parseFloat(tmpData[i][1]);
                fvr.push([tmpTime, parseFloat(tmpData[i][2])]);
            }
            // 临时数据赋值
            tmpObj_Data[0] = fvr;
            splitObj_History[0] = (tmpObj_Data);
            // 把每次查询到的整体数据赋值给全局变量（给切换时候用）
            var tmpObj_History = obj_History[0];
            // 假如不为空则执行更新
            if (tmpObj_History != null) {
                // 临时数据赋值
                tmpObj_History[0] = tmpObj_History[0].concat(fvr);
                obj_History[0] = tmpObj_History;// 重新给该位置赋值
            }
            // 假如为空则执行插入
            else {
                obj_History[0] = tmpObj_Data;
            }
            //判断当前的数据方式
            if ($("#dataTail").val() == 1) {
                detailData(obj_History[0]);
            }
        } else {
            // 数据解析
            for (var i = 0; i < tmpData.length; i++) {
                tmpTime = parseFloat(tmpData[i][1]);
                avr.push([tmpTime, parseFloat(tmpData[i][2])]);
                bvr.push([tmpTime, parseFloat(tmpData[i][3])]);
                cvr.push([tmpTime, parseFloat(tmpData[i][4])]);
            }
            // 临时数据赋值
            tmpObj_Data[0] = avr;
            tmpObj_Data[1] = bvr;
            tmpObj_Data[2] = cvr;
            splitObj_History[0] = (tmpObj_Data);
            // 把每次查询到的整体数据赋值给全局变量（给切换时候用）
            var tmpObj_History = obj_History[0];
            // 假如不为空则执行更新
            if (tmpObj_History != null) {
                // 临时数据赋值
                tmpObj_History[0] = tmpObj_History[0].concat(avr);
                tmpObj_History[1] = tmpObj_History[1].concat(bvr);
                tmpObj_History[2] = tmpObj_History[2].concat(cvr);
                obj_History[0] = tmpObj_History;// 重新给该位置赋值
            }
            // 假如为空则执行插入
            else {
                obj_History[0] = tmpObj_Data;
            }
            //判断当前的数据方式
            if ($("#dataTail").val() == 1) {
                detailData(obj_History[0]);
            }
        }
    }

}

/*******************************************************************************
 * 9、新增图形
 ******************************************************************************/
function drawCharts() {
    objdata = [];
    $('#container1').html("");
    //判断当前的数据方式
    if ($("#dataTail").val() == 1) {
        if (dataTailData.length > 0) {
            if (path.indexOf("plate") != -1) {
                var name = splitName(num);// 所选择的监测点
            } else {
                var name = window.parent.document.getElementById("lineName").value;

            }
            var targetName;// 所选择指标名称
            var targetId = obj_Search.condition.split(",");
            //单检测点单指标
            targetName = getTargetName(targetId[0]);// 获取指标名称
            objdata = dataTailData[0];
            pushWaveData(targetName, objdata, 0);

            initWave(name, targetName, 0, objdata);
        }
    } else {
        if (obj_History.length > 0) {
            if (path.indexOf("plate") != -1) {
                var name = splitName(num);// 所选择的监测点
            } else {
                var name = window.parent.document.getElementById("lineName").value;

            }
            var targetName;// 所选择指标名称
            var targetId = obj_Search.condition.split(",");
            //单检测点单指标
            targetName = getTargetName(targetId[0]);// 获取指标名称
            objdata = obj_History[0];
            pushWaveData(targetName, objdata, 0);

            initWave(name, targetName, 0, objdata);
        }
    }
    // 分割查询控制
    controlSplitSearch();
}

/*******************************************************************************
 * 初始化图形
 *
 * @param name
 *            监测点名称
 * @param targetName
 *            所选指标名称
 * @param number
 *            绘制图形的个数（1,2,3）
 * @param data
 *            所传入数据
 ******************************************************************************/
function initWave(name, targetName, number, data) {
    var unit = getUnit(targetName);// 获取展示Y单位
    $("#echartId").css("height", height);
    Highcharts.setOptions({
        global: {
            useUTC: false
        }
    });
    Highcharts.stockChart('container1', {
        title: {
            text: name + " " + targetName
        },
        subtitle: {
            text: valueTypeName,
            style: {
                color: "#ff0000"
            }
        },
        //导出选中背景色
        navigation: {
            menuItemHoverStyle: {
                background: color,
                color: "#ffffff"
            },
        },
        dataLabels: {
            allowOverlap: true
        },
        tooltip: {
            borderColor: grey,
            backgroundColor: 'rgba(105,105,105,0.7)',
            style: {
                color: 'white',
                fontSize: "15px",
                padding: 10,
            },
            formatter: function () {
                var s = '<b>时刻：'
                    + Highcharts.dateFormat('%Y-%m-%d %H:%M:%S', this.x)
                    + '</b>';
                $.each(this.points, function () {
                    s += '<br/>' + this.series.name + ': '
                        + this.y.toFixed(4) + unit;
                });
                return s;
            },
            shared: true
        },
        // 导航器各项属性设置
        navigator: {
            height: 20,
            margin: 1,
            xAxis: {
                labels: {
                    formatter: function () {
                        return Highcharts.dateFormat('%Y-%m-%d %H:%M:%S',
                            this.value);
                    }
                }
            },
            series: series_Nav[number]
        },
        plotOptions: {
            // line: {
            //     dataGrouping: {
            //         enabled: false
            //     }
            // }
        },
        rangeSelector: {
            enabled: false
        },
        scrollbar: {
            enabled: false
        },
        exporting: {
            enabled: true,   // 开启导出按钮
            filename: name + " " + targetName,
        },
        credits: false,
        colors: colo,
        xAxis: {
            title: {
                text: '(时间)',
                enabled: true,
                align: 'high',
            },
            labels: {
                step: 2
            },
            type: 'datetime',
            dateTimeLabelFormats: {
                second: '%H:%M:%S',
                minute: '%H:%M',
                hour: '%H:%M',
                day: '%m-%d',
                week: '%m-%d',
                month: '%Y-%m',
                year: '%Y'
            },
        },
        yAxis: {
            title: {
                align: 'high',
                offset: 0,
                text: unit,
                rotation: 0,
                y: -10
            },
            labels: {
                formatter: function () {
                    return Highcharts.numberFormat(this.value, 4);
                },
            },
            opposite: false
        },
        legend: {
            align: 'left',
            verticalAlign: 'top',
            left: '10%',
            enabled: true
        },
        series: series_Data[number]
    });
    $('.bxfx').on(
        'mousemove',
        function (e) {
            var sourceChartContainer = $(this);
            // 获取所有highcharts对象
            var sourceChart = sourceChartContainer.highcharts();
            // x坐标轴
            var sourceXAxis = sourceChart.xAxis[0];
            // 获取极值
            var extremes = sourceXAxis.getExtremes();
            // 遍历同节点元素 即highcharts元素块
            var targetChartContainerList = sourceChartContainer
                .siblings('.bxfx');

            // 遍历进行处理
            targetChartContainerList.each(function (num,
                                                    targetChartContainerElement) {
                var targetChartContainer = $(targetChartContainerElement);
                // 获取highcharts对象
                var targetChart = targetChartContainer.highcharts();
                // 偏移值
                var sourceOffset = sourceChartContainer.offset();
                var targetOffset = targetChartContainer.offset();
                var targetE = {};

                targetE.pageX = e.pageX + targetOffset.left
                    - sourceOffset.left;
                targetE.pageY = e.pageY + targetOffset.top
                    - sourceOffset.top;
                var targetE = targetChartContainer
                        .find('rect.highcharts-background')[0]
                    || targetChartContainer
                        .find('path.highcharts-tracker')[0];

                if (targetChart && targetChart.pointer) {
                    var el = targetChart.pointer.normalize(e); // Find
                    if (targetChart.series.length == 0) {
                        if (targetChart.series[num] != undefined) {
                            var point = targetChart.series[1].searchPoint(
                                el, true); // Get
                            if (point) {
                                point.onMouseOver(); // Show the hover
                                // marker
                            }
                        }
                    } else {
                        if (targetChart.series[num] != undefined) {
                            var point = targetChart.series[1].searchPoint(
                                el, true); // Get
                            if (point) {
                                point.onMouseOver(); // Show the hover
                                // marker
                            }
                        }
                    }
                }
            });
        })
}

/*******************************************************************************
 * 初始化数据，当没有数据时画一张无数据的图 obj_History[0]、obj_History[1]、obj_History[2]指的是数据
 * obj_History[0].length == 0,说明该监测点在该指标、在该时间内没有数据
 */
function isData() {
    if ($("#dataTail").val() == 1) {
        if (xhcs == realxhcs) {
            if (dataTailData[0].length == 0) {
                layer.msg("没有获取到该监测点的历史数据", {
                    icon: 5,
                    time: 3000
                });
                container1.style.display = "none";
                point.style.display = "block";
                controlSearch(false);
            }
            ityzl_CLOSE_LOAD_LAYER(loading);// 关闭loading
        } else if (realxhcs == 0) {
            if (dataTailData[0].length == 0) {
                layer.msg("没有获取到该监测点的历史数据", {
                    icon: 5,
                    time: 3000
                });
                container1.style.display = "none";
                point.style.display = "block";
            }
            ityzl_CLOSE_LOAD_LAYER(loading);// 关闭loading
        } else {
            if (dataTailData[0].length == 0) {
                container1.style.display = "none";
                point.style.display = "block";
            }
            ityzl_CLOSE_LOAD_LAYER(loading);// 关闭loading
        }
        if (realxhcs == 0 || realxhcs == xhcs) {
            controlSearch(false);
            ityzl_CLOSE_LOAD_LAYER(loading);// 关闭loading
        }
    } else {
        if (xhcs == realxhcs) {
            if (obj_History[0] == null) {
                layer.msg("没有获取到该监测点的历史数据", {
                    icon: 5,
                    time: 3000
                });
                container1.style.display = "none";
                point.style.display = "block";
                controlSearch(false);
            }
            ityzl_CLOSE_LOAD_LAYER(loading);// 关闭loading
        } else if (realxhcs == 0) {
            if (obj_History[0] == null) {
                layer.msg("没有获取到该监测点的历史数据", {
                    icon: 5,
                    time: 3000
                });
                container1.style.display = "none";
                point.style.display = "block";
            }
            ityzl_CLOSE_LOAD_LAYER(loading);// 关闭loading
        } else {
            if (obj_History[0] == null) {
                container1.style.display = "none";
                point.style.display = "block";
            }
            ityzl_CLOSE_LOAD_LAYER(loading);// 关闭loading
        }
        if (realxhcs == 0 || realxhcs == xhcs) {
            controlSearch(false);
            ityzl_CLOSE_LOAD_LAYER(loading);// 关闭loading
        }
    }
}

/*******************************************************************************
 * 根据所选择的数据类型进行数据切换
 *
 * @param targetName
 *            所选择的目标名称
 * @param data
 *            传入数据
 * @param number
 *            绘图个数（1,2,3）
 ******************************************************************************/
var iv = [];
var zj = [];

function pushWaveData(targetName, data) {
    colo = [];
    titleName = null;// 图形标题名称
    var tmpSeries_Data = [];// 展示数据
    var tmpSeries_Nav = [];// 导航栏
    if (data == null) {
        if (series_Data.length < 3) {
            series_Data.push(tmpSeries_Data);
            series_Nav.push(tmpSeries_Nav);
        }
    } else {
        var targetId = obj_Search.condition.split(",");
        if (targetId[0] == 111 || targetId[0] == 121 || targetId[0] == 131 || targetId[0] == 141 || targetId[0] == 151
            || targetId[0] == 161 || targetId[0] == 171) {
            tmpSeries_Nav.push({
                "data": data[0]
            });
            tmpSeries_Data.push({
                "name": valueTypeName,
                "data": data[0]
            });
            colo.push(black);
        }else {
            tmpSeries_Nav.push({
                "data": data[0]
            });
            tmpSeries_Nav.push({
                "data": data[1]
            });
            tmpSeries_Nav.push({
                "data": data[2]
            });
            tmpSeries_Data.push({
                "name": "A相",
                "data": data[0]
            });
            tmpSeries_Data.push({
                "name": "B相",
                "data": data[1]
            });
            tmpSeries_Data.push({
                "name": "C相",
                "data": data[2]
            });
            colo.push(yellow, green, red);
        }
        series_Data[0] = (tmpSeries_Data);
        series_Nav[0] = (tmpSeries_Nav);
    }

}

/*******************************************************************************
 * 10、更新图形
 ******************************************************************************/
function updateCharts() {
    if (path.indexOf("plate") != -1) {
        var name = splitName(num);// 所选择的监测点
    } else {
        var name = window.parent.document.getElementById("lineName").value;

    }
    var targetName;// 所选择指标名称
    var targetId = obj_Search.condition.split(",");
    // 单监测点单指标情况
    targetName = getTargetName(targetId[0]);// 获取指标名称
    if ($("#dataTail").val() == 1) {
        var data = dataTailData[0];
        updateWaveData(targetName, data);
    } else {
        var data = obj_History[0];
        updateWaveData(targetName, data);
    }

    // //分割查询控制
    controlSplitSearch();
}

/*******************************************************************************
 * 11、查询控制
 ******************************************************************************/
function controlSplitSearch() {
    // 更新完图形之后需要重新进行查询
    if (xhcs <= realxhcs - 1) {
        // 假如是最后一次查询，则结束时间为选择时间
        if (xhcs == realxhcs - 1) {
            obj_Search.startTime = dataAddOneDay(obj_Search.endTime);
            obj_Search.endTime = obj_Search.endAllTime;
        } else if (xhcs < realxhcs - 1) {
            obj_Search.startTime = dataAddOneDay(obj_Search.endTime);
            obj_Search.endTime = dateAddDays(obj_Search.startTime, xhday);
        }

        var aoData = new Array();// 所有查询条件a
        aoData.push(obj_Search);
        getData(aoData);
    }
}

/*******************************************************************************
 * 更新图表
 *
 * @param targetName
 *            所选择的目标名称
 * @param data
 *            传入数据
 ******************************************************************************/
function updateWaveData(targetName, data) {
    var chart = $('#container1').highcharts();
    if (data == undefined) {
        // chart.navigator.series[0].setData(null);
    } else {
        if (chart == undefined) {
            pushWaveData(targetName, data);
            ityzl_CLOSE_LOAD_LAYER(loading);// 关闭loading
        } else {
            if (chart.navigator.series[0] != null) {
                chart.navigator.series[0].setData([]);
                chart.navigator.series[0].setData(data[0]);
            }
            if (chart.navigator.series[1] != null) {
                chart.navigator.series[1].setData([]);
                chart.navigator.series[1].setData(data[1]);
            }
            if (chart.navigator.series[2] != null) {
                chart.navigator.series[2].setData([]);
                chart.navigator.series[2].setData(data[2]);
            }

            if (chart.series[0] != null) {
                chart.series[0].setData([]);
                chart.series[0].setData(data[0]);
            }
            if (chart.series[1] != null) {
                chart.series[1].setData([]);
                chart.series[1].setData(data[1]);
            }
            if (chart.series[2] != null) {
                chart.series[2].setData([]);
                chart.series[2].setData(data[2]);
            }
            chart.redraw(true);
        }

    }
}

/*******************************************************************************
 * 单位指标名称
 ******************************************************************************/
function getTargetName(targetid) {
    var targetName;
    if (targetid == 11) {
        targetName = "有功电能"; // 有功电能
        if (obj_Search.valueType == 1) {
            valueTypeName = "正向有功电能";
        } else if (obj_Search.valueType == 2) {
            valueTypeName = "反向有功电能";
        } else if (obj_Search.valueType == 3) {
            valueTypeName = "组合有功电能";
        }
    } else if (targetid == 111) {
        targetName = "三相总有功电能"; // 三相总有功电能
        if (obj_Search.valueType == 1) {
            valueTypeName = "三相总正向有功电能";
        } else if (obj_Search.valueType == 2) {
            valueTypeName = "三相总反向有功电能";
        } else if (obj_Search.valueType == 3) {
            valueTypeName = "三相总组合有功电能";
        }
    }else if (targetid == 12) {
        targetName = "无功电能"; // 无功电能
        if (obj_Search.valueType == 1) {
            valueTypeName = "I象限无功电能";
        } else if (obj_Search.valueType == 2) {
            valueTypeName = "II象限无功电能"
        } else if (obj_Search.valueType == 3) {
            valueTypeName = "III象限无功电能"
        } else if (obj_Search.valueType == 4) {
            valueTypeName = "IV象限无功电能"
        } else if (obj_Search.valueType == 5) {
            valueTypeName = "组合1无功电能"
        } else if (obj_Search.valueType == 6) {
            valueTypeName = "组合2无功电能"
        }
    } else if (targetid == 121) {
        targetName = "三相总无功电能"; // 三相总无功电能
        if (obj_Search.valueType == 1) {
            valueTypeName = "三相总I象限无功电能";
        } else if (obj_Search.valueType == 2) {
            valueTypeName = "三相总II象限无功电能"
        } else if (obj_Search.valueType == 3) {
            valueTypeName = "三相总III象限无功电能"
        } else if (obj_Search.valueType == 4) {
            valueTypeName = "三相总IV象限无功电能"
        } else if (obj_Search.valueType == 5) {
            valueTypeName = "三相总组合1无功电能"
        } else if (obj_Search.valueType == 6) {
            valueTypeName = "三相总组合2无功电能"
        }
    } else if (targetid == 13) {
        targetName = "视在电能"; // 视在电能
        if (obj_Search.valueType == 1) {
            valueTypeName = "正向视在电能";
        } else if (obj_Search.valueType == 2) {
            valueTypeName = "反向视在电能";
        }
    } else if (targetid == 131) {
        targetName = "三相总视在电能"; // 视在电能
        if (obj_Search.valueType == 1) {
            valueTypeName = "三相总正向视在电能";
        } else if (obj_Search.valueType == 2) {
            valueTypeName = "三相总反向视在电能";
        }
    } else if (targetid == 14) {
        targetName = "基波有功电能"; // 基波有功电能
        if (obj_Search.valueType == 1) {
            valueTypeName = "正向基波有功电能";
        } else if (obj_Search.valueType == 2) {
            valueTypeName = "反向基波有功电能";
        } else if (obj_Search.valueType == 3) {
            valueTypeName = "组合基波有功电能";
        }
    } else if (targetid == 141) {
        targetName = "三相总基波有功电能"; // 基波有功电能
        if (obj_Search.valueType == 1) {
            valueTypeName = "三相总正向基波有功电能";
        } else if (obj_Search.valueType == 2) {
            valueTypeName = "三相总反向基波有功电能";
        } else if (obj_Search.valueType == 3) {
            valueTypeName = "三相总组合基波有功电能";
        }
    } else if (targetid == 15) {
        targetName = "基波无功电能"; // 基波无功电能
        if (obj_Search.valueType == 1) {
            valueTypeName = "I象限基波无功电能";
        } else if (obj_Search.valueType == 2) {
            valueTypeName = "II象限基波无功电能";
        } else if (obj_Search.valueType == 3) {
            valueTypeName = "III象限基波无功电能";
        } else if (obj_Search.valueType == 4) {
            valueTypeName = "IV象限基波无功电能";
        } else if (obj_Search.valueType == 5) {
            valueTypeName = "组合1基波无功电能";
        } else if (obj_Search.valueType == 6) {
            valueTypeName = "组合2基波无功电能";
        }
    } else if (targetid == 151) {
        targetName = "三相总基波无功电能"; // 基波无功电能
        if (obj_Search.valueType == 1) {
            valueTypeName = "三相总I象限基波无功电能";
        } else if (obj_Search.valueType == 2) {
            valueTypeName = "三相总II象限基波无功电能";
        } else if (obj_Search.valueType == 3) {
            valueTypeName = "三相总III象限基波无功电能";
        } else if (obj_Search.valueType == 4) {
            valueTypeName = "三相总IV象限基波无功电能";
        } else if (obj_Search.valueType == 5) {
            valueTypeName = "三相总组合1基波无功电能";
        } else if (obj_Search.valueType == 6) {
            valueTypeName = "三相总组合2基波无功电能";
        }
    } else if (targetid == 16) {
        targetName = "总谐波有功电能"; // 总谐波有功电能
        if (obj_Search.valueType == 1) {
            valueTypeName = "正向总谐波有功电能";
        } else if (obj_Search.valueType == 2) {
            valueTypeName = "反向总谐波有功电能";
        } else if (obj_Search.valueType == 3) {
            valueTypeName = "组合总谐波有功电能";
        }
    } else if (targetid == 161) {
        targetName = "三相总谐波有功电能"; // 总谐波有功电能
        if (obj_Search.valueType == 1) {
            valueTypeName = "三相正向总谐波有功电能";
        } else if (obj_Search.valueType == 2) {
            valueTypeName = "三相反向总谐波有功电能";
        } else if (obj_Search.valueType == 3) {
            valueTypeName = "三相组合总谐波有功电能";
        }
    } else if (targetid == 17) {
        targetName = "总谐波无功电能"; // 总谐波无功电能
        if (obj_Search.valueType == 1) {
            valueTypeName = "I象限总谐波无功电能";
        } else if (obj_Search.valueType == 2) {
            valueTypeName = "II象限总谐波无功电能";
        } else if (obj_Search.valueType == 3) {
            valueTypeName = "III象限总谐波无功电能";
        } else if (obj_Search.valueType == 4) {
            valueTypeName = "IV象限总谐波无功电能";
        } else if (obj_Search.valueType == 5) {
            valueTypeName = "组合1总谐波无功电能";
        } else if (obj_Search.valueType == 6) {
            valueTypeName = "组合2总谐波无功电能";
        }
    } else if (targetid == 171) {
        targetName = "三相总谐波无功电能"; // 总谐波无功电能
        if (obj_Search.valueType == 1) {
            valueTypeName = "三相I象限总谐波无功电能";
        } else if (obj_Search.valueType == 2) {
            valueTypeName = "三相II象限总谐波无功电能";
        } else if (obj_Search.valueType == 3) {
            valueTypeName = "三相III象限总谐波无功电能";
        } else if (obj_Search.valueType == 4) {
            valueTypeName = "三相IV象限总谐波无功电能";
        } else if (obj_Search.valueType == 5) {
            valueTypeName = "三相组合1总谐波无功电能";
        } else if (obj_Search.valueType == 6) {
            valueTypeName = "三相组合2总谐波无功电能";
        }
    } else if (targetid == 21) {
        targetName = "谐波有功电能"; // 谐波有功电能
        if (obj_Search.valueType == 1) {
            valueTypeName = obj_Search.harmonic + "次正向谐波有功电能";
        } else if (obj_Search.valueType == 2) {
            valueTypeName = obj_Search.harmonic + "次反向谐波有功电能";
        }
    } else if (targetid == 22) {
        targetName = "谐波无功电能"; // 谐波无功电能
        if (obj_Search.valueType == 1) {
            valueTypeName = obj_Search.harmonic + "次I象限谐波无功电能";
        } else if (obj_Search.valueType == 2) {
            valueTypeName = obj_Search.harmonic + "次II象限谐波无功电能";
        } else if (obj_Search.valueType == 3) {
            valueTypeName = obj_Search.harmonic + "次III象限谐波无功电能";
        } else if (obj_Search.valueType == 4) {
            valueTypeName = obj_Search.harmonic + "次IV象限谐波无功电能";
        }
    } else if (targetid == 31) {
        targetName = "有功需量"; // 有功需量
        if (obj_Search.valueType == 1) {
            valueTypeName = "正向有功需量";
        } else if (obj_Search.valueType == 2) {
            valueTypeName = "反向有功需量";
        } else if (obj_Search.valueType == 3) {
            valueTypeName = "组合有功需量";
        }
    } else if (targetid == 32) {
        targetName = "无功需量"; // 无功需量
        if (obj_Search.valueType == 1) {
            valueTypeName = "I象限无功需量";
        } else if (obj_Search.valueType == 2) {
            valueTypeName = "II象限无功需量";
        } else if (obj_Search.valueType == 3) {
            valueTypeName = "III象限无功需量";
        } else if (obj_Search.valueType == 4) {
            valueTypeName = "IV象限无功需量";
        } else if (obj_Search.valueType == 5) {
            valueTypeName = "组合1无功需量";
        } else if (obj_Search.valueType == 6) {
            valueTypeName = "组合2无功需量";
        }
    }
    return targetName;
}

/*******************************************************************************
 * 单位获取
 ******************************************************************************/
function getUnit(targetName) {
    var unit;
    if (targetName == "有功电能" ||targetName == "三相总有功电能" || targetName == "基波有功电能" ||targetName == "三相总基波有功电能"|| targetName == "总谐波有功电能"
        ||targetName == "三相总谐波有功电能" || targetName == "谐波有功电能") {
        unit = 'kwh'; // 纵坐标单位为kwh
    } else if (targetName == "无功电能" ||targetName == "三相总无功电能"|| targetName == "基波无功电能"||targetName == "三相总基波无功电能"
        || targetName == "总谐波无功电能" ||targetName == "三相总谐波无功电能"|| targetName == "谐波无功电能") {
        unit = 'kvarh'; // 纵坐标单位为kvarh
    } else if (targetName == "视在电能"||targetName == "三相总视在电能") {
        unit = 'kvah'; // 纵坐标单位为kvah
    } else if (targetName == "有功需量") {
        unit = 'w'; // 纵坐标单位为w
    } else if (targetName == "无功需量") {
        unit = 'var'; // 纵坐标单位为var
    }
    return unit;
}

function changeTree(ptType) {
    var numd = splitTree(num);
    if (ptType == 0) {
        $.fn.zTree.init($("#target"), settingRight, zNodes);
        isType = true;
    } else {
        $.fn.zTree.init($("#target"), settingRight, zNodes);
        isType = false;
    }
    var zTree = $.fn.zTree.getZTreeObj("target");
    zTree.checkAllNodes(false);
    disabledNode(false);
    if (ismult) {
        if (path.indexOf("plate") != -1) {
            parent.triggerCheckBox(1);
        }
        num = 2;
        if (isType) {
            var node = zTree.getNodeByParam("id", 11);
            zTree.checkNode(node, true, true);
        } else {
            var node = zTree.getNodeByParam("id", 12);
            zTree.checkNode(node, true, true);
        }
    } else {
        num = 1;
        if (isType) {
            var node = zTree.getNodeByParam("id", 11);
            zTree.checkNode(node, true, true);
            var node2 = zTree.getNodeByParam("id", 21);
            zTree.checkNode(node2, true, true);
        } else {
            var node = zTree.getNodeByParam("id", 12);
            zTree.checkNode(node, true, true);

            var node2 = zTree.getNodeByParam("id", 21);
            zTree.checkNode(node2, true, true);

        }
    }
    nodes = [];
    checkTarget();
}


//判断当前是否含有数据
function containData() {
    if (dataTailNum == 1) {
        if (obj_History[0] != null) {
            //判断当前数据中的监测点是否与选中的监测点一致
            if (obj_Search.point == splitTree(2)) {
                //判断当前数据中的指标是否与选中的指标一直
                detailData(obj_History[0]);
            } else {
                dataTailData[0] = [];
                queryAndShowData();
            }
        } else {
            dataTailData[0] = [];
            queryAndShowData();
        }
    } else {
        dataTailData[0] = [];
        queryAndShowData();
    }
}

//增量方式进行数据重组
function detailData(data) {
    loading = ityzl_SHOW_LOAD_LAYER();
    var tmpObj_Data = [];
    var avr = [], bvr = [], cvr = [], fvr = [];
    var tmpTime;// 获取时间
    if (data.length > 0) {
        var targetId = obj_Search.condition.split(",");
        if (targetId[0] == 111 || targetId[0] == 121 || targetId[0] == 131 || targetId[0] == 141 || targetId[0] == 151
            || targetId[0] == 161 || targetId[0] == 171) {
            for (var j = 0; j < (data[0].length - 1); j++) {
                tmpTime = parseFloat(data[0][j][0]);
                fvr.push([tmpTime, parseFloat(data[0][j + 1][1] - data[0][j][1])]);
            }
            dataTailData[0] = [];
            // 临时数据赋值
            tmpObj_Data[0] = fvr;
            splitObj_History[0] = (tmpObj_Data);
            // 把每次查询到的整体数据赋值给全局变量（给切换时候用）
            var tmpObj_History = dataTailData[0];
            // 假如不为空则执行更新
            if (tmpObj_History.length != 0) {
                // 临时数据赋值
                tmpObj_History[0] = tmpObj_History[0].concat(fvr);
                dataTailData[0] = tmpObj_History;// 重新给该位置赋值
            }
            // 假如为空则执行插入
            else {
                dataTailData[0] = tmpObj_Data;
            }
        } else {
            for (var j = 0; j < (data[0].length - 1); j++) {
                tmpTime = parseFloat(data[0][j][0]);
                avr.push([tmpTime, parseFloat(data[0][j + 1][1] - data[0][j][1])]);
            }

            for (var j = 0; j < (data[1].length - 1); j++) {
                tmpTime = parseFloat(data[1][j][0]);
                bvr.push([tmpTime, parseFloat(data[1][j + 1][1] - data[1][j][1])]);
            }

            for (var j = 0; j < (data[2].length - 1); j++) {
                tmpTime = parseFloat(data[2][j][0]);
                cvr.push([tmpTime, parseFloat(data[2][j + 1][1] - data[2][j][1])]);
            }
            dataTailData[0] = [];
            // 临时数据赋值
            tmpObj_Data[0] = avr;
            tmpObj_Data[1] = bvr;
            tmpObj_Data[2] = cvr;
            splitObj_History[0] = (tmpObj_Data);
            // 把每次查询到的整体数据赋值给全局变量（给切换时候用）
            var tmpObj_History = dataTailData[0];
            // 假如不为空则执行更新
            if (tmpObj_History.length != 0) {
                // 临时数据赋值
                tmpObj_History[0] = tmpObj_History[0].concat(avr);
                tmpObj_History[1] = tmpObj_History[1].concat(bvr);
                tmpObj_History[2] = tmpObj_History[2].concat(cvr);
                dataTailData[0] = tmpObj_History;// 重新给该位置赋值
            }
            // 假如为空则执行插入
            else {
                dataTailData[0] = tmpObj_Data;
            }
        }
    }
    drawCharts();
    isData();
}