wr1207
2023-10-17 e4b02462b2718be6ae677385ca90328e45a61a4d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
var current_selected_monitor_type = 1001;
var current_selected_monitor_name = "国控点";
var current_selected_monitor_qindex = "pm25";
 
var tmpTopListQueryResult;
 
//对应widget.js中MyWidget实例化后的对象
var thisWidget
 
//当前页面业务
function initWidgetView(_thisWidget) {
    thisWidget = _thisWidget
 
    loadCountByUserid();
    // loadCountByUserid_taxi();
 
    $(".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();
        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()
    }, 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;
            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) {
            console.log(request);
            console.log(textStatus);
            haoutil.msg("系统后台错误,请联系管理员处理!");
        }
    });
    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) {
            console.log(request);
            console.log(textStatus);
            haoutil.msg("系统后台错误,请联系管理员处理!");
        }
    });
 
    $("#qindex_selection").change(function () {
        current_selected_monitor_qindex = $("#qindex_selection").val();
        reloadData();
    });
 
}
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);
    } 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() {
    $("#top10Tb").empty();
    var backend_url = thisWidget.nodejs_url_predix + "dataapi/Bdata?bid=get_" + current_selected_monitor_type + "_list&datatype=" + thisWidget.datatype 
        + "&datatime=" + thisWidget.datatime+ "&userid=" + thisWidget.userid + "&qindex=" + current_selected_monitor_qindex 
        + "&pageno=1&pagesize=" + default_system_params.summary_topN_count;
    //加入cntId
    $.ajax({
        type: 'get',
        dataType: 'json',
        //crossDomain: true,
        data: {},
        async: true,//同步
        url: backend_url,
        success: function (data) {
            tmpTopListQueryResult = data.data.result;;
            if (tmpTopListQueryResult != null && tmpTopListQueryResult.length > 0) {
                for (var i = 0; length = tmpTopListQueryResult.length, i < length; i++) {
                    var j = i + 1;
                    var topObj = tmpTopListQueryResult[i];
                    topObj = changeNullAndundefinedToEmpty(topObj);
                    var _tr = "<tr _siteid='" + topObj.code + "' _lon='" + topObj.lon + "' _lat='" + topObj.lat + "' onmouseover='over(this)' onmouseout='out(this)' ><td><input 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>"
                    $("#top10Tb").append(_tr);
                }
            } else {
                haoutil.msg("查询无数据,请更换查询条件!");
            }
 
        },
        error: function (request, textStatus) {
            console.log(request);
            console.log(textStatus);
            haoutil.msg("系统后台错误,请联系管理员处理!");
        }
    });
}
 
 
function over(obj) {
    $('#top10Tb tr').removeClass("over_tr");
    $(obj).addClass("over_tr");
}
 
function out(obj) {
 
    $(obj).removeClass("over_tr");
}
 
function locateAndShowDetail(obj) {
    $('#top10Tb 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 != 'undefined') {
        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 selectedItem = [];
    for (var i = 0; i < obj.length; ++i) {
        if (obj[i].checked) {
            selectedItem[selectedItem.length] = tmpTopListQueryResult[i];
        }
    }
 
    if (selectedItem.length <= 0) {
        haoutil.msg("请勾选");
    } else {
        //console.log(selectedItem);
        thisWidget.HighlightMulti(current_selected_monitor_type, current_selected_monitor_qindex, selectedItem);
    }
}