You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
100 lines
3.1 KiB
100 lines
3.1 KiB
import { getStationList } from "../../../api/ztb"
|
|
const util = require('../../../utils/util')
|
|
const event = require('../../../utils/event')
|
|
const app = getApp()
|
|
|
|
Component({
|
|
options: {
|
|
addGlobalClass: true,
|
|
multipleSlots: true
|
|
},
|
|
properties: {
|
|
cityName: { type: String, value: '' }
|
|
},
|
|
/** 页面的初始数据 */
|
|
data: {
|
|
firstShow: false,
|
|
active: 0,
|
|
loading: true,
|
|
requesting: false,
|
|
finished: false,
|
|
stationList: [],
|
|
form: {
|
|
pageNum: 1,
|
|
pageSize: 10
|
|
}
|
|
},
|
|
lifetimes: {
|
|
attached: function () {
|
|
event.on('EventMessage', this, this.onEvent)
|
|
},
|
|
detached: function () {
|
|
event.remove('EventMessage', this)
|
|
}
|
|
},
|
|
methods: {
|
|
onRestart: function () {
|
|
if(!this.data.firstShow) {
|
|
this.setData({
|
|
height: app.globalData.safeFragmentHeight - 190,
|
|
customHeight: app.globalData.customHeight,
|
|
customWidth: app.globalData.Custom.left,
|
|
StatusBar: app.globalData.StatusBar || 40,
|
|
})
|
|
}
|
|
this.data.firstShow = true
|
|
},
|
|
onEvent: function (message) {
|
|
if(message.what == 444){
|
|
this.data.form.locCityId = app.nowCity.cityCode
|
|
if(app.nowLocation){
|
|
this.data.form.personalLatitude = app.nowLocation.latitude
|
|
this.data.form.personalLongitude = app.nowLocation.longitude
|
|
}
|
|
this.setData({ cityName: app.nowCity.cityName, stationList: [], ['form.pageNum']: 1, loading: true, finished: false })
|
|
this.fetchSationList()
|
|
}
|
|
},
|
|
gridTap: function(e){
|
|
if(e.currentTarget.id == 'city'){
|
|
wx.navigateTo({url: `/pages/home/city-select/index` })
|
|
}
|
|
},
|
|
onTabChange: function({detail}){
|
|
if(this.data.active == detail.index){
|
|
return
|
|
}
|
|
this.data.active = detail.index
|
|
if(this.data.active == 1 && this.data.stationList.length <= 0){
|
|
if(app.nowCity){
|
|
this.data.form.locCityId = app.nowCity.cityCode
|
|
}
|
|
if(app.nowLocation){
|
|
this.data.form.personalLatitude = app.nowLocation.latitude
|
|
this.data.form.personalLongitude = app.nowLocation.longitude
|
|
}
|
|
this.fetchSationList()
|
|
}
|
|
},
|
|
fetchSationList: function(){
|
|
if (this.data.requesting || this.data.finished) {
|
|
return
|
|
}
|
|
this.data.requesting = true
|
|
getStationList(this.data.form).then(result => {
|
|
if (result.data && result.data.records && result.data.records.length) {
|
|
var respList = result.data.records
|
|
let nowList = `stationList[${this.data.stationList.length}]`
|
|
var num = this.data.form.pageNum
|
|
var finished = ((num - 1) * this.data.form.pageSize + respList.length) >= result.data.total
|
|
this.setData({ [nowList]: respList, ['form.pageNum']: (num + 1), finished, requesting: false, loading: false })
|
|
} else {
|
|
this.setData({ finished: true, requesting: false, loading: false })
|
|
}
|
|
}).catch(err => {
|
|
this.setData({ requesting: false, loading: false })
|
|
util.showToast(err)
|
|
})
|
|
}
|
|
}
|
|
})
|