千目品牌领券机
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.
 

174 lines
2.9 KiB

import {
getCities
} from '../../js/cities'
Page({
/**
* 页面的初始数据
*/
data: {
q: "",
showList: false,
cities: [],
filteredCities: [],
currentMall: null,
currentCity: null,
currentMalls: [],
isMallExpand: false,
indexedList: [],
scrollIntoView: ''
},
scrollIntoView(e) {
this.setData({
scrollIntoView: e.target.id
})
},
setCity(e) {
const name = e.target.id;
const city = this.data.filteredCities.find((city) => city.name === name)
this.setData({
currentCity: city,
currentMalls: city.malls,
currentMall: city.malls[0],
showList: false
})
},
expandMall() {
this.setData({
isMallExpand: true
})
},
hideMallExpand() {
this.setData({
isMallExpand: false
})
},
onInput({
detail: {
value
}
}) {
this.setData({
q: value,
filteredCities: this.data.cities.map(({
name
}) => name === value)
});
},
doShowList() {
this.setData({
showList: true
});
},
onBlur() {
!this.data.q && this.setData({
showList: false
})
},
clearQ() {
this.setData({
q: ''
})
},
async setMall(e) {
const name = e.target.id;
const mall = this.data.currentMalls.find((mall) => mall.name === name)
const {
malls
} = getApp()
this.setData({
currentMall: mall,
isMallExpand: false
});
malls.setCurrentMall({
city: this.data.currentCity.name,
name: mall.name,
code: mall.code
})
wx.navigateBack()
},
setMallByCity(e) {
const name = e.target.id;
const city = this.data.cities.find((city) => city.name === name)
this.setData({
currentCity: city,
currentMalls: city.malls,
currentMall: city.malls[0]
});
},
/**
* 生命周期函数--监听页面加载
*/
async onLoad(options) {
const {
malls
} = getApp()
const cities = await getCities()
const mall = await malls.getCurrentMall()
const city = cities.find(({
name
}) => name === mall.city)
this.setData({
cities,
filteredCities: cities,
currentCity: city,
currentMalls: city.malls,
currentMall: mall
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})