-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBusPreviewForSuzhou.js
More file actions
154 lines (134 loc) · 3.22 KB
/
BusPreviewForSuzhou.js
File metadata and controls
154 lines (134 loc) · 3.22 KB
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
/******* config ***********/
var stopID = 10003177; // 独墅湖图书馆id
var stopName = "独墅湖图书馆";
var lineID = "10000522";
var busName = "110(南线)";
var url = "http://app.2500.tv/bus1/api_line_status_a.php";
var result = "未知";
var current = 200;
/******* UI ***********/
var templateCell = {
props: {
bgcolor: $color("clear")
},
views: [{
type: "label",
props: {
id: "stopNameLabel",
align: $align.center,
font: $font(20)
},
layout: function(make, view) {
make.left.inset(20)
make.centerY.equalTo(0);
}
},
{
type: "label",
props: {
id: "busNoLabel",
textColor: $color("#3399ff"),
align: $align.center,
font: $font(15)
},
layout: function(make, view) {
make.right.inset(10)
make.centerY.equalTo(0);
},
}]
}
var listView = {
type: "list",
props: {
id: 'listView',
template: templateCell,
data: []
},
layout:function(make, view) {
make.left.right.bottom.inset(0)
make.top.equalTo(80)
},
}
var topView = {
type: "label",
props: {
id:'topLabel',
textColor: $color("#3399ff"),
text: "正在请求....",
autoFontSize: true,
align: $align.center,
lines: 0,
},
layout: function(make, view) {
make.top.left.right.inset(0);
make.height.equalTo(80);
},
}
$ui.render({
views: [
topView,
listView
]
})
/******* Network ***********/
$http.post({
url: url,
form: {
lineID: lineID
},
handler: function (resp) {
handleBusResponse(resp);
}
});
// 处理接口数据
function handleBusResponse(resp) {
var data = resp.data.data;
var busArray = [];
if (resp.data.status == 1) {
for (var i in data) {
var busStop = data[i];
if (busStop.ID == stopID) { // 遍历到目的站点
if (current == 200) {
result = "在" + stopName + "之前没有" + busName + "运行";
} else if (busStop.BusInfo.length == 0) {
result = i - current == 0 ? busName + "刚刚到达" + stopName : busName + "还有" + (i - current) + "站路到达" + stopName
} else {
var next = "\n下一班还有" + (i - current) + "站路到达"
result = busStop.BusInfo + "于" + busStop.InTime + "到达" + stopName + next;
}
busArray.push(busStop);
break;
} else {// 未遍历到目的站点
if (busStop.BusInfo.length > 0) { // 有车
current = i;
busArray = [];
busArray = [busStop];
} else { // 没有车
busArray.push(busStop);
}
}
}
// $ui.alert(result);
/** 更新UI **/
var label = $("topLabel");
label.text = result;
var dataArray = [];
for(var i in busArray){
var busStop = busArray[i];
var j = i + 1.0;
var obj = {
stopNameLabel: {
text: (parseInt(i)+1) + busStop.StationCName
},
busNoLabel:{
text: busStop.BusInfo.length > 0 ? busStop.BusInfo + " " + busStop.InTime : ""
}
}
dataArray.push(obj);
}
var list = $("listView");
list.data = dataArray;
} else {
$ui.alert("错误");
}
}