// 医生列表 // 网络请求工具类 var networkUtil = require('../../utils/network_util.js') var api = require('../../utils/apiFile.js') // 地理位置信息 var latitude = 0 var longitude = 0 // 页码 var page = 1 // 是否有更多 var hasMore = true Page({ data: { hospitalList: [ // { // "areaName": "成都", list: [{ "id": "138", "icon": "https://ss0.baidu.com/6ONWsjip0QIZ8tyhnq/it/u=2845876344,2547149135&fm=173&s=CB50DFA600825BEF16B8A43403001073&w=550&h=334&img.JPEG", "name": "犯得上发射点发司法所让我去误认为亲热万人更大", "distance": "100km" }, { // "id": "2", // "icon": "https://ss0.baidu.com/6ONWsjip0QIZ8tyhnq/it/u=2845876344,2547149135&fm=173&s=CB50DFA600825BEF16B8A43403001073&w=550&h=334&img.JPEG", "name": "name1", "distance": "100km" // }, { "id": "3", "icon": "https://ss0.baidu.com/6ONWsjip0QIZ8tyhnq/it/u=2845876344,2547149135&fm=173&s=CB50DFA600825BEF16B8A43403001073&w=550&h=334&img.JPEG", "name": "name1", "distance": "100km" },] // }, // { // "areaName": "成都2", list: [{ "id": "31", "icon": "https://ss0.baidu.com/6ONWsjip0QIZ8tyhnq/it/u=2845876344,2547149135&fm=173&s=CB50DFA600825BEF16B8A43403001073&w=550&h=334&img.JPEG", "name": "name4", "distance": "100km" }, { // "id": "12", // "icon": "https://ss0.baidu.com/6ONWsjip0QIZ8tyhnq/it/u=2845876344,2547149135&fm=173&s=CB50DFA600825BEF16B8A43403001073&w=550&h=334&img.JPEG", "name": "name51", "distance": "100km" // }, { "id": "11", "icon": "https://ss0.baidu.com/6ONWsjip0QIZ8tyhnq/it/u=2845876344,2547149135&fm=173&s=CB50DFA600825BEF16B8A43403001073&w=550&h=334&img.JPEG", "name": "name17", "distance": "100km" },] // } ], hasMore:true, }, /*---------生命周期--------*/ onLoad: function (options) { networkUtil.showLoading() var self = this setTimeout(function(){ self.getUserLocation() },1000) // this.getUserLocation() // this.requestData() }, onUnload:function(e){ page = 0 }, /*---------自定义函数--------*/ // 获取地理位置 getUserLocation() { var self = this wx.getLocation({ type: 'wgs84', // 默认为 wgs84 返回 gps 坐标,gcj02 返回可用于 wx.openLocation 的坐标 success: function (res) { // success console.log(res) latitude = res.latitude longitude = res.longitude self.requestData() }, fail: function (res) { // fail console.log(res) self.requestData() }, complete: function (res) { // complete console.log(res) } }) // latitude = 115.52 // longitude = 38.23 }, requestData() { var self = this var param = { page: page, limit: 15, lat: latitude, lng: longitude} networkUtil._get(api.hospitals, param, function (res) { console.log(res) var sumCount = self.paging(res.data.list) if (sumCount < 15) { hasMore = false } else { hasMore = true } var arr = [] if (page > 1) {// 加载更多模式 arr = self.data.hospitalList self.concatArr(res.data.list) arr = arr.concat(res.data.list) } else { arr = res.data.list } self.setData({ hospitalList: arr, hasMore: hasMore }) }, function (res) { }) }, // 下拉刷新回调接口 onPullDownRefresh: function () { page = 0; hasMore = true networkUtil.showLoading() // 网络请求,重新请求一遍数据 this.requestData(); }, // 加载更多 loadMore: function (e) { if (!hasMore) { return } page++ networkUtil.showLoading() this.requestData() }, paging(list){ var count = 0 for(var item in list){ count += list[item].data.length } return count console.log(count) }, concatArr(list){ var self = this var lastItem = self.data.hospitalList[self.data.hospitalList.length - 1] var newItem = list[0] // 如果是同一个区域 if (lastItem.id == newItem.id){ // 拼接到一起 lastItem.data = lastItem.data.concat(newItem.data) // 把拼接的删除 list.splice(0, 1) } }, toHospitalDetail: function (e) { var id = e.currentTarget.dataset.id console.log(e) wx.navigateTo({ url: "../hospital_detail/hospital_detail?id="+id }) } })