import { serviceStationService } from '../../services' interface ServiceLocation { id: string name: string shortName?: string address?: string contactPhone?: string contactPhoneDisplay?: string openingHoursText?: string services?: string[] latitude?: number | string longitude?: number | string } interface ServiceAnnouncement { id: string title: string content?: string expiresAt?: string | null } interface ServiceStationPageData { serviceLocation: ServiceLocation | null announcements: ServiceAnnouncement[] loading: boolean loadError: boolean } Page({ data: { serviceLocation: null as ServiceLocation | null, announcements: [] as ServiceAnnouncement[], loading: true, loadError: false, }, onLoad() { this.loadStation() }, async loadStation() { this.setData({ loading: true, loadError: false }) try { const station = await serviceStationService.getStation() if (!station) { this.setData({ serviceLocation: null, announcements: [], loading: false }) return } // 公告是增强信息:失败降级为空数组,不阻断站点主体信息展示 const announcements = await serviceStationService.getVisibleAnnouncements(station.id as string) this.setData({ serviceLocation: station as ServiceLocation, announcements, loading: false }) } catch (error) { console.error('加载服务站失败', error) this.setData({ loading: false, loadError: true }) } }, call() { const station = this.data.serviceLocation if (!station) return const phoneNumber = station.contactPhone || station.contactPhoneDisplay || '' const digitCount = phoneNumber.replace(/\D/g, '').length if (!phoneNumber || phoneNumber.includes('*') || digitCount < 5) { wx.showToast({ title: '联系电话请以预约确认为准', icon: 'none' }) return } wx.makePhoneCall({ phoneNumber }) }, openMap() { const station = this.data.serviceLocation if (!station) return const latitude = Number(station.latitude) const longitude = Number(station.longitude) if (Number.isFinite(latitude) && Number.isFinite(longitude) && latitude && longitude) { wx.openLocation({ latitude, longitude, name: station.name, address: station.address || '', }) return } if (station.address) { wx.setClipboardData({ data: station.address }) return } wx.showToast({ title: '暂未提供地图位置', icon: 'none' }) }, book() { const station = this.data.serviceLocation const id = station ? station.id : '' const query = id ? `?serviceLocationId=${encodeURIComponent(id)}` : '' wx.navigateTo({ url: `/pages/service-appointment/service-appointment${query}` }) }, /** 公告详情:临时公告正文较长,用弹窗完整展示,避免卡片被截断 */ onShowAnnouncement(e: WechatMiniprogram.TouchEvent) { const id = e.currentTarget.dataset.id as string const target = (this.data.announcements as ServiceAnnouncement[]).find((item) => item.id === id) if (!target) return wx.showModal({ title: target.title || '临时公告', content: target.content || target.title || '', showCancel: false, confirmText: '知道了', }) }, onRetry() { this.loadStation() }, })