var current_selected_monitor_type;
|
var current_selected_monitor_name;
|
var current_selected_monitor_keyword;
|
var current_selected_monitor_qindex = "pm25";
|
|
var tableData;
|
var monitor_type_changed = false;
|
|
//对应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");
|
if (current_selected_monitor_type && current_selected_monitor_type != $(this).attr("_code")) {
|
monitor_type_changed = true;
|
}
|
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&userid=" + thisWidget.userid;
|
$.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("<option value='" + element + "'>" + element + "</option>"));
|
$("#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; //每页显示个数
|
if (!monitor_type_changed && tableData) {
|
pageData(tableData, avgnam, page)
|
monitor_type_changed = false;
|
} else {
|
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;
|
}
|
pageData(tableData, avgnam, page);
|
}
|
});
|
}
|
}
|
|
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);
|
}
|
}
|
|
function pageData(tableData, avgnam, page) {
|
var newsTotalNum = tableData.length; //记录的总条数
|
var pageNum = Math.ceil(newsTotalNum / avgnam); //分页的总页数
|
|
for (var i = (page - 1) * avgnam; i < Math.min(page * avgnam, newsTotalNum); i++) {
|
var j = i + 1;
|
var topObj = tableData[i];
|
topObj = changeNullAndundefinedToEmpty(topObj);
|
var content = "<tr _siteid='" + topObj.code + "' _lon='" + topObj.lon + "' _lat='" + topObj.lat + "' onmouseover='over(this)' onmouseout='out(this)' ><td><input id='items' type='checkbox' name='selectedItem' value='" + j + "' /></td><td>" + j + "</td><td onclick='locateAndShowDetail(this)'>" + topObj.code + "</td><td onclick='locateAndShowDetail(this)'>" + topObj.name + "</td><td><font color='" + getLayerPointColorByQindexandValue(current_selected_monitor_type, current_selected_monitor_qindex, topObj[current_selected_monitor_qindex]) + "'>" + topObj[current_selected_monitor_qindex] + "</font></td></tr>"
|
$("#searchInfo").append(content);
|
}
|
var content1 = '<div class="am-cf">' +
|
'共 ' + newsTotalNum + ' 条记录 / ' + pageNum + '页' +
|
'</div>';
|
var content2 = '<div class="pageDiv">' +
|
'<ul class="am-pagination">';
|
// 判断前面是否还有页面
|
if (page == 1) {
|
content2 += '<li class="am-disabled"><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" >«</a></li>';
|
} else {
|
content2 += '<li><a href="javascript:reloadData(' + (page - 1) + ')" rel="external nofollow" >«</a></li>';
|
}
|
if (pageNum <= 3) {//总页数小于五页,则加载所有页
|
for (var i = 1; i <= pageNum; i++) {
|
if (i == page) {
|
content2 += '<li class="am-active"><a href="javascript:reloadData(' + i + ')" rel="external nofollow" rel="external nofollow" >' + i + '</a></li>';
|
} else {
|
content2 += '<li><a href="javascript:reloadData(' + i + ')" rel="external nofollow" rel="external nofollow" >' + i + '</a></li>';
|
}
|
};
|
$('#page').append(content2);
|
// return;
|
} else if (pageNum > 3) {//总页数大于五页,则加载五页
|
if (page < 3) {//当前页小于3,加载1-3页
|
for (var i = 1; i <= 3; i++) {
|
if (i == page) {
|
content2 += '<li class="am-active"><a href="javascript:reloadData(' + i + ')" rel="external nofollow" rel="external nofollow" >' + i + '</a></li>';
|
|
} else {
|
content2 += '<li><a href="javascript:reloadData(' + i + ')" rel="external nofollow" rel="external nofollow" >' + i + '</a></li>';
|
}
|
};
|
if (page <= pageNum - 2) {//最后一页追加“...”代表省略的页
|
content2 += "<li><a>...</a></li>";
|
}
|
$('#page').append(content2);
|
// return;
|
} else if (page >= 3) {//当前页大于3页
|
for (var i = 1; i <= 2; i++) {//1,2页码始终显示
|
content2 += '<li><a href="javascript:reloadData(' + i + ')" rel="external nofollow" rel="external nofollow" >' + i + '</a></li>';
|
}
|
content2 += "<li><a>...</a></li>";//2页码后面用...代替部分未显示的页码
|
if (page + 1 == pageNum) {//当前页+1等于总页码
|
for (i = page - 1; i <= pageNum; i++) {//“...”后面跟三个页码当前页居中显示
|
if (i == page) {
|
content2 += '<li class="am-active"><a href="javascript:reloadData(' + i + ')" rel="external nofollow" rel="external nofollow" >' + i + '</a></li>';
|
} else {
|
content2 += '<li><a href="javascript:reloadData(' + i + ')" rel="external nofollow" rel="external nofollow" >' + i + '</a></li>';
|
}
|
}
|
} else if (page == pageNum) {//当前页数等于总页数则是最后一页页码显示在最后
|
for (var i = page - 2; i <= pageNum; i++) {//...后面跟三个页码当前页居中显示
|
if (i == page) {
|
content2 += '<li class="am-active"><a href="javascript:reloadData(' + i + ')" rel="external nofollow" rel="external nofollow" >' + i + '</a></li>';
|
} else {
|
content2 += '<li><a href="javascript:reloadData(' + i + ')" rel="external nofollow" rel="external nofollow" >' + i + '</a></li>';
|
}
|
}
|
} else {//当前页小于总页数,则最后一页后面跟...
|
for (var i = page; i <= page + 1; i++) {//dqPage+1页后面...
|
if (i == page) {
|
content2 += '<li class="am-active"><a href="javascript:reloadData(' + i + ')" rel="external nofollow" rel="external nofollow" >' + i + '</a></li>';
|
|
} else {
|
content2 += '<li><a href="javascript:reloadData(' + i + ')" rel="external nofollow" rel="external nofollow" >' + i + '</a></li>';
|
}
|
}
|
content2 += "<li><a>...</a></li>";
|
}
|
$('#page').append(content2);
|
// return;
|
}
|
}
|
// 判断后面是否还有页面
|
if (page == pageNum) {
|
content2 += '<li class="am-disabled"><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" >»</a></li>';
|
} else {
|
content2 += '<li><a href="javascript:reloadData(' + (page + 1) + ')" rel="external nofollow" >»</a></li>';
|
}
|
content2 += '</ul>' +
|
'</div>';
|
$("#pageID").empty();
|
$("#pageID").append(content1);
|
$("#page").empty();
|
$("#page").append(content2);
|
}
|