var picHeight;
var lineIndex = window.parent.document.getElementById("lineIndex").value;
lineIndex = filterXSS(lineIndex);

window.parent.parent.actLineIndex = lineIndex

window.parent.parent.thisUrl = "actualData"
var hisIndex = window.parent.hisIndex;

var webSocket = window.parent.parent.webSocket;
var sssjOption;
var it = null;
var vMax = 0;
var iMax = 0;
var atitle, btitle, ctitle, cShow;
$(function () {

    if (parent.pttype === 0) {
        atitle = "A相";
        btitle = "B相";
        ctitle = "C相";
        atitle = filterXSS(atitle);
        btitle = filterXSS(btitle);
        ctitle = filterXSS(ctitle);
        cShow = true;

        document.getElementById("title1").innerText = atitle;
        document.getElementById("title2").innerText = btitle;
        document.getElementById("title3").innerText = ctitle;
        document.getElementById("title4").innerText = atitle;
        document.getElementById("title5").innerText = btitle;
        document.getElementById("title6").innerText = ctitle;
        document.getElementById("title7").innerText = atitle;
        document.getElementById("title8").innerText = btitle;
        document.getElementById("title9").innerText = ctitle;
    } else if (parent.pttype === 1) {
        atitle = "AB相";
        btitle = "BC相";
        ctitle = "CA相";
        atitle = filterXSS(atitle);
        btitle = filterXSS(btitle);
        ctitle = filterXSS(ctitle);
        cShow = true;
        document.getElementById("title1").innerText = atitle;
        document.getElementById("title2").innerText = btitle;
        document.getElementById("title3").innerText = ctitle;
        document.getElementById("title4").innerText = atitle;
        document.getElementById("title5").innerText = btitle;
        document.getElementById("title6").innerText = ctitle;
        document.getElementById("title7").innerText = atitle;
        document.getElementById("title8").innerText = btitle;
        document.getElementById("title9").innerText = ctitle;
    } else {
        atitle = "AB相";
        btitle = "CB相";
        ctitle = "CA相";
        atitle = filterXSS(atitle);
        btitle = filterXSS(btitle);
        ctitle = filterXSS(ctitle);
        var temp = "-";
        temp = filterXSS(temp);
        cShow = false;
        console.log(btitle)
        document.getElementById("title1").innerText = atitle;
        document.getElementById("title2").innerText = btitle;
        document.getElementById("title3").innerText = temp;
        document.getElementById("title4").innerText = atitle;
        document.getElementById("title5").innerText = btitle;
        document.getElementById("title6").innerText = temp;
        document.getElementById("title7").innerText = atitle;
        document.getElementById("title8").innerText = btitle;
        document.getElementById("title9").innerText = temp;
    }
    getMax();
    picHeight = $(window).height() - 265;
    drawPic();
    //首先判断webSocket是否连接
    if (webSocket.readyState != 1) {
        layer.msg('webSocket连接关闭,请联系管理人员', {icon: 2})
        return;
    }
    startSocket();

})

function getMax() {
    $.ajax({
        type: 'POST',
        url: '/pqs9000/device/getLineInfo',
        async: false,
        data: {
            lineIndex: lineIndex
        },
        success: function (data) {
            var pt1 = data.pt1;
            var ct1 = data.ct1;

            vMax = pt1 * 1.2 / 1000;
            iMax = ct1;
        }
    })
}


function startSocket() {
    let index;
    $.ajax({
        type: 'POST',
        dataType: "json",
        url: '/pqs9000/device/socketon',
        data: {
            lineIndex: lineIndex
        },
        beforeSend: function () {
            index = ityzl_SHOW_LOAD_LAYER_PARENT()
        },
        success: function (da) {
          //  console.log(da.code)
            if (da.code == 200) {
                getDatasss();
            } else {
                layer.msg('设备前置机服务器配置异常,请联系管理员', {icon: 2})
                $("#btn_trend").attr("style", "display:none;");
                $("#btn_deal").attr("style", "display:none;");
            }
            ityzl_CLOSE_LOAD_LAYER_PARENT(index);
            /*if(data == null || data == ""){
                layer.msg('前置机连接失败！',{icon:2,time:1000});
            }else{
                var d= data
                let json = JSON.parse(d)
                if (json.resultcode == 10000) {


                    it = setInterval('refreshQuery()', 30000);
                } else {

                }

            }*/
        }
    })


}

var heart = null;

function refreshQuery() {
    heart = window.setInterval(function () {
        $.ajax({
            type: 'get',
            dataType: "json",
            url: '/pqs9000/device/heartSocketon',
            data: {
                lineIndex: lineIndex
            },
            success: function (data) {

            }
        })
    }, 20000)
}


function shutdownsc() {
    window.clearInterval(heart);
    $.ajax({
        type: 'get',
        dataType: "json",
        url: '/pqs9000/device/closeRealTimeData',
        data: {
            lineIndex: lineIndex
        },
        success: function (data) {
        }
    })
}

window.onbeforeunload = function (event) {
   // console.log(hisIndex+"--"+lineIndex)
    if(hisIndex != lineIndex){

        shutdownsc()
    }
};



function timestampToTime(timestamp) {
    var date = new Date(timestamp);// 时间戳为10位需*1000，时间戳为13位的话不需乘1000
    var Y = date.getFullYear() + '-';
    var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date
            .getMonth() + 1)
        + '-';
    var D = change(date.getDate()) + ' ';
    var h = change(date.getHours()) + ':';
    var m = change(date.getMinutes()) + ':';
    var s = change(date.getSeconds());
    return Y + M + D + h + m + s;
}

