<%@ page import="com.lightinit.hsdatashow.model.admin.DicFacilitiesType" %>
<%@ page import="com.lightinit.hsdatashow.dictionary.DicPublishType" %>
<%@ 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">
    <style type="text/css">
        #allmap {width: 100%;height: 100%;overflow: hidden;margin:0;font-family:"微软雅黑";}
    </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>
    <jsp:include page="../../../common/admin/search_pre.jsp"></jsp:include>

    <form id="formSearch" action="<%=basePath%>/admin/data_register_api/list.action" method="get" class="form-inline">
        <div class="form-group">
            <label for="searchName">公共设施名称</label>
            <input type="text" id="searchName" name="searchName" class="form-control" />
        </div>
        <div class="form-group">
            <button id="btnSearch" type="button" class="btn btn-sm btn-primary"><i class="fa fa-search"></i>查询</button>
        </div>
    </form>

    <jsp:include page="../../../common/admin/search_post.jsp"></jsp:include>
    <div class="row hidden-print">
            <div class="col-lg-12 col-md-12">
                <div class="col-lg-11 col-md-11 ibox-content-noline">
            <div id="allmap" style="width: 100%;height: 655px;"></div>
            <input type="hidden" value=0 id="isFalg">
            </div>
                <div class="col-lg-1 col-md-1 ibox-content-noline">
                    <div style="height: 655px">
                    <div class="col-lg-12 col-md-12">
                        <a title="<%=DicPublishType.PARK%>" onclick="changeByFalg('<%=DicPublishType.PARK%>')">
                            <img id="gy" src="<%=basePath%>/resource/images/publish/gy.png">
                            <img id="nogy" src="<%=basePath%>/resource/images/publish/no_gy.png" style="display: none">
                        </a>
                    </div>
                    <div class="col-lg-12 col-md-12">
                        <a title="<%=DicPublishType.SQUARE%>" onclick="changeByFalg('<%=DicPublishType.SQUARE%>')">
                            <img id="gc" src="<%=basePath%>/resource/images/publish/gc.png">
                            <img id="nogc" src="<%=basePath%>/resource/images/publish/no_gc.png" style="display: none">
                        </a>
                    </div>
                    <div class="col-lg-12 col-md-12">
                        <a title="" onclick="changeByFalg('<%=DicPublishType.PUBLISHWC%>')">
                            <img id="wc" src="<%=basePath%>/resource/images/publish/ggcs.png">
                            <img id="nowc" src="<%=basePath%>/resource/images/publish/no_ggcs.png" style="display: none">
                        </a>
                    </div>
                    </div>
                </div>
            </div>
        <div class="col-lg-12 col-md-12 ">
            <div class="col-lg-12 col-md-12 ibox-content-noline">
                <div style="width: 100%;height: 220px;">
                    <table  class="table table-condensed table-hover">
                        <thead>
                        <tr>
                            <th>
                                公共设施
                            </th>
                            <th>
                                数量
                            </th>
                        </tr>
                        </thead>
                        <tbody id="tableList">
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
    <jsp:include page="../../../common/admin/body_post.jsp"></jsp:include>
    <script type="text/javascript">
        var falg1 = 0;
        var falg2 = 0;
        var falg3 = 0;

        function changeByFalg(name){
            if (name=='<%=DicPublishType.PARK%>'){
                if (falg1==0){
                    falg1=1 ;
                    $("#gy").hide() ;
                    $("#nogy").show() ;
                }else {
                    falg1=0 ;
                    $("#gy").show() ;
                    $("#nogy").hide() ;
                }
            }
            if (name=='<%=DicPublishType.SQUARE%>'){
                if (falg2==0){
                    falg2=1 ;
                    $("#gc").hide() ;
                    $("#nogc").show() ;
                }else {
                    falg2=0 ;
                    $("#gc").show() ;
                    $("#nogc").hide() ;
                }
            }
            if (name=='<%=DicPublishType.PUBLISHWC%>'){
                if (falg3==0){
                    falg3=1 ;
                    $("#wc").hide() ;
                    $("#nowc").show() ;
                }else {
                    falg3=0 ;
                    $("#wc").show() ;
                    $("#nowc").hide() ;
                }
            }
            changeByName();
        }
        changeByName()
        function changeByName() {
            var count1 = 0 ;
            var count2= 0 ;
            var count3 = 0 ;
            // 百度地图API功能
            var map = new BMap.Map("allmap");
            $.ajax({
                url: "<%=basePath%>/resource/json/mapStyle.json",
                dataType: "json",
                success: function (data) {
                    map.setMapStyle({
                        styleJson: data
                    });
                }
            })
            var point = new BMap.Point(115.675402, 37.745191);
            map.centerAndZoom(point, 15);

            $.post("<%=basePath%>/admin/facilities/getPublish.action", {
                categoryName: '<%=DicFacilitiesType.PUBLISH%>',
                name:$("#searchName").val()
            }, function (datas) {
                $("#tableList").empty() ;
                if (datas.length > 0) {
                    for (var i = 0; i < datas.length; i++) {
                        (function (x) {
                            if (datas[i].orgType == '<%=DicPublishType.PARK%>'&&falg1==0) {
                                count1++ ;
                                var fax= datas[i].fax==null?'暂无':datas[i].fax ;
                                var sContent =
                                    "<h4 style='margin:0 0 5px 0;padding:0.2em 0'>管理单位：" + datas[i].shortName + "</h4>" +
                                    "<p style='margin:0;line-height:1.5;font-size:13px;text-indent:2em'>名称：" + datas[i].orgName + "</p>" +
                                    "<p style='margin:0;line-height:1.5;font-size:13px;text-indent:2em'>地址：" + fax + "</p>" +
                                    "</div>";
                                var pt = new BMap.Point(datas[i].longitude, datas[i].latitude);
                                var myIcon = new BMap.Icon("<%=basePath%>/resource/images/publish/gy.png", new BMap.Size(40, 40));
                                var marker = new BMap.Marker(pt, {icon: myIcon});  // 创建标注
                                var infoWindow = new BMap.InfoWindow(sContent);
                                map.centerAndZoom(point, 15);
                                marker.addEventListener("click", function () {
                                    this.openInfoWindow(infoWindow);
                                });
                                map.addOverlay(marker);
                            }
                            if (datas[i].orgType == '<%=DicPublishType.SQUARE%>'&&falg2==0) {
                                count2++ ;
                                var fax= datas[i].fax==null?'暂无':datas[i].fax ;
                                var sContent =
                                    "<h4 style='margin:0 0 5px 0;padding:0.2em 0'>管理单位：" + datas[i].shortName + "</h4>" +
                                    "<p style='margin:0;line-height:1.5;font-size:13px;text-indent:2em'>名称：" + datas[i].orgName + "</p>" +
                                    "<p style='margin:0;line-height:1.5;font-size:13px;text-indent:2em'>地址：" + fax + "</p>" +
                                    "</div>";
                                var pt = new BMap.Point(datas[i].longitude, datas[i].latitude);
                                var myIcon = new BMap.Icon("<%=basePath%>/resource/images/publish/gc.png", new BMap.Size(40, 40));
                                var marker = new BMap.Marker(pt, {icon: myIcon});  // 创建标注
                                var infoWindow = new BMap.InfoWindow(sContent);
                                map.centerAndZoom(point, 15);
                                marker.addEventListener("click", function () {
                                    this.openInfoWindow(infoWindow);
                                });
                                map.addOverlay(marker);
                            }
                            if (datas[i].orgType == '<%=DicPublishType.PUBLISHWC%>'&&falg3==0) {
                                count3++ ;
                                var fax= datas[i].fax==null?'暂无':datas[i].fax ;
                                var sContent =
                                    "<h4 style='margin:0 0 5px 0;padding:0.2em 0'>管理单位：" + datas[i].shortName + "</h4>" +
                                    "<p style='margin:0;line-height:1.5;font-size:13px;text-indent:2em'>名称：" + datas[i].orgName + "</p>" +
                                    "<p style='margin:0;line-height:1.5;font-size:13px;text-indent:2em'>地址：" + fax + "</p>" +
                                    "</div>";
                                var pt = new BMap.Point(datas[i].longitude, datas[i].latitude);
                                var myIcon = new BMap.Icon("<%=basePath%>/resource/images/publish/ggcs.png", new BMap.Size(40, 40));
                                var marker = new BMap.Marker(pt, {icon: myIcon});  // 创建标注
                                var infoWindow = new BMap.InfoWindow(sContent);
                                map.centerAndZoom(point, 15);
                                map.addOverlay(marker);
                                marker.addEventListener("click", function () {
                                    this.openInfoWindow(infoWindow);
                                });
                            }
                        })(i);
                    }
                }
                var html1 = '<tr>' +
                    '<th><%=DicPublishType.PARK%></th>' +
                    '<th>'+count1+'</th>' +
                    '</tr>' ;
                $("#tableList").append(html1) ;
                var html2 = '<tr>' +
                    '<th><%=DicPublishType.SQUARE%></th>' +
                    '<th>'+count2+'</th>' +
                    '</tr>' ;
                $("#tableList").append(html2) ;
                var html3= '<tr>' +
                    '<th><%=DicPublishType.PUBLISHWC%></th>' +
                    '<th>'+count3+'</th>' +
                    '</tr>' ;
                $("#tableList").append(html3) ;
            }, "json")
        }

        $("#btnSearch").click(function () {
            changeByName();
        });
    </script>
</body>
</html>