<%@ page import="org.apache.commons.lang.StringUtils" %>
<%@ page language="java" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" %>
<%@ page isELIgnored="false" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
    <%
    String basePath = request.getContextPath();
%>
<!DOCTYPE html>
<html>
<head>
    <jsp:include page="../../../common/admin/head.jsp"></jsp:include>
    <link  rel="stylesheet" type="text/css" href="<%=basePath%>/resource/css/admin/home/index.css">

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <style type="text/css">
        body, html {width: 100%;height: 100%;margin:0;font-family:"微软雅黑";}
        #allmap{width:100%;height:500px;}
    </style>
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=RleRpI1DQegNo17XGsVvUUS1e3oiubUG"></script>

</head>
<body>
<jsp:include page="../../../common/admin/body_pre.jsp"></jsp:include>
<div class="row hidden-print">
    <div class="col-lg-12">
        <div class="ibox">
            <div class="ibox-title">
                <h2>城市运行监测预警</h2>
                <ol class="breadcrumb">
                    <li>
                        <a href="javascript:void(0);" >公共安全</a>
                    </li>
                    <li class="active">
                        <strong>生产安全</strong>
                    </li>
                </ol>
            </div>
        </div>
    </div>
</div>
<%--////////////////--%>
<div class="row hidden-print">
    <div class="col-lg-3 col-md-3">
        <div class="ibox shortcut">
            <div id="divChart1" style="width: 100%;height: 400px;"></div>
        </div>
    </div>
    <div class="col-lg-3 col-md-3">
        <div class="ibox shortcut">
            <div id="divChart2" style="width: 100%;height: 400px;"></div>
        </div>
    </div>
    <div class="col-lg-3 col-md-3">
        <div class="ibox shortcut">
            <div id="divChart3" style="width: 100%;height: 400px;"></div>
        </div>
    </div>
    <div class="col-lg-3 col-md-3">
        <div class="ibox shortcut">
            <div id="divChart4" style="width: 100%;height: 400px;"></div>
        </div>
    </div>
</div>
<div class="row hidden-print">
    <div style="position: absolute;z-index: 999; font-weight: bold;font-size: 20px;background: #fff;left:26px">工伤事故分布</div>
    <div class="col-lg-12 col-md-12">
        <div class="ibox shortcut">
            <div id="divChart5" style="width: 100%;height: 400px;"></div>
        </div>
    </div>
