var current_selected_monitor_type; var current_selected_monitor_name; var current_selected_monitor_keyword; var current_selected_monitor_qindex = "pm25"; var tableData; //对应widget.js中MyWidget实例化后的对象 var thisWidget //当前页面业务 function initWidgetView(_thisWidget) { thisWidget = _thisWidget loadCountByUserid(); $(".cnt_div a").on("click", function () { $(".cnt_div a").removeClass("select_btn"); $(this).addClass("select_btn"); current_selected_monitor_type = $(this).attr("_code"); current_selected_monitor_name = $(this).attr("_name"); changeQindexSelection(); }); //开始查询数据 $("#btn").click(function () { current_selected_monitor_keyword = $('#search').val(); throttling(); }); //绑定enter回车键事件 $('#search').bind('keypress', function (event) { if (event.keyCode == "13") { current_selected_monitor_keyword = $('#search').val(); throttling(); } }) $("#selectedALL").click(function() { if (this.checked){ $("input[name='selectedItem']:checkbox").each(function(){ $(this).prop("checked", true); }); } else { $("input[name='selectedItem']:checkbox").each(function() { $(this).prop("checked", false); }); } }); } // 节流,防止用户点击多次请求多次 let timeout; //需要定义在方法外 function throttling(){ //先清理 clearTimeout(timeout) timeout = setTimeout(() => { reloadData(1) }, 500) } //加载count function loadCountByUserid() { var backend_url = thisWidget.nodejs_url_predix + "dataapi/Bdata?bid=get_all_count_by_id&userid=" + thisWidget.userid; $.ajax({ type: 'get', dataType: 'json', data: {}, async: true,//同步 url: backend_url, success: function (data) { var cntGroup = data.data.result; console.log(cntGroup) if (cntGroup != null) { for (var i = 0; i < cntGroup.length; i++) { var j = i + 1; var cntObj = cntGroup[i]; $("#count" + j).text(cntObj.count); $("#countName" + j).text(cntObj.name); $("#href" + j).attr("_code", cntObj.code); $("#href" + j).attr("_name", cntObj.name); } } }, error: function (request, textStatus) { } }); var backend_url_taxi = thisWidget.nodejs_url_predix + "dataapi/Bdata?bid=get_count_all&datatype=" + thisWidget.datatype + "&datatime="+ thisWidget.datatime; $.ajax({ type: 'get', dataType: 'json', data: {}, async: true,//同步 url : backend_url_taxi, success: function (data) { var cntGroup = data.data.result; if (cntGroup != null) { for(var i=0;i < cntGroup.length;i++){ var cntobj = cntGroup[i] $("#count_all").text(cntobj.count_all); $("#count_bus").text(cntobj.count_bus); $("#count_taxi").text(cntobj.count_taxi); $("#countName").text(cntobj.name); $("#href4").attr("_code", cntobj.code); $("#href4").attr("_name", cntobj.name); } } }, error: function (request, textStatus) { haoutil.msg("系统后台错误,请联系管理员处理!"); } }); } $("#qindex_selection").change(function () { current_selected_monitor_qindex = $("#qindex_selection").val(); reloadData(1); }); function changeQindexSelection() { current_selected_monitor_qindex = "pm25"; // 重设qindex $("#qindex_selection").empty(); var options = []; if (current_selected_monitor_type == 1001) { options = Object.keys(qindex_range_list_1001); console.log(options) } else if (current_selected_monitor_type == 1002) { options = Object.keys(qindex_range_list_1002); } else if (current_selected_monitor_type == 1003) { options = Object.keys(qindex_range_list_1003); current_selected_monitor_qindex = "tsp"; } else { options = Object.keys(qindex_range_list_1004_and_other); } options.forEach(element => $("#qindex_selection").append("")); $("#qindex_selection").find("option[value=pm25]").text("PM₂.₅"); $("#qindex_selection").find("option[value=pm10]").text("PM₁₀"); $("#qindex_selection").find("option[value=no]").text("NO"); $("#qindex_selection").find("option[value=nox]").text("NOₓ"); $("#qindex_selection").find("option[value=no2]").text("NO₂"); $("#qindex_selection").find("option[value=co]").text("CO"); $("#qindex_selection").find("option[value=so2]").text("SO₂"); $("#qindex_selection").find("option[value=o3]").text("O₃"); $("#qindex_selection").find("option[value=o31]").text("O₃₁"); $("#qindex_selection").find("option[value=o38]").text("O₃₈"); $("#qindex_selection").find("option[value=aqi]").text("AQI"); $("#qindex_selection").find("option[value=tsp]").text("TSP"); } function reloadData(page){ $("#searchInfo").empty(); var avgnam = 30; //每页显示个数 var backend_url = thisWidget.nodejs_url_predix + "dataapi/Bdata?bid=get_" + current_selected_monitor_type + "_list_keyword&datatype=" + thisWidget.datatype + "&datatime=" + thisWidget.datatime +"&userid=" + thisWidget.userid+ "&qindex=" + current_selected_monitor_qindex +"&keyword=" + current_selected_monitor_keyword + "&pageno="+page+"&pagesize="+avgnam; $.ajax({ type:"GET", url:backend_url, dataType:"json", success:function(data){ tableData = data.data.result; if(current_selected_monitor_keyword == null){ haoutil.msg("请输入关键字!!!") return; } if(tableData == null){ haoutil.msg("请选择查询类别!!!") return; } if(tableData.length == 0){ haoutil.msg("无查询结果,请更换查询条件!") return; } var newsTotalNum = data.data.counter.counter; //记录的总条数 var pageNum = Math.ceil(newsTotalNum/avgnam); //分页的总页数 for(var i=0;i" + j + "" + topObj.code + "" + topObj.name + "" + topObj[current_selected_monitor_qindex] + "" $("#searchInfo").append(content); } var content1 = '
' + '共 '+newsTotalNum+' 条记录 / '+pageNum+'页' + '
'; var content2 = '
' + '' + '
'; $("#pageID").empty(); $("#pageID").append(content1); $("#page").empty(); $("#page").append(content2); } }); } function over(obj) { $('#searchInfo tr').removeClass("over_tr"); $(obj).addClass("over_tr"); } function out(obj) { $(obj).removeClass("over_tr"); } function locateAndShowDetail(obj) { $('#searchInfo tr').removeClass("select_tr"); let parentObj = $(obj).parent(); $(parentObj).addClass("select_tr"); var siteId = $(parentObj).attr("_siteid"); var lon = $(parentObj).attr("_lon"); var lat = $(parentObj).attr("_lat"); if (lon && lon != '/') { thisWidget.locateAndHighlight(lon, lat); } if (current_selected_monitor_type != 100500) { thisWidget.showDetailedWindow({ "nodejs_url_predix": thisWidget.nodejs_url_predix, "datatype": thisWidget.datatype, "selected_qindex": current_selected_monitor_qindex, "datatime": thisWidget.datatime, "layerid": current_selected_monitor_type, "siteid": siteId }); } } function setTopNname(count) { $("#topN_name").html("Top" + count); } function highlightSelected() { var obj = document.getElementsByName('selectedItem'); //选择所有name="'selectedItem'"的对象,返回数组 // var first_value = document.getElementById('items').value; //选择所有value="'值' var selectedItem = []; for (var i = 0; i < obj.length; ++i) { if (obj[i].checked) { // selectedItem[selectedItem.length] = tableData[i+(first_value-1)]; selectedItem[selectedItem.length] = tableData[i]; } } if (selectedItem.length <= 0) { haoutil.msg("请勾选"); } else { //console.log(selectedItem); thisWidget.HighlightMulti(current_selected_monitor_type, current_selected_monitor_qindex, selectedItem); } }