function change(t) {
    if (t < 10) {
        return "0" + t;
    } else {
        return t;
    }
}
//测试副本
/*function getData() {
    webSocket.onmessage = function (event) {
        console.log(event)

        var aVlist = [], bVlist = [], cVlist = [], Vlist = [];
        var aIlist = [], bIlist = [], cIlist = [], Ilist = [];
        var aPlist = [], bPlist = [], cPlist = [], Plist = [];
        var json1 = (JSON.parse(event.data))['msgbody'];// 通过kafka收到消息的主体

        var json2 = json1[lineIndex];// 监测点数据
        if (json2 === undefined) {
            return;
        }

        var timepoint = json2['TIME'];// 发生时刻
        var s = "最新时刻：" + timestampToTime(parseInt(timepoint));
        var vjson = json2['V'];// 电压相关数据,数组
        var ijson = json2['I'];// 电流相关数据,数组
        var pjson = json2['PQ'];// 功率相关数据,数组
        for (var i = 0; i < vjson.length; i++) {
            var tmplist = vjson[i];
            if (tmplist['SEQ'] == 'A') {
                aVlist.push(parseFloat(tmplist['VRMS']).toFixed(2));// 电压有效值
                aVlist.push(parseFloat(tmplist['V1']).toFixed(2));// 基波电压有效值
                aVlist.push(parseFloat(tmplist['V_ANGLE']).toFixed(2));// 基波电压相角
                aVlist.push((parseFloat(tmplist['DELTA_V'])).toFixed(2));// 电压偏差
                aVlist.push((parseFloat(tmplist['VTHD'])).toFixed(2));// 电压总谐波畸变率
            }
            if (tmplist['SEQ'] == 'B') {
                bVlist.push(parseFloat(tmplist['VRMS']).toFixed(2));// 电压有效值
                bVlist.push(parseFloat(tmplist['V1']).toFixed(2));// 基波电压有效值
                bVlist.push(parseFloat(tmplist['V_ANGLE']).toFixed(2));// 基波电压相角
                bVlist.push((parseFloat(tmplist['DELTA_V'])).toFixed(2));// 电压偏差
                bVlist.push((parseFloat(tmplist['VTHD'])).toFixed(2));// 电压总谐波畸变率
            }
            if (tmplist['SEQ'] == 'C') {
                cVlist.push(parseFloat(tmplist['VRMS']).toFixed(2));// 电压有效值
                cVlist.push(parseFloat(tmplist['V1']).toFixed(2));// 基波电压有效值
                cVlist.push(parseFloat(tmplist['V_ANGLE']).toFixed(2));// 基波电压相角
                cVlist.push((parseFloat(tmplist['DELTA_V'])).toFixed(2));// 电压偏差
                cVlist.push((parseFloat(tmplist['VTHD'])).toFixed(2));// 电压总谐波畸变率
            }
            if (tmplist['SEQ'] == 'T') {
                Vlist.push((parseFloat(tmplist['V_UNBAN'])).toFixed(2));// 电压不平衡
                Vlist.push(parseFloat(tmplist['FREQ']).toFixed(2));// 频率
            }
        }

        for (var i = 0; i < ijson.length; i++) {
            var tmplist = ijson[i];
            if (tmplist['SEQ'] == 'A') {
                aIlist.push(parseFloat(tmplist['IRMS']).toFixed(2));// 电流有效值
                aIlist.push(parseFloat(tmplist['I1']).toFixed(2));// 基波电流有效值
                aIlist.push(parseFloat(tmplist['I_ANGLE']).toFixed(2));// 基波电流相角
                aIlist.push((parseFloat(tmplist['ITHD'])).toFixed(2));// 电流总谐波畸变率
            }
            if (tmplist['SEQ'] == 'B') {
                bIlist.push(parseFloat(tmplist['IRMS']).toFixed(2));// 电流有效值
                bIlist.push(parseFloat(tmplist['I1']).toFixed(2));// 基波电流有效值
                bIlist.push(parseFloat(tmplist['I_ANGLE']).toFixed(2));// 基波电流相角
                bIlist.push((parseFloat(tmplist['ITHD'])).toFixed(2));// 电流总谐波畸变率
            }
            if (tmplist['SEQ'] == 'C') {
                cIlist.push(parseFloat(tmplist['IRMS']).toFixed(2));// 电流有效值
                cIlist.push(parseFloat(tmplist['I1']).toFixed(2));// 基波电流有效值
                cIlist.push(parseFloat(tmplist['I_ANGLE']).toFixed(2));// 基波电流相角
                cIlist.push((parseFloat(tmplist['ITHD'])).toFixed(2));// 电流总谐波畸变率
            }
            if (tmplist['SEQ'] == 'T') {
                Ilist.push((parseFloat(tmplist['I_UNBAN'])).toFixed(2));// 电流不平衡
            }
        }



        var vtmp = Math.max.apply(Math, [aVlist[1], bVlist[1], cVlist[1]]);
        var itmp = Math.max.apply(Math, [aIlist[1], bIlist[1], cIlist[1]]);
        var avlen = (aVlist[1] / vtmp * 75).toString() + '%';
        var bvlen = (bVlist[1] / vtmp * 75).toString() + '%';
        var cvlen = (cVlist[1] / vtmp * 75).toString() + '%';

        var ailen = (aIlist[1] / itmp * 45).toString() + '%';
        var bilen = (bIlist[1] / itmp * 45).toString() + '%';
        var cilen = (cIlist[1] / itmp * 45).toString() + '%';

        sssjOption.setOption({
            title: {
                text: s,
                x: 'center'
            },
            series: [{
                name: atitle + '电压有效值',
                data: [{
                    value: aVlist[0],
                    name: atitle + '(kV)'
                }]
            }, {
                name: btitle + '电压有效值',
                data: [{
                    value: bVlist[0],
                    name: btitle + '(kV)'
                }]
            }, {
                name: ctitle + '电压有效值',
                data: [{
                    value: cVlist[0],
                    name: ctitle + '(kV)'
                }]
            }, {
                name: 'A相电流有效值',
                data: [{
                    value: aIlist[0],
                    name: 'A相(A)'
                }]
            }, {
                name: 'B相电流有效值',
                data: [{
                    value: bIlist[0],
                    name: 'B相(A)'
                }]
            }, {
                name: 'C相电流有效值',
                data: [{
                    value: cIlist[0],
                    name: 'C相(A)'
                }]
            }, {
                name: '基波电流有效值',
                pointer: {
                    length: ailen
                },
                data: [{
                    value: aIlist[2],
                    name: 'A相'
                }]
            }, {
                name: '基波电流有效值',
                pointer: {
                    length: bilen
                },
                data: [{
                    value: bIlist[2],
                    name: 'B相'
                }]
            }, {
                name: '基波电流有效值',
                pointer: {
                    length: cilen
                },
                data: [{
                    value: cIlist[2],
                    name: 'C相'
                }]
            }, {
                name: '基波电压有效值',
                pointer: {
                    length: avlen
                },
                data: [{
                    value: aVlist[2],
                    name: 'A相'
                }]
            }, {
                name: '基波电压有效值',
                pointer: {
                    length: bvlen
                },
                data: [{
                    value: bVlist[2],
                    name: 'B相'
                }]
            }, {
                name: '基波电压有效值',
                pointer: {
                    length: cvlen
                },
                data: [{
                    value: cVlist[2],
                    name: 'C相'
                }]
            }]
        });

        document.getElementById("data1").innerText = aVlist[0];
        document.getElementById("data2").innerText = bVlist[0];
        if (parent.pttype == 2) {
            document.getElementById("data3").innerText = "-";
        } else {
            document.getElementById("data3").innerText = cVlist[0];
        }
        document.getElementById("data4").innerText = aIlist[0];
        document.getElementById("data5").innerText = bIlist[0];
        document.getElementById("data6").innerText = cIlist[0];
        document.getElementById("data7").innerText = aVlist[1];
        document.getElementById("data8").innerText = bVlist[1];
        document.getElementById("data9").innerText = cVlist[1];
        document.getElementById("data10").innerText = aVlist[2];
        document.getElementById("data11").innerText = bVlist[2];
        document.getElementById("data12").innerText = cVlist[2];
        document.getElementById("data13").innerText = aIlist[1];
        document.getElementById("data14").innerText = bIlist[1];
        document.getElementById("data15").innerText = cIlist[1];
        document.getElementById("data16").innerText = aIlist[2];
        document.getElementById("data17").innerText = bIlist[2];
        document.getElementById("data18").innerText = cIlist[2];

        document.getElementById("sdata1").innerText = aVlist[3];
        document.getElementById("sdata2").innerText = bVlist[3];
        if (parent.pttype == 2) {
            document.getElementById("sdata3").innerText = "-";
        } else {
            document.getElementById("sdata3").innerText = cVlist[3];
        }
        document.getElementById("sdata4").innerText = aVlist[4];
        document.getElementById("sdata5").innerText = bVlist[4];
        if (parent.pttype == 2) {
            document.getElementById("sdata6").innerText = "-";
        } else {
            document.getElementById("sdata6").innerText = cVlist[4];
        }
        document.getElementById("sdata7").innerText = aIlist[3];
        document.getElementById("sdata8").innerText = bIlist[3];
        document.getElementById("sdata9").innerText = cIlist[3];
        document.getElementById("sdata10").innerText = Vlist[0];
        document.getElementById("sdata11").innerText = Ilist[0];
        document.getElementById("sdata12").innerText = Vlist[1];

        // drawPic(aVlist, bVlist, cVlist, Vlist, aIlist, bIlist, cIlist,
        // Ilist,s);


    }
}*/