</div>
<jsp:include page="../../../common/admin/body_post.jsp"></jsp:include>
</body>
<script type="text/javascript">
    var myChart1 = echarts.init(document.getElementById('divChart1'));
    option = {
        title : {
            text: '万人工伤事故死亡率',
            subtext:''
        },
        tooltip: {},
        xAxis: {
            type: 'category',
            data: []
        },
        yAxis: {
            type: 'value',
            axisLabel: {
                formatter: '{value} %'
            }
        },
        series: [{
            data: [],
            type: 'line'
        }]
    };
    myChart1.setOption(option);
    var fnMyChart1=function() {
        $.get('<%=basePath%>/admin/produceSecurity/accidentdeath.action', function (result) {
            myChart1.setOption({
                title:{
                    subtext: "最新工伤事故死亡率:"+result.data.deathAmount[result.data.deathAmount.length-1]+"%  同比数据值:"+result.data.newGrowth+"%"
                },
                xAxis: {
                    data: result.data.years
                },
                series: [{
                    // 根据名字对应到相应的系列
                    data: result.data.deathAmount
                }]
            });
        })
    }
    fnMyChart1();
    /*//////////////////////////////////*/
    var myChart2 = echarts.init(document.getElementById('divChart2'));
    option = {
        title : {
            text: '区域工伤事故占比',
            subtext:''
        },
        tooltip: {
            trigger: 'item',
            formatter: "{a} <br/>{b}: {c} ({d}%)"
        },
        legend: {
            orient: 'vertical',
            x: 'right',
            data:[]
        },
        series: [
            {
                name:'区域工伤事故占比',
                type:'pie',
                radius: ['50%', '70%'],
                avoidLabelOverlap: false,
                label: {
                    normal: {
                        show: false,
                        position: 'center'
                    },
                    emphasis: {
                        show: true,
                        textStyle: {
                            fontSize: '30',
                            fontWeight: 'bold'
                        }
                    }
                },
                labelLine: {
                    normal: {
                        show: false
                    }
                },
                data:[]
            }
        ]
    };
    myChart2.setOption(option);
    var fnMyChart2=function() {
        $.get('<%=basePath%>/admin/produceSecurity/accidentproportion.action', function (result) {
            myChart2.setOption({
                title:{
                    subtext: "最新总事故数:"+result.data.total +"起"
                },
                legend: {
                    data:result.data.names
                },
                series: [{
                    // 根据名字对应到相应的系列
                    data: result.data.list
                }]
            });
        })
    }
    fnMyChart2();
    /*///////////////////////////////////*/
    var myChart3 = echarts.init(document.getElementById('divChart3'));
    option = {
        title: {
            text: '工伤事故类别排名',
        },
        tooltip: {
            trigger: 'axis',
            axisPointer: {
                type: 'shadow'
            }
        },
        grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
        },
        xAxis: {
            type: 'value',
            boundaryGap: [0, 0.01]
        },
        yAxis: {
            type: 'category',
            data: []
        },
        series: [
            {
                type: 'bar',
                data: []
            }
        ]
    };
    myChart3.setOption(option);
    var fnMyChart3=function() {
        $.get('<%=basePath%>/admin/produceSecurity/industrialaccidentranking.action', function (result) {
            myChart3.setOption({
                yAxis: {
                    data: result.data.names
                },
                series: [{
                    // 根据名字对应到相应的系列
                    data: result.data.amount
                }]
            });
        })
    }
    fnMyChart3();
    /*///////////////////////////////////*/
    var myChart4 = echarts.init(document.getElementById('divChart4'));
    var colors = ['#5793f3', '#d14a61', '#675bba'];
    option = {
        title: {
            text: '工伤事故发展趋势',
        },
        tooltip : {
            trigger: 'axis',
            axisPointer : {            // 坐标轴指示器，坐标轴触发有效
                type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
            }
        },
        legend: {
            orient:'horizontal',
            left: 'right',
            itemWidth:5,
            itemHeight:5,
            top:23,
            data: ['受伤人数(人)', '死亡人数(人)','万人工伤死亡率(%)']
        },
        grid: {
            left:'15%',
            top:'20%'
    },
        xAxis:  {
            type: 'category',
            data: []

        },
        yAxis: [
            {
                type: 'value',
                name: '受伤人数(人)',
                min: 0,
                max: 250,
                position: 'left',
                axisLine: {
                    lineStyle: {
                        color: colors[1]
                    }
                }
            },
            {
                type: 'value',
                name: '死亡人数(人)',
                min: 0,
                max: 250,
                position: 'right',
                offset: 0,
                axisLine: {
                    lineStyle: {
                        color: colors[0]
                    }
                }
            },
            {
                type: 'value',
                name: '万人工伤死亡率',
                show:false,
                min: 0,
                max: 25,
                position: 'left',
                axisLine: {
                    lineStyle: {
                        color: colors[2]
                    }
                },
                axisLabel: {
                    formatter: '{value} %'
                }
            }
        ],

        series: [
            {
                name: '受伤人数(人)',
                type: 'bar',
                stack: '总量',
                label: {
                    normal: {
                        show: true,
                        position: 'insideRight'
                    }
                },
                data: []
            },
            {
                name: '死亡人数(人)',
                type: 'bar',
                stack: '总量',
                label: {
                    normal: {
                        show: true,
                        position: 'insideRight'
                    }
                },
                data: []
            },
            {
                name:'万人工伤死亡率(%)',
                type:'line',
                yAxisIndex: 2,
                data:[]
            }
        ]
    };
    myChart4.setOption(option);
    var fnMyChart4=function() {
        $.get('<%=basePath%>/admin/produceSecurity/industrialaccidenttendency.action', function (result) {
            myChart4.setOption({
                xAxis: {
                    data: result.data.years
                },
                series: [
                    // 根据名字对应到相应的系列
                    {data: result.data.hurtAmount},
                    {data: result.data.deathAmount},
                    {data: result.data.proportionAmount}
                ]
            });
        })
    }
    fnMyChart4();
    /*///////////////////////////////////*/
    var myChart5 = echarts.init(document.getElementById('divChart5'));
    var map = new BMap.Map("divChart5",{enableMapClick:false,mapType: BMAP_NORMAL_MAP});            // 创建Map实例
    map.setCurrentCity("衡水市");
    map.centerAndZoom(new BMap.Point(115.675402, 37.745191), 14);
    map.enableScrollWheelZoom();                 //启用滚轮放大缩小

    // 自定义一个控件类
    function ZoomControl(){
        // 默认停靠位置和偏移量
        this.defaultAnchor = BMAP_ANCHOR_TOP_RIGHT;
        this.defaultOffset = new BMap.Size(10, 5);
    }
    // 通过JavaScript的prototype属性继承于BMap.Control
    ZoomControl.prototype = new BMap.Control();
    // 自定义控件必须实现自己的initialize方法,并且将控件的DOM元素返回
    // 在本方法中创建个div元素作为控件的容器,并将其添加到地图容器中
    ZoomControl.prototype.initialize = function(map){
        // 创建一个DOM元素
        var div = document.createElement("div");
        // 添加文字说明
        div.innerHTML+="<a href='javascript:void(0)' style='background: yellowgreen;color: #fff' >&nbsp;轻伤事故&nbsp;</a>"+
            "<a href='javascript:void(0)' style='background: orange;color: #fff' >&nbsp;重伤事故&nbsp;</a>"+
            "<a href='javascript:void(0)' style='background: red;color: #fff' >&nbsp;死亡事故&nbsp;</a>";
        // 设置样式
        div.style.cursor = "pointer";
        div.style.border = "1px solid";
        // 添加DOM元素到地图中
        map.getContainer().appendChild(div);
        // 将DOM元素返回
        return div;
    }
    // 创建控件
    var myZoomCtrl = new ZoomControl();
    // 添加到地图当中
    map.addControl(myZoomCtrl);
    /*/////////////////////////////////////////////////////////*/
    // 编写自定义函数,创建标注
    function addMarker(point){
        var marker = new BMap.Marker(point);
        map.addOverlay(marker);
    }

    //添加信息窗口
    var opts = {
        width : 250,     // 信息窗口宽度
        height: 80,     // 信息窗口高度
        title : "详细信息" , // 信息窗口标题
    };
    //添加点击事件监听器
    function addClickHandler(content,marker){
        marker.addEventListener("click",function(e){
            openInfo(content,e)}
        );
    }
    function openInfo(content,e){
        var p = e.target;
        var infoPoint = new BMap.Point(p.getPosition().lng, p.getPosition().lat);
        var infoWindow = new BMap.InfoWindow(content,opts);  // 创建信息窗口对象
        map.openInfoWindow(infoWindow,infoPoint); //开启信息窗口
    }
    //轻伤事故
    function fnFireDegree1() {
        for (var i = 0; i < degreeArray1.length; i++) {
            var vectorMarker = new BMap.Marker(new BMap.Point(degreeArray1[i].lng,degreeArray1[i].lat),{
                // 指定Marker的icon属性为Symbol
                icon: new BMap.Symbol(BMap_Symbol_SHAPE_POINT, {
                    scale: 1,//图标缩放大小
                    fillColor: "yellowgreen",//填充颜色
                    fillOpacity: 0.8//填充透明度
                })
            });
            var content = "严重程度；"+degreeArray1[i].degree+ "<br/>详细地址："+degreeArray1[i].address;
            map.addOverlay(vectorMarker);
            addClickHandler(content,vectorMarker);
        }
        vectorMarker.show();
    }
    //重伤事故
    function fnFireDegree2() {
        for (var i = 0; i <degreeArray2.length; i++) {
            var vectorMarker = new BMap.Marker(new BMap.Point(degreeArray2[i].lng,degreeArray2[i].lat),{
                // 指定Marker的icon属性为Symbol
                icon: new BMap.Symbol(BMap_Symbol_SHAPE_POINT, {
                    scale: 1,//图标缩放大小
                    fillColor: "orange",//填充颜色
                    fillOpacity: 0.8//填充透明度
                })
            });
            var content = "严重程度；"+degreeArray2[i].degree+ "<br/>详细地址："+degreeArray2[i].address;
            map.addOverlay(vectorMarker);
            addClickHandler(content,vectorMarker);
        }
        vectorMarker.show();
    }
    //死亡事故
    function fnFireDegree3() {
        for (var i = 0; i < degreeArray3.length; i++) {
            var vectorMarker = new BMap.Marker(new BMap.Point(degreeArray3[i].lng,degreeArray3[i].lat),{
                // 指定Marker的icon属性为Symbol
                icon: new BMap.Symbol(BMap_Symbol_SHAPE_POINT, {
                    scale: 1,//图标缩放大小
                    fillColor: "red",//填充颜色
                    fillOpacity: 0.8//填充透明度
                })
            });
            var content = "严重程度；"+degreeArray3[i].degree+ "<br/>详细地址："+degreeArray3[i].address;
            map.addOverlay(vectorMarker);
            addClickHandler(content,vectorMarker);
        }
        vectorMarker.show();
    }

    $.get('<%=basePath%>/admin/produceSecurity/industriaaccidentdistribution.action',function(result){
        degreeArray1=result.data.lightDegree;
        degreeArray2=result.data.seriouseDegree;
        degreeArray3=result.data.deathDegree;
        degreeArray1.length<1?'':fnFireDegree1();
        degreeArray2.length<1?'':fnFireDegree2();
        degreeArray3.length<1?'':fnFireDegree3();
    });

</script>
</html>

