var proName = window.location.pathname.split("/")[1];
var sysUrl = "http://" + window.location.host + "/" + proName;
$(function () {
    // 基于准备好的dom，初始化echarts实例
    videoRate();
    machineRate();
    xhdRate();
    ydpRate();
//	var spzxl = echarts.init(document.getElementById('spzxl'));
//	var spwhl = echarts.init(document.getElementById('spwhl'));
//	var lxwhl = echarts.init(document.getElementById('lxwhl'));
//	var fwqzxl = echarts.init(document.getElementById('fwqzxl'));
//	var fwqwhl = echarts.init(document.getElementById('fwqwhl'));
    // 使用刚指定的配置项和数据显示图表。
//	spzxl.setOption(option);
//	spwhl.setOption(option);
//	lxwhl.setOption(option);
//	fwqzxl.setOption(option);
//	fwqwhl.setOption(option);
});
// 指定图表的配置项和数据
var option = {
    tooltip: {
        trigger: 'item',
        formatter: "{a} <br/>{b}: {c} ({d}%)"
    },
    legend: {
        orient: 'vertical',
        x: 'left',
        data: []
    },
    series: [{
        name: '访问来源',
        type: 'pie',
        radius: ['50%', '70%'],
        center: ['50%', '40%'],
        color: ['#27a72d', '#ff7a05'],
        avoidLabelOverlap: false,
        label: {
            normal: {
                show: false,
                position: 'center'
            },
            emphasis: {
                show: true,
                textStyle: {
                    fontSize: '20',
                    fontWeight: 'bold'
                }
            }
        },
        labelLine: {
            normal: {
                show: false
            }
        },
        data: [{
            value: 335,
            name: '在线'
        }, {
            value: 310,
            name: '不在线'
        }]
    }]
};

//在线率
function videoRate() {
    $.ajax({
        url: "ywvideocurrentstateAction!statisticsVideoOnlineRate.do",
        type: "post",
        dataType: "JSON",
        data: {},
        success: function (res) {
            if (res) {
                //	console.log(res);
                // 在线率
                $("#videoOnline").text(res.onlinenum);
                $("#videoUnOnline").text(res.unonlinenum);
                var data = [{
                    value: res.onlinenum,
                    name: '在线'
                }, {
                    value: res.unonlinenum,
                    name: '不在线'
                }];
                EchartsBase.circularGraphChart(
                    {
                        id: "spzxl",
                        data: data
                    });
                // // 视频完好率
                // $("#videoIntact").text(res.intactnum);
                // $("#videoUnintact").text(res.unintactnum);
                // var spdata = [{
                // 	value : res.intactnum,
                // 	name : '正常'
                // }, {
                // 	value : res.unintactnum,
                // 	name : '异常'
                // }];
                // EchartsBase.circularGraphChart({
                // 	id:"spwhl",
                // 	data:spdata
                // });
                // // 录像完好率
                // $("#recordIntact").text(res.recordintactnum);
                // $("#recordUnIntact").text(res.unrecordintactnum);
                // var lxdata = [ {
                // 	value : res.recordintactnum,
                // 	name : '正常'
                // }, {
                // 	value : res.unrecordintactnum,
                // 	name : '异常'
                // } ];
                // EchartsBase.circularGraphChart({
                // 	id:"lxwhl",
                // 	data:lxdata
                // });
            }else {
				EchartsBase.circularGraphChart({
					id: "spzxl",
					data: [{
						value: 0,
						name: '在线'
					}, {
						value: 0,
						name: '不在线'
					}]
				});

			}
        },
        error: function (res) {

        }
    })
}