//正式使用
function getDatasss() {
    webSocket.onmessage = function (event) {
       // console.log(event.data)
        var json0 = JSON.parse(event.data);// 通过kafka收到消息的主体
        var rescode = json0['resultcode'];
        if (rescode == '10000') {
            var aVlist = [], bVlist = [], cVlist = [], Vlist = [];
            var aIlist = [], bIlist = [], cIlist = [], Ilist = [];
            var aPlist = [], bPlist = [], cPlist = [], Plist = [];

            var json1 = json0['resultmsg'];
            var json2 = json1[lineIndex];// 监测点数据
            if (json2 === undefined) {
                return;
            }
            var timepoint = json2['TIME'];// 发生时刻
            var s = "最新时刻：" + timestampToTime(parseInt(timepoint));
            var vjson = json2['V'];// 电压相关数据,数组
            var ijson = json2['I'];// 电流相关数据,数组
            var pjson = json2['PQ'];// 功率相关数据,数组

            for (var i = 0; i < vjson.length; i++) {
                var tmplist = vjson[i];
                if (tmplist['SEQ'] == 'A') {
                    aVlist.push(parseFloat(tmplist['VRMS']).toFixed(2));// 电压有效值
                    aVlist.push(parseFloat(tmplist['V1']).toFixed(2));// 基波电压有效值
                    aVlist.push(parseFloat(tmplist['V_ANGLE']).toFixed(2));// 基波电压相角
                    aVlist.push((parseFloat(tmplist['DELTA_V']) ).toFixed(2));// 电压偏差
                    aVlist.push((parseFloat(tmplist['VTHD']) ).toFixed(2));// 电压总谐波畸变率
                }
                if (tmplist['SEQ'] == 'B') {
                    bVlist.push(parseFloat(tmplist['VRMS']).toFixed(2));// 电压有效值
                    bVlist.push(parseFloat(tmplist['V1']).toFixed(2));// 基波电压有效值
                    bVlist.push(parseFloat(tmplist['V_ANGLE']).toFixed(2));// 基波电压相角
                    bVlist.push((parseFloat(tmplist['DELTA_V'])).toFixed(2));// 电压偏差
                    bVlist.push((parseFloat(tmplist['VTHD'])).toFixed(2));// 电压总谐波畸变率
                }
                if (tmplist['SEQ'] == 'C') {
                    cVlist.push(parseFloat(tmplist['VRMS']).toFixed(2));// 电压有效值
                    cVlist.push(parseFloat(tmplist['V1']).toFixed(2));// 基波电压有效值
                    cVlist.push(parseFloat(tmplist['V_ANGLE']).toFixed(2));// 基波电压相角
                    cVlist.push((parseFloat(tmplist['DELTA_V'])).toFixed(2));// 电压偏差
                    cVlist.push((parseFloat(tmplist['VTHD'])).toFixed(2));// 电压总谐波畸变率
                }
                if (tmplist['SEQ'] == 'T') {
                    Vlist.push((parseFloat(tmplist['V_UNBAN'])).toFixed(2));// 电压不平衡
                    Vlist.push(parseFloat(tmplist['FREQ']).toFixed(2));// 频率
                }
            }

            for (var i = 0; i < ijson.length; i++) {
                var tmplist = ijson[i];
                if (tmplist['SEQ'] == 'A') {
                    aIlist.push(parseFloat(tmplist['IRMS']).toFixed(2));// 电流有效值
                    aIlist.push(parseFloat(tmplist['I1']).toFixed(2));// 基波电流有效值
                    aIlist.push(parseFloat(tmplist['I_ANGLE']).toFixed(2));// 基波电流相角
                    aIlist.push((parseFloat(tmplist['ITHD'])).toFixed(2));// 电流总谐波畸变率
                }
                if (tmplist['SEQ'] == 'B') {
                    bIlist.push(parseFloat(tmplist['IRMS']).toFixed(2));// 电流有效值
                    bIlist.push(parseFloat(tmplist['I1']).toFixed(2));// 基波电流有效值
                    bIlist.push(parseFloat(tmplist['I_ANGLE']).toFixed(2));// 基波电流相角
                    bIlist.push((parseFloat(tmplist['ITHD'])).toFixed(2));// 电流总谐波畸变率
                }
                if (tmplist['SEQ'] == 'C') {
                    cIlist.push(parseFloat(tmplist['IRMS']).toFixed(2));// 电流有效值
                    cIlist.push(parseFloat(tmplist['I1']).toFixed(2));// 基波电流有效值
                    cIlist.push(parseFloat(tmplist['I_ANGLE']).toFixed(2));// 基波电流相角
                    cIlist.push((parseFloat(tmplist['ITHD'])).toFixed(2));// 电流总谐波畸变率
                }
                if (tmplist['SEQ'] == 'T') {
                    Ilist.push((parseFloat(tmplist['I_UNBAN'])).toFixed(2));// 电流不平衡
                }
            }

            //功率
            for (var i = 0; i < pjson.length; i++) {
                let tmplist = pjson[i];
                if (tmplist['SEQ'] == 'A') {
                    aPlist.push((parseFloat(tmplist['P'])).toFixed(2));// 有功功率
                    aPlist.push((parseFloat(tmplist['Q'])).toFixed(2));// 无功功率
                    aPlist.push(parseFloat(tmplist['S']).toFixed(2));// 视在功率
                    aPlist.push(parseFloat(tmplist['PF']).toFixed(2));// 功率因素
                    aPlist.push(parseFloat(tmplist['DF']).toFixed(2));// 基波功率因素
                }
                if (tmplist['SEQ'] == 'B') {
                    bPlist.push((parseFloat(tmplist['P'])).toFixed(2));// 有功功率
                    bPlist.push((parseFloat(tmplist['Q'])).toFixed(2));// 无功功率
                    bPlist.push(parseFloat(tmplist['S']).toFixed(2));// 视在功率
                    bPlist.push(parseFloat(tmplist['PF']).toFixed(2));// 功率因素
                    bPlist.push(parseFloat(tmplist['DF']).toFixed(2));// 基波功率因素
                }
                if (tmplist['SEQ'] == 'C') {
                    cPlist.push((parseFloat(tmplist['P'])).toFixed(2));// 有功功率
                    cPlist.push((parseFloat(tmplist['Q'])).toFixed(2));// 无功功率
                    cPlist.push(parseFloat(tmplist['S']).toFixed(2));// 视在功率
                    cPlist.push(parseFloat(tmplist['PF']).toFixed(2));// 功率因素
                    cPlist.push(parseFloat(tmplist['DF']).toFixed(2));// 基波功率因素
                }
                if (tmplist['SEQ'] == 'T') {
                    Plist.push((parseFloat(tmplist['P'])).toFixed(2));// 有功功率
                    Plist.push((parseFloat(tmplist['Q'])).toFixed(2));// 无功功率
                    Plist.push(parseFloat(tmplist['S']).toFixed(2));// 视在功率
                    Plist.push(parseFloat(tmplist['PF']).toFixed(2));// 功率因素
                    Plist.push(parseFloat(tmplist['DF']).toFixed(2));// 基波功率因素
                }
            }

            var vtmp = Math.max.apply(Math, [aVlist[1], bVlist[1], cVlist[1]]);
            var itmp = Math.max.apply(Math, [aIlist[1], bIlist[1], cIlist[1]]);
            var avlen = (aVlist[1] / vtmp * 75).toString() + '%';
            var bvlen = (bVlist[1] / vtmp * 75).toString() + '%';
            var cvlen = (cVlist[1] / vtmp * 75).toString() + '%';

            var ailen = (aIlist[1] / itmp * 45).toString() + '%';
            var bilen = (bIlist[1] / itmp * 45).toString() + '%';
            var cilen = (cIlist[1] / itmp * 45).toString() + '%';

            let temSer;
            if(parent.pttype === 2){
                temSer = {
                    name: ctitle + '电压有效值',
                    data: [{
                        value: '-',
                        name: ctitle + '(kV)'
                    }]
                }
            }else {
                temSer = {
                    name: ctitle + '电压有效值',
                    data: [{
                        value: cVlist[0],
                        name: ctitle + '(kV)'
                    }]
                }
            }

            sssjOption.setOption({
                title: {
                    text: s,
                    x: 'center'
                },
                series: [{
                    name: atitle + '电压有效值',
                    data: [{
                        value: aVlist[0],
                        name: atitle + '(kV)'
                    }]
                }, {
                    name: btitle + '电压有效值',
                    data: [{
                        value: bVlist[0],
                        name: btitle + '(kV)'
                    }]
                }, temSer, {
                    name: 'A相电流有效值',
                    data: [{
                        value: aIlist[0],
                        name: 'A相(A)'
                    }]
                }, {
                    name: 'B相电流有效值',
                    data: [{
                        value: bIlist[0],
                        name: 'B相(A)'
                    }]
                }, {
                    name: 'C相电流有效值',
                    data: [{
                        value: cIlist[0],
                        name: 'C相(A)'
                    }]
                }, {
                    name: '基波电流相角',
                    pointer: {
                        length: ailen
                    },
                    data: [{
                        value: aIlist[2],
                        name: 'A相'
                    }]
                }, {
                    name: '基波电流相角',
                    pointer: {
                        length: bilen
                    },
                    data: [{
                        value: bIlist[2],
                        name: 'B相'
                    }]
                }, {
                    name: '基波电流相角',
                    pointer: {
                        length: cilen
                    },
                    data: [{
                        value: cIlist[2],
                        name: 'C相'
                    }]
                }, {
                    name: '基波电压相角',
                    pointer: {
                        length: avlen
                    },
                    data: [{
                        value: aVlist[2],
                        name: 'A相'
                    }]
                }, {
                    name: '基波电压相角',
                    pointer: {
                        length: bvlen
                    },
                    data: [{
                        value: bVlist[2],
                        name: 'B相'
                    }]
                }, {
                    name: '基波电压相角',
                    pointer: {
                        length: cvlen
                    },
                    data: [{
                        value: cVlist[2],
                        name: 'C相'
                    }]
                }]
            });

            document.getElementById("data1").innerText = aVlist[0];
            document.getElementById("data2").innerText = bVlist[0];
            if (parent.pttype == 2) {
                document.getElementById("data3").innerText = "-";
            } else {
                document.getElementById("data3").innerText = cVlist[0];
            }
            document.getElementById("data4").innerText = aIlist[0];
            document.getElementById("data5").innerText = bIlist[0];
            document.getElementById("data6").innerText = cIlist[0];
            document.getElementById("data7").innerText = aVlist[1];
            document.getElementById("data8").innerText = bVlist[1];
            document.getElementById("data9").innerText = cVlist[1];
            document.getElementById("data10").innerText = aVlist[2];
            document.getElementById("data11").innerText = bVlist[2];
            document.getElementById("data12").innerText = cVlist[2];
            document.getElementById("data13").innerText = aIlist[1];
            document.getElementById("data14").innerText = bIlist[1];
            document.getElementById("data15").innerText = cIlist[1];
            document.getElementById("data16").innerText = aIlist[2];
            document.getElementById("data17").innerText = bIlist[2];
            document.getElementById("data18").innerText = cIlist[2];

            document.getElementById("sdata1").innerText = aVlist[3];
            document.getElementById("sdata2").innerText = bVlist[3];
            if (parent.pttype == 2) {
                document.getElementById("sdata3").innerText = "-";
            } else {
                document.getElementById("sdata3").innerText = cVlist[3];
            }
            document.getElementById("sdata4").innerText = aVlist[4];
            document.getElementById("sdata5").innerText = bVlist[4];
            if (parent.pttype == 2) {
                document.getElementById("sdata6").innerText = "-";
            } else {
                document.getElementById("sdata6").innerText = cVlist[4];
            }
            document.getElementById("sdata7").innerText = aIlist[3];
            document.getElementById("sdata8").innerText = bIlist[3];
            document.getElementById("sdata9").innerText = cIlist[3];
            document.getElementById("sdata10").innerText = Vlist[0];
            document.getElementById("sdata11").innerText = Ilist[0];
            document.getElementById("sdata12").innerText = Vlist[1];

            // drawPic(aVlist, bVlist, cVlist, Vlist, aIlist, bIlist, cIlist,
            // Ilist,s);

            //功率
            document.getElementById("gdata1").innerText = aPlist[0];
            document.getElementById("gdata2").innerText = bPlist[0];
            document.getElementById("gdata3").innerText = cPlist[0];
            document.getElementById("gdata4").innerText = Plist[0];
            document.getElementById("gdata5").innerText = aPlist[1];
            document.getElementById("gdata6").innerText = bPlist[1];
            document.getElementById("gdata7").innerText = cPlist[1];
            document.getElementById("gdata8").innerText = Plist[1];
            document.getElementById("gdata9").innerText = aPlist[2];
            document.getElementById("gdata10").innerText = bPlist[2];
            document.getElementById("gdata11").innerText = cPlist[2];
            document.getElementById("gdata12").innerText = Plist[2];
            document.getElementById("gdata13").innerText = aPlist[3];
            document.getElementById("gdata14").innerText = bPlist[3];
            document.getElementById("gdata15").innerText = cPlist[3];
            document.getElementById("gdata16").innerText = Plist[3];
            document.getElementById("gdata17").innerText = aPlist[4];
            document.getElementById("gdata18").innerText = bPlist[4];
            document.getElementById("gdata19").innerText = cPlist[4];
            document.getElementById("gdata20").innerText = Plist[4];

            //发送心跳
            if (heart == null) {
                $.ajax({
                    type: 'get',
                    dataType: "json",
                    url: '/pqs9000/device/heartSocketon',
                    data: {
                        lineIndex: lineIndex
                    },
                    success: function (data) {

                    }
                })
                refreshQuery()
            }

            $("#btn_trend").attr("style","display;");
            $("#btn_deal").attr("style","display;");
        } else if (rescode == 5555) {
            //出错情况
            window.clearInterval(heart);
            layer.msg('请求数据超时', {icon: 2, time: 2000})

        } else if (rescode == 5556) {
            //出错情况
            window.clearInterval(heart);
            layer.msg('连接前置服务器失败', {icon: 2, time: 2000})

        } else if (rescode == 10008) {
           // console.log("6666")
            //出错情况
            window.clearInterval(heart);
            layer.msg('前置机正在处理,请稍后再试', {icon: 2, time: 2000})

        } else {
            window.clearInterval(heart);
            layer.msg('未知异常', {icon: 2, time: 2000})
        }
    }
}

