-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhospitalList.js
More file actions
441 lines (386 loc) · 10.4 KB
/
Copy pathhospitalList.js
File metadata and controls
441 lines (386 loc) · 10.4 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
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
let appInstance = getApp();
var QQMapWX = require('../../libs/qqmap-wx-jssdk.js');
//等级
let grade = '';
//定位城市
let city = ""
//存定位的标识符
let LOCATIN = "LOCATION"
//用户经纬度
let userLo = ""
let userLa = ""
var qqmapsdk;
Page({
pageNo: 1,
data: {
isShowSorry: false,
city: '正在定位',
area: "全部地区",
grade: "全部等级",
//---医院数组
array: [],
isLoadComplete: false,//是否加载完毕
isNearbyMyself: false,//是否离我最近
areas: [],//地区
isSortArea: false,
isSortGrade: false,
selectedGradeIndex: 0,
selectedAreaIndex: 0,
isFirstGetData: true,
imageurl: appInstance.data.imageUrl,
},
/**
* 根据APP.js 的城市信息判断是否应该刷新当前页面
*/
onShow: function() {
if (appInstance.data.region.city) {
if (appInstance.data.region.city != this.data.city) {
let all = ["全部地区"]
this.setData({
area: "全部地区",
grade: "全部等级",
city: appInstance.data.region.city,
areas: all.concat(appInstance.data.region.areas),
selectedAreaIndex: 0,
selectedGradeIndex: 0,
isLoadComplete: false
})
this.getHospitalList()
} else {
// this.getHospitalList()
}
}
},
bindGetUserInfo: function(e) {
//console.log(e)
},
onLoad: function(options) {
let that = this;
wx.onNetworkStatusChange(function(res) {
if (res.isConnected) {
wx.hideLoading()
that.getHospitalList()
}
})
var _this = this
wx.getSystemInfo({
success: function(res) {
var height = res.windowHeight * 750 / res.windowWidth
_this.setData({
windowHeight: height
})
}
})
//需要登录
this.getposition()
},
/**
* 获取各个城市各个区的编码号
* 1. 定位
* 2. 反编译经纬度城市信息
* 3. 后端接口返回数据
*/
getposition() {
let that = this;
// 实例化API核心类
qqmapsdk = new QQMapWX({
key: 'MPKBZ-MYNCF-JVKJA-J73A4-OM74V-N2BOZ'
});
wx.getLocation({
type: 'wgs84',
success: function(res) {
let userLocation = {
latitude: res.latitude,
longitude: res.longitude,
}
userLa = res.latitude
userLo = res.longitude
wx.setStorageSync(LOCATIN, userLocation)
//---定位成功获取医院列表
qqmapsdk.reverseGeocoder({
location: {
latitude: res.latitude,
longitude: res.longitude,
},
success: function(results) {
// ("腾讯地图反编码成功")
var province = results.result.address_component.province;
var city = results.result.address_component.city;
wx.setStorageSync('LOCATIONCITY', city);
appInstance.getServerce(appInstance.data.url + '/current-city/', "POST", {
"cityName": city
}, (isSuccess, json) => {
if (isSuccess) {
//定位城市存在
//存地区
//存下地区列表和城市
let allArea = ["全部地区"]
that.setData({
city: city,
areas: allArea.concat(json.data.areas)
})
let region = appInstance.data.region
region.city = city
region.areas = json.data.areas
that.getHospitalList();
} else {
//定位城市未开通 选择城市
// let _this = this
wx.showModal({
title: '',
content: "定位城市暂未开通,请选择城市",
showCancel: false,
success: function(res) {
if (res.confirm) {
wx.navigateTo({
url: '../chooseCity/chooseCity?lookCity=' + that.data.city,
})
} else if (res.cancel) {}
}
})
}
})
},
fail: function(results) {
// 腾讯地图反编码错误
if (results.status == 1000) {
wx.showModal({
title: '',
content: '好像没网了呀',
showCancel: false,
})
}
},
complete: function(results) {}
});
},
fail: function(err) {
//console.log(err)
//获取定位失败
if (err.errMsg == "getLocation:fail auth deny") {
wx.navigateTo({
url: '../chooseCity/chooseCity?lookCity=' + "定位失败",
})
} else {
wx.showModal({
title: '',
content: '定位失败,请选择城市',
showCancel: false,
success: function(res) {
wx.navigateTo({
url: '../chooseCity/chooseCity?lookCity=' + "定位失败",
})
}
})
}
},
complete: function() {
// complete
}
})
},
onReady: function() {
// 页面渲染完成
},
getHospitalList() {
wx.showNavigationBarLoading()
//为了判断是否显示抱歉,未找到医院
this.pageNo = 1
let url = appInstance.data.url + '/search/hospital/'
let params = {
"pageSize": 20,
"pageNo": this.pageNo,
"grade": this.data.grade == "全部等级" ? "" : this.data.grade,
"city": this.data.city == "定位失败" || this.data.city == "正在定位" ? "杭州市" : this.data.city,
"district": this.data.area == "全部地区" ? "" : this.data.area,
"searchCondition": "",
"longitude": userLo,
"latitude": userLa,
"isDistance": this.data.isNearbyMyself
}
let hospitalAry = []
wx.showLoading({
title: '加载中',
mask: true,
})
this.setData({
array: [],
isShowSorry: false,
})
appInstance.getServerce(url, "GET", params, (isSuccess, data) => {
wx.hideLoading()
wx.hideNavigationBarLoading()
if (isSuccess) {
let results = data.data.resultList
if (results.length == 0 && this.data.isFirstGetData == false) {
this.setData({
array: [],
isShowSorry: true
})
}
for (let m = 0; m < results.length; m++) {
let bean = results[m];
/**
* 处理占位图
*/
if (bean.icon_pic) {
//图片存在 不处理
} else {
bean.icon_pic = this.data.imageUrl + 'icon_ty_yy@2x.png'
}
if (bean.canAddition == true) {
bean.hospitalTags2 = ["可加项"]
}
hospitalAry.push(bean);
}
this.setData({
array: hospitalAry,
isFirstGetData: false
})
} else {
appInstance.showloadingMessgage(data)
}
});
},
loadMoreHospitalList() {
//为了判断是否显示抱歉,未找到医院
let url = appInstance.data.url + '/search/hospital/'
let params = {
"pageSize": 20,
"pageNo": this.pageNo,
"grade": this.data.grade == "全部等级" ? "" : this.data.grade,
"city": this.data.city == "定位失败" || this.data.city == "正在定位" ? "杭州市" : this.data.city,
"district": this.data.area == "全部地区" ? "" : this.data.area,
"searchCondition": "",
"longitude": userLo,
"latitude": userLa,
"isDistance": this.data.isNearbyMyself
}
let hospitalAry = []
wx.showLoading({
title: '加载中',
mask: true,
})
appInstance.getServerce(url, "GET", params, (isSuccess, data) => {
wx.hideLoading()
if (isSuccess) {
let results = data.data.resultList
if (results.length == 0) {
this.setData({
isLoadComplete: true
})
} else {
let data = this.data.array.concat(results)
this.setData({
array: data
})
}
} else {
wx.showModal({
title: '',
content: data,
showCancel: false,
})
}
});
},
cancle: function() {
this.setData({
isshowView: true,
});
},
//条目点击事件
pushToHospitalList: function(event) {
let itemDetail = event.currentTarget.dataset.item;
wx.navigateTo({
url: '../meals/meals?hid=' + itemDetail.id
})
},
onShareAppMessage: function() {
return {
title: '一键康医院列表',
path: '/pages/hospitalList/hospitalList'
}
},
//跳转搜索页面
gotoSearchPage: function() {
wx.navigateTo({
url: '../searchPageTow/searchPageTow',
})
},
/**选择城市信息 */
chooseCity: function() {
wx.navigateTo({
url: '../chooseCity/chooseCity?lookCity=' + this.data.city,
})
},
scrollToBottom: function(e) {
if (this.data.isLoadComplete == true) {
//console.log("加载完成")
} else {
this.pageNo = this.pageNo + 1
this.loadMoreHospitalList()
}
},
/**
* 全部等级点击事件
*/
sortGradeClick: function() {
this.setData({
isSortGrade: !this.data.isSortGrade,
isSortArea: false
})
},
/**
* 全部地区点击事件
*/
sortAreaClick: function() {
this.setData({
isSortGrade: false,
isSortArea: !this.data.isSortArea
})
},
/**
* 离我最近点击方法
*/
neaderByClick: function() {
this.setData({
isNearbyMyself: !this.data.isNearbyMyself,
isSortGrade: false,
isSortArea: false
})
this.getHospitalList()
},
/**
* 地区cell点击方法
*/
sortAreaCellDidClck: function(e) {
this.setData({
selectedAreaIndex: e.currentTarget.dataset.index,
isSortArea: false,
area: e.currentTarget.dataset.area
})
this.getHospitalList()
},
cancelSortArea: function() {
this.setData({
isSortArea: false,
})
},
/**
* 等级筛选
*/
sortGradeCellDidClck: function(e) {
this.setData({
selectedGradeIndex: e.currentTarget.dataset.index,
isSortGrade: false,
grade: e.currentTarget.dataset.grade
})
this.getHospitalList()
},
cancelSortGrade: function() {
this.setData({
isSortGrade: false,
})
},
})