feat(M03-C): 完成地图选店与距离排序

This commit is contained in:
Codex
2026-06-18 15:15:39 +08:00
parent 9417064e61
commit df373faa82
24 changed files with 614 additions and 132 deletions
+47 -38
View File
@@ -1,46 +1,55 @@
const defaultAvatarUrl = 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'
const { request } = require('../../utils/api.js')
Page({
data: {
motto: '自助棋牌室',
userInfo: {
avatarUrl: defaultAvatarUrl,
nickName: '',
},
hasUserInfo: false,
canIUseGetUserProfile: wx.canIUse('getUserProfile'),
canIUseNicknameComp: wx.canIUse('input.type.nickname'),
city: '',
locating: false,
loading: false,
errorMessage: '',
stores: [],
},
bindViewTap() {
wx.navigateTo({
url: '../logs/logs'
onCityInput(event) {
this.setData({ city: event.detail.value })
},
async searchByCity() {
const city = this.data.city.trim()
if (!city) {
this.setData({ errorMessage: '请输入城市名称' })
return
}
await this.loadStores({ city })
},
locateNearby() {
this.setData({ locating: true, errorMessage: '' })
wx.getLocation({
type: 'gcj02',
success: async ({ latitude, longitude }) => {
await this.loadStores({ latitude, longitude })
},
fail: () => {
this.setData({ errorMessage: '定位未授权,请输入城市手工选店' })
},
complete: () => {
this.setData({ locating: false })
},
})
},
onChooseAvatar(e) {
const { avatarUrl } = e.detail
const { nickName } = this.data.userInfo
this.setData({
'userInfo.avatarUrl': avatarUrl,
hasUserInfo: nickName && avatarUrl && avatarUrl !== defaultAvatarUrl,
})
},
onInputChange(e) {
const nickName = e.detail.value
const { avatarUrl } = this.data.userInfo
this.setData({
'userInfo.nickName': nickName,
hasUserInfo: nickName && avatarUrl && avatarUrl !== defaultAvatarUrl,
})
},
getUserProfile() {
wx.getUserProfile({
desc: '用于展示用户头像和昵称',
success: (res) => {
this.setData({
userInfo: res.userInfo,
hasUserInfo: true
})
}
})
async loadStores(filters) {
this.setData({ loading: true, errorMessage: '' })
try {
const query = Object.entries(filters)
.map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`)
.join('&')
const response = await request(`/stores?${query}`)
this.setData({ stores: response.data || [] })
} catch (error) {
this.setData({ errorMessage: error.message || '门店加载失败' })
} finally {
this.setData({ loading: false })
}
},
})