function drawPic() {
    $("#sssj").css("height", picHeight);

    echarts.dispose($("#sssj")[0]);
    sssjOption = echarts.init($("#sssj")[0]);


    option = {
        title: {
            text: '',
            x: 'center'
        },
        tooltip: {
            formatter: "{a} <br/>{c} {b}"
        },
        series: [
            {
                name: atitle + '电压有效值',
                type: 'gauge',
                center: ['20%', '30%'], // 默认全局居中
                radius: '50%',
                min: 0,
                max: vMax,
                startAngle: 180,
                endAngle: 90,
                splitNumber: 2,
                axisLine: { // 坐标轴线
                    lineStyle: { // 属性lineStyle控制线条样式
                        color: [[0.25, '#DAA520'], [0.5, '#DAA520'],
                            [0.75, '#DAA520'], [1, '#DAA520']],
                        width: 5
                    }
                },
                axisTick: { // 坐标轴小标记
                    length: 12, // 属性length控制线长
                    lineStyle: { // 属性lineStyle控制线条样式
                        color: 'auto'
                    }
                },
                splitLine: { // 分隔线
                    length: 20, // 属性length控制线长
                    lineStyle: { // 属性lineStyle（详见lineStyle）控制线条样式
                        color: 'auto'
                    }
                },
                pointer: {
                    width: 5
                },
                title: {
                    offsetCenter: ['-125%', '-55%'], // x, y，单位px
                },
                detail: {
                    // 其余属性默认使用全局文本样式，详见TEXTSTYLE
                    fontWeight: 'bolder',
                    offsetCenter: ['40%', '-35%'],
                    fontSize: '35px',
                    fontWeight: 'bolder'
                },
                data: [{
                    value: [0],
                    name: atitle + '(kV)'
                }]
            },
            {
                name: btitle + '电压有效值',
                type: 'gauge',
                center: ['20%', '60%'], // 默认全局居中
                radius: '50%',
                min: 0,
                max: vMax,
                startAngle: 180,
                endAngle: 90,
                splitNumber: 2,
                axisLine: { // 坐标轴线
                    lineStyle: { // 属性lineStyle控制线条样式
                        color: [[0.25, '#2E8B57'], [0.5, '#2E8B57'],
                            [0.75, '#2E8B57'], [1, '#2E8B57']],
                        width: 5
                    }
                },
                axisTick: { // 坐标轴小标记
                    length: 12, // 属性length控制线长
                    lineStyle: { // 属性lineStyle控制线条样式
                        color: 'auto'
                    }
                },
                splitLine: { // 分隔线
                    length: 20, // 属性length控制线长
                    lineStyle: { // 属性lineStyle（详见lineStyle）控制线条样式
                        color: 'auto'
                    }
                },
                pointer: {
                    width: 5
                },
                title: {
                    offsetCenter: ['-125%', '-55%'], // x, y，单位px
                },
                detail: {
                    // 其余属性默认使用全局文本样式，详见TEXTSTYLE
                    fontWeight: 'bolder',
                    offsetCenter: ['40%', '-35%'],
                    fontSize: '35px',
                    fontWeight: 'bolder'
                },
                data: [{
                    value: [0],
                    name: btitle + '(kV)'
                }]
            },
            {
                name: ctitle + '电压有效值',
                type: 'gauge',
                center: ['20%', '90%'], // 默认全局居中
                radius: '50%',
                min: 0,
                max: vMax,
                startAngle: 180,
                endAngle: 90,
                splitNumber: 2,
                axisLine: { // 坐标轴线
                    lineStyle: { // 属性lineStyle控制线条样式
                        color: [[0.25, '#A52a2a'], [0.5, '#A52a2a'],
                            [0.75, '#A52a2a'], [1, '#A52a2a']],
                        width: 5
                    }
                },
                axisTick: { // 坐标轴小标记
                    length: 12, // 属性length控制线长
                    lineStyle: { // 属性lineStyle控制线条样式
                        color: 'auto'
                    }
                },
                splitLine: { // 分隔线
                    length: 20, // 属性length控制线长
                    lineStyle: { // 属性lineStyle（详见lineStyle）控制线条样式
                        color: 'auto'
                    }
                },
                pointer: {
                    width: 5
                },
                title: {
                    offsetCenter: ['-125%', '-55%'], // x, y，单位px
                },
                detail: {
                    // 其余属性默认使用全局文本样式，详见TEXTSTYLE
                    fontWeight: 'bolder',
                    offsetCenter: ['40%', '-35%'],
                    fontSize: '35px',
                    fontWeight: 'bolder'
                },
                data: [{
                    value: [0],
                    name: ctitle + '(kV)'
                }]
            },
            {
                name: 'A相电流有效值',
                type: 'gauge',
                center: ['80%', '30%'], // 默认全局居中
                radius: '50%',
                min: 0,
                max: iMax,
                startAngle: 90,
                endAngle: 0,
                splitNumber: 2,
                axisLine: { // 坐标轴线
                    lineStyle: { // 属性lineStyle控制线条样式
                        color: [[0.25, '#DAA520'], [0.5, '#DAA520'],
                            [0.75, '#DAA520'], [1, '#DAA520']],
                        width: 5
                    }
                },
                axisTick: { // 坐标轴小标记
                    length: 12, // 属性length控制线长
                    lineStyle: { // 属性lineStyle控制线条样式
                        color: 'auto'
                    }
                },
                splitLine: { // 分隔线
                    length: 20, // 属性length控制线长
                    lineStyle: { // 属性lineStyle（详见lineStyle）控制线条样式
                        color: 'auto'
                    }
                },
                pointer: {
                    width: 5
                },
                title: {
                    offsetCenter: ['125%', '-55%'], // x, y，单位px
                },
                detail: {
                    // 其余属性默认使用全局文本样式，详见TEXTSTYLE
                    fontWeight: 'bolder',
                    offsetCenter: ['-45%', '-35%'],
                    fontSize: '35px',
                    fontWeight: 'bolder'
                },
                data: [{
                    value: [0],
                    name: 'A相(A)'
                }]
            },
            {
                name: 'B相电流有效值',
                type: 'gauge',
                center: ['80%', '60%'], // 默认全局居中
                radius: '50%',
                min: 0,
                max: iMax,
                startAngle: 90,
                endAngle: 0,
                splitNumber: 2,
                axisLine: { // 坐标轴线
                    lineStyle: { // 属性lineStyle控制线条样式
                        color: [[0.25, '#2E8B57'], [0.5, '#2E8B57'],
                            [0.75, '#2E8B57'], [1, '#2E8B57']],
                        width: 5
                    }
                },
                axisTick: { // 坐标轴小标记
                    length: 12, // 属性length控制线长
                    lineStyle: { // 属性lineStyle控制线条样式
                        color: 'auto'
                    }
                },
                splitLine: { // 分隔线
                    length: 20, // 属性length控制线长
                    lineStyle: { // 属性lineStyle（详见lineStyle）控制线条样式
                        color: 'auto'
                    }
                },
                pointer: {
                    width: 5
                },
                title: {
                    offsetCenter: ['125%', '-55%'], // x, y，单位px
                },
                detail: {
                    // 其余属性默认使用全局文本样式，详见TEXTSTYLE
                    fontWeight: 'bolder',
                    offsetCenter: ['-45%', '-35%'],
                    fontSize: '35px',
                    fontWeight: 'bolder'
                },
                data: [{
                    value: [0],
                    name: 'B相(A)'
                }]
            },
            {
                name: 'C相电流有效值',
                type: 'gauge',
                center: ['80%', '90%'], // 默认全局居中
                radius: '50%',
                min: 0,
                max: iMax,
                startAngle: 90,
                endAngle: 0,
                splitNumber: 2,
                axisLine: { // 坐标轴线
                    lineStyle: { // 属性lineStyle控制线条样式
                        color: [[0.25, '#A52a2a'], [0.5, '#A52a2a'],
                            [0.75, '#A52a2a'], [1, '#A52a2a']],
                        width: 5
                    }
                },
                axisTick: { // 坐标轴小标记
                    length: 12, // 属性length控制线长
                    lineStyle: { // 属性lineStyle控制线条样式
                        color: 'auto'
                    }
                },
                splitLine: { // 分隔线
                    length: 20, // 属性length控制线长
                    lineStyle: { // 属性lineStyle（详见lineStyle）控制线条样式
                        color: 'auto'
                    }
                },
                pointer: {
                    width: 5
                },
                title: {
                    offsetCenter: ['125%', '-55%'], // x, y，单位px
                },
                detail: {
                    // 其余属性默认使用全局文本样式，详见TEXTSTYLE
                    fontWeight: 'bolder',
                    offsetCenter: ['-45%', '-35%'],
                    fontSize: '35px',
                    fontWeight: 'bolder'
                },
                data: [{
                    value: [0],
                    name: 'C相(A)'
                }]
            },
            {
                name: '基波电流相位',
                type: 'gauge',
                // 表盘最小值
                min: 180,
                // 表盘最大值
                max: -180,
                // 表盘分割数
                splitNumber: 12,
                // 圆心位置
                center: ['50%', '50%'],
                // 半径
                radius: '50%',
                startAngle: 180,
                endAngle: -179.99,
                // 指针方向
                clockWise: true,
                title: false,
                // 表盘外框
                axisLine: {
                    show: true,
                    lineStyle: {
                        color: [[0.25, '#DAA520'], [0.5, '#DAA520'],
                            [0.75, '#DAA520'], [1, '#DAA520']],
                        width: 2
                    }
                },
                // 表盘细分数
                axisTick: {
                    show: true,
                    splitNumber: 5,
                    length: 6,
                    lineStyle: {
                        color: '#eee',
                        width: 1,
                        type: 'solid',
                    }
                },
                // 分割线
                splitLine: {
                    show: true,
                    length: 10,
                    lineStyle: {
                        color: '#eee',
                        width: 2,
                        type: 'solid',
                    }
                },
                // 分割线标识
                axisLabel: {
                    show: true,
                    distance:5,
                    formatter: function (v) {
                        switch (v + '') {
                            case '-180':
                                return '';
                            default:
                                return v;
                        }
                    }
                },

                // 指针设置
                pointer: {
                    length: '45%',
                    width: 2
                },
                detail: {
                    show: false
                },
                data: [{
                    value: 0,
                    name: 'A相'
                }]
            },
            {
                name: '基波电流相位',
                type: 'gauge',
                // 表盘最小值
                min: 180,
                // 表盘最大值
                max: -180,
                // 表盘分割数
                splitNumber: 12,
                // 圆心位置
                center: ['50%', '50%'],
                // 半径
                radius: '50%',
                startAngle: 180,
                endAngle: -179.99,
                // 指针方向
                clockWise: true,
                title: false,
                // 表盘外框
                axisLine: {
                    show: true,
                    lineStyle: {
                        color: [[0.25, '#2E8B57'], [0.5, '#2E8B57'],
                            [0.75, '#2E8B57'], [1, '#2E8B57']],
                        width: 2
                    }
                },
                // 表盘细分数
                axisTick: {
                    show: true,
                    splitNumber: 5,
                    length: 6,
                    lineStyle: {
                        color: '#eee',
                        width: 1,
                        type: 'solid',
                    }
                },
                // 分割线
                splitLine: {
                    show: true,
                    length: 10,
                    lineStyle: {
                        color: '#eee',
                        width: 2,
                        type: 'solid',
                    }
                },
                // 分割线标识
                axisLabel: {
                    show: false
                },

                // 指针设置
                pointer: {
                    length: '45%',
                    width: 2
                },
                detail: {
                    show: false
                },
                data: [{
                    value: 0,
                    name: 'B相'
                }]
            },
            {
                name: '基波电流相位',
                type: 'gauge',
                // 表盘最小值
                min: 180,
                // 表盘最大值
                max: -180,
                // 表盘分割数
                splitNumber: 12,
                // 圆心位置
                center: ['50%', '50%'],
                // 半径
                radius: '50%',
                startAngle: 180,
                endAngle: -179.99,
                // 指针方向
                clockWise: true,
                title: false,
                // 表盘外框
                axisLine: {
                    show: true,
                    lineStyle: {
                        color: [[0.25, '#A52a2a'], [0.5, '#A52a2a'],
                            [0.75, '#A52a2a'], [1, '#A52a2a']],
                        width: 2
                    }
                },
                // 表盘细分数
                axisTick: {
                    show: true,
                    splitNumber: 5,
                    length: 6,
                    lineStyle: {
                        color: '#eee',
                        width: 1,
                        type: 'solid',
                    }
                },
                // 分割线
                splitLine: {
                    show: true,
                    length: 10,
                    lineStyle: {
                        color: '#eee',
                        width: 2,
                        type: 'solid',
                    }
                },
                // 分割线标识
                axisLabel: {
                    show: false
                },

                // 指针设置
                pointer: {
                    length: '45%',
                    width: 2
                },
                detail: {
                    show: false
                },
                data: [{
                    value: 0,
                    name: 'C相'
                }]
            },
            {
                name: '基波电压相位',
                type: 'gauge',
                // 表盘最小值
                min: 180,
                // 表盘最大值
                max: -180,
                // 表盘分割数
                splitNumber: 12,
                // 圆心位置
                center: ['50%', '50%'],
                // 半径
                radius: '85%',
                startAngle: 180,
                endAngle: -179.99,
                // 指针方向
                clockWise: true,
                title: false,
                // 表盘外框
                axisLine: {
                    show: true,
                    lineStyle: {
                        color: [[0.25, '#DAA520'], [0.5, '#DAA520'],
                            [0.75, '#DAA520'], [1, '#DAA520']],
                        width: 1.5
                    }
                },
                // 表盘细分数
                axisTick: {
                    show: true,
                    splitNumber: 5,
                    length: 6,
                    lineStyle: {
                        color: '#eee',
                        width: 1,
                        type: 'solid',
                    }
                },
                // 分割线
                splitLine: {
                    show: true,
                    length: 10,
                    lineStyle: {
                        color: '#eee',
                        width: 2,
                        type: 'solid',
                    }
                },
                // 分割线标识
                axisLabel: {
                    show: true,
                    distance: 5,
                    formatter: function (v) {
                        switch (v + '') {
                            case '-180':
                                return '';
                            default:
                                return v;
                        }
                    }
                },

                // 指针设置
                pointer: {
                    length: '75%',
                    width: 4
                },
                detail: {
                    show: false
                },
                data: [{
                    value: 0,
                    name: 'A相'
                }]
            },
            {
                name: '基波电压相位',
                type: 'gauge',
                // 表盘最小值
                min: 180,
                // 表盘最大值
                max: -180,
                // 表盘分割数
                splitNumber: 12,
                // 圆心位置
                center: ['50%', '50%'],
                // 半径
                radius: '85%',
                startAngle: 180,
                endAngle: -179.99,
                // 指针方向
                clockWise: true,
                title: false,
                // 表盘外框
                axisLine: {
                    show: true,
                    lineStyle: {
                        color: [[0.25, '#2E8B57'], [0.5, '#2E8B57'],
                            [0.75, '#2E8B57'], [1, '#2E8B57']],
                        width: 1.5
                    }
                },
                // 表盘细分数
                axisTick: {
                    show: true,
                    splitNumber: 5,
                    length: 6,
                    lineStyle: {
                        color: '#eee',
                        width: 1,
                        type: 'solid',
                    }
                },
                // 分割线
                splitLine: {
                    show: true,
                    length: 10,
                    lineStyle: {
                        color: '#eee',
                        width: 2,
                        type: 'solid',
                    }
                },
                // 分割线标识
                axisLabel: {
                    show: false
                },

                // 指针设置
                pointer: {
                    length: '75%',
                    width: 4
                },
                detail: {
                    show: false
                },
                data: [{
                    value: 0,
                    name: 'B相'
                }]
            },
            {
                name: '基波电压相位',
                type: 'gauge',
                // 表盘最小值
                min: 180,
                // 表盘最大值
                max: -180,
                // 表盘分割数
                splitNumber: 12,
                // 圆心位置
                center: ['50%', '50%'],
                // 半径
                radius: '85%',
                startAngle: 180,
                endAngle: -179.99,
                // 指针方向
                clockWise: true,
                title: false,
                // 表盘外框
                axisLine: {
                    show: true,
                    lineStyle: {
                        color: [[0.25, '#A52a2a'], [0.5, '#A52a2a'],
                            [0.75, '#A52a2a'], [1, '#A52a2a']],
                        width: 1.5
                    }
                },
                // 表盘细分数
                axisTick: {
                    show: true,
                    splitNumber: 5,
                    length: 6,
                    lineStyle: {
                        color: '#eee',
                        width: 1,
                        type: 'solid',
                    }
                },
                // 分割线
                splitLine: {
                    show: true,
                    length: 10,
                    lineStyle: {
                        color: '#eee',
                        width: 2,
                        type: 'solid',
                    }
                },
                // 分割线标识
                axisLabel: {
                    show: false
                },

                // 指针设置
                pointer: {
                    length: '75%',
                    width: 4
                },
                detail: {
                    show: false
                },
                data: [{
                    value: 0,
                    name: 'C相'
                }]
            }]
    };

    sssjOption.setOption(option);

    document.getElementById("data1").innerText = "";
    document.getElementById("data2").innerText = "";
    document.getElementById("data3").innerText = "";
    document.getElementById("data4").innerText = "";
    document.getElementById("data5").innerText = "";
    document.getElementById("data6").innerText = "";
    document.getElementById("data7").innerText = "";
    document.getElementById("data8").innerText = "";
    document.getElementById("data9").innerText = "";
    document.getElementById("data10").innerText = "";
    document.getElementById("data11").innerText = "";
    document.getElementById("data12").innerText = "";
    document.getElementById("data13").innerText = "";
    document.getElementById("data14").innerText = "";
    document.getElementById("data15").innerText = "";
    document.getElementById("data16").innerText = "";
    document.getElementById("data17").innerText = "";
    document.getElementById("data18").innerText = "";

    document.getElementById("sdata1").innerText = "";
    document.getElementById("sdata2").innerText = "";
    document.getElementById("sdata3").innerText = "";
    document.getElementById("sdata4").innerText = "";
    document.getElementById("sdata5").innerText = "";
    document.getElementById("sdata6").innerText = "";
    document.getElementById("sdata7").innerText = "";
    document.getElementById("sdata8").innerText = "";
    document.getElementById("sdata9").innerText = "";
    document.getElementById("sdata10").innerText = "";
    document.getElementById("sdata11").innerText = "";
    document.getElementById("sdata12").innerText = "";
}

function queryData() {
    $.ajax({
        url: '/pqs9000/device/qualityAssess',
        data: {
            lineIndex: lineIndex
        },
        type: 'post',
        dataType: 'json',
        beforeSend: function () {
            i = ityzl_SHOW_LOAD_LAYER();
        },
        success: function (data) {

        }
    })
}

$("#btn_deal").click(function () {
    layer.open({
        type: 2,
        title: '谐波频谱',
        maxmin: false,
        shadeClose: true, // 点击遮罩关闭层
        area: ['100%', '100%'],
        content: 'xbpp',
        scrollbar: false,
        end: function (index, layero) {
            getDatasss();
        }
    });
})

$("#btn_trend").click(function () {
    layer.open({
        type: 2,
        title: '实时趋势',
        maxmin: false,
        shadeClose: true, // 点击遮罩关闭层
        area: ['100%', '100%'],
        content: 'trend',
        scrollbar: false,
        end: function (index, layero) {
            getDatasss();
        }
    });
})