function machineRate() {
    $.ajax({
        url: "ywmachinecurrentstateAction!statisticsMachineOnlineRate.do",
        type: "post",
        dataType: "JSON",
        data: {},
        success: function (res) {
            if (res) {
                //console.log(res);
                // 服务器在线率
                $("#machineOnline").text(res.fwonlinenum);
                $("#machineUnOnline").text(res.fwunonlinenum);
                var data = [{
                    value: res.fwonlinenum,
                    name: '在线'
                }, {
                    value: res.fwunonlinenum,
                    name: '不在线'
                }];
                EchartsBase.circularGraphChart({
                    id: "fwqzxl",
                    data: data
                });
                // // 服务器完好率
                // $("#machineIntact").text(res.fwintactnum);
                // $("#machineUnIntact").text(res.fwunIntactnum);
                // var whdata = [ {
                // 	value : res.fwintactnum,
                // 	name : '正常'
                // }, {
                // 	value : res.fwunIntactnum,
                // 	name : '异常'
                // } ];
                // EchartsBase.circularGraphChart({
                // 	id:"fwqwhl",
                // 	data:whdata
                // });
            }else {
				EchartsBase.circularGraphChart({
					id: "fwqzxl",
					data: [{
						value: 0,
						name: '在线'
					}, {
						value: 0,
						name: '不在线'
					}]
				});

			}
        },
        error: function (res) {

        }
    })
}

function xhdRate() {
    $.ajax({
        url: "nhywjtxhdglAction!xhdRate.do",
        type: "post",
        dataType: "JSON",
        data: {},
        success: function (res) {
            if (res) {
                //console.log(res);
                // 信号灯在线率
                $("#xhdOnline").text(res.online);
                $("#xhdUnOnline").text(res.unonline);
                var data = [{
                    value: res.online,
                    name: '在线'
                }, {
                    value: res.unonline,
                    name: '不在线'
                }];
                EchartsBase.circularGraphChart({
                    id: "xhdzxl",
                    data: data
                });
            } else {
                EchartsBase.circularGraphChart({
                    id: "xhdzxl",
                    data: [{
                        value: 0,
                        name: '在线'
                    }, {
                        value: 0,
                        name: '不在线'
                    }]
                });

            }
        },
        error: function (res) {

        }
    })
}


function ydpRate() {
    $.ajax({
        url: "nhywjtledydpglAction!statisticsYDPOnlineRate.do",
        type: "post",
        dataType: "JSON",
        data: {},
        success: function (res) {
            if (res) {
                $("#ydpOnline").text(res.ydponlinenum);
                $("#ydpUnOnline").text(res.ydpunonlinenum);
                var data = [{
                    value: res.ydponlinenum,
                    name: '在线'
                }, {
                    value: res.ydpunonlinenum,
                    name: '不在线'
                }];
                EchartsBase.circularGraphChart({
                    id: "ydpzxl",
                    data: data
                });
            } else {
                EchartsBase.circularGraphChart({
                    id: "ydpzxl",
                    data: [{
                        value: 0,
                        name: '在线'
                    }, {
                        value: 0,
                        name: '不在线'
                    }]
                });

            }
        },
        error: function (res) {

        }
    })
}

function showVideoDetail(deviceType, type) {
    windowid = top.$.createWin({
        title: '详情',
        width: '720',
        height: '400',
        data: {deviceType: deviceType, type: type},
        url: sysUrl + "/yw/homepage/showVideoDetail.jsp",

    });
}

function showMachineDetail(deviceType, type) {
    windowid = top.$.createWin({
        title: '详情',
        width: '720',
        height: '400',
        data: {deviceType: deviceType, type: type},
        url: sysUrl + "/yw/homepage/showMachineDetail.jsp",

    });
}

function showXHDDetail(deviceType, type) {
    windowid = top.$.createWin({
        title: '详情',
        width: '720',
        height: '400',
        data: {deviceType: deviceType, type: type},
        url: sysUrl + "/yw/homepage/showXHDDetail.jsp",

    });

}

function showYDPDetail(deviceType, type) {
    windowid = top.$.createWin({
        title: '详情',
        width: '720',
        height: '400',
        data: {deviceType: deviceType, type: type},
        url: sysUrl + "/yw/homepage/showYDPDetail.jsp",

    });

}