feat(M08-A): 接入顾客端选店下单入口
This commit is contained in:
@@ -1,8 +1,60 @@
|
||||
const { request, ensureLogin, cents } = require('../../utils/api.js')
|
||||
|
||||
Page({
|
||||
data: {
|
||||
storeId: '',
|
||||
loading: false,
|
||||
errorMessage: '',
|
||||
store: null,
|
||||
rooms: [],
|
||||
wifi: null,
|
||||
},
|
||||
onLoad(options) {
|
||||
this.setData({ storeId: options.storeId || '' })
|
||||
if (options.storeId) this.loadStore(options.storeId)
|
||||
},
|
||||
|
||||
async loadStore(storeId) {
|
||||
this.setData({ loading: true, errorMessage: '' })
|
||||
try {
|
||||
const [storeResponse, roomsResponse] = await Promise.all([
|
||||
request(`/stores/${encodeURIComponent(storeId)}`),
|
||||
request(`/stores/${encodeURIComponent(storeId)}/rooms`),
|
||||
])
|
||||
this.setData({
|
||||
store: storeResponse.data,
|
||||
rooms: (roomsResponse.data || []).map((room) => ({
|
||||
...room,
|
||||
basePriceText: cents(room.basePriceCents),
|
||||
depositText: cents(room.depositCents),
|
||||
})),
|
||||
})
|
||||
} catch (error) {
|
||||
this.setData({ errorMessage: error.message || '门店加载失败' })
|
||||
} finally {
|
||||
this.setData({ loading: false })
|
||||
}
|
||||
},
|
||||
|
||||
openRoom(event) {
|
||||
const roomId = event.currentTarget.dataset.roomId
|
||||
if (!roomId || !this.data.storeId) return
|
||||
wx.navigateTo({
|
||||
url: `/pages/room/detail?storeId=${encodeURIComponent(this.data.storeId)}&roomId=${encodeURIComponent(roomId)}`,
|
||||
})
|
||||
},
|
||||
|
||||
async loadWifi() {
|
||||
if (!this.data.storeId) return
|
||||
this.setData({ loading: true, errorMessage: '' })
|
||||
try {
|
||||
await ensureLogin()
|
||||
const response = await request(`/stores/${encodeURIComponent(this.data.storeId)}/wifi`)
|
||||
this.setData({ wifi: response.data })
|
||||
} catch (error) {
|
||||
this.setData({ errorMessage: error.message || '请登录并确认到店权限后查看 Wi-Fi' })
|
||||
} finally {
|
||||
this.setData({ loading: false })
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
@@ -1,5 +1,31 @@
|
||||
<view class="page">
|
||||
<view class="title">门店详情</view>
|
||||
<view>门店编号:{{storeId}}</view>
|
||||
<view wx:if="{{store}}" class="store-head">
|
||||
<view class="title">{{store.name}}</view>
|
||||
<view class="muted">{{store.city}}{{store.district}} {{store.address}}</view>
|
||||
<view class="{{store.openNow ? 'open' : 'closed'}}">{{store.openNow ? '营业中' : '休息中'}}</view>
|
||||
<view wx:if="{{store.contactPhone}}" class="muted">电话:{{store.contactPhone}}</view>
|
||||
</view>
|
||||
<view wx:else class="title">门店详情</view>
|
||||
|
||||
<view wx:if="{{errorMessage}}" class="error">{{errorMessage}}</view>
|
||||
|
||||
<view class="section-title">房间</view>
|
||||
<view wx:if="{{!loading && rooms.length === 0}}" class="empty">暂无可预订房间</view>
|
||||
<view wx:for="{{rooms}}" wx:key="id" class="room-card" bindtap="openRoom" data-room-id="{{item.id}}">
|
||||
<view class="room-name">{{item.name}}</view>
|
||||
<view class="muted">{{item.categoryName}} · {{item.capacity}}人 · {{item.roomNo}}</view>
|
||||
<view class="price">{{item.basePriceText}}/小时</view>
|
||||
<view class="muted">押金 {{item.depositText}} · 最少 {{item.minimumMinutes}} 分钟</view>
|
||||
<view class="{{item.operationalStatus === 'AVAILABLE' ? 'open' : 'closed'}}">
|
||||
{{item.operationalStatus === 'AVAILABLE' ? '可预订' : '暂不可订'}}
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<button loading="{{loading}}" bindtap="loadWifi">查看到店 Wi-Fi</button>
|
||||
<view wx:if="{{wifi}}" class="wifi-box">
|
||||
<view>SSID:{{wifi.ssid}}</view>
|
||||
<view>密码:{{wifi.password}}</view>
|
||||
</view>
|
||||
|
||||
<view class="notice">场景码仅用于页面导航,不授予开门或设备控制权限。</view>
|
||||
</view>
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
.page {
|
||||
padding: 32rpx;
|
||||
min-height: 100vh;
|
||||
background: #f5f6f8;
|
||||
}
|
||||
|
||||
.title {
|
||||
@@ -12,3 +14,56 @@
|
||||
margin-top: 32rpx;
|
||||
color: #777777;
|
||||
}
|
||||
|
||||
.store-head,
|
||||
.room-card,
|
||||
.wifi-box {
|
||||
margin-bottom: 24rpx;
|
||||
padding: 28rpx;
|
||||
border-radius: 16rpx;
|
||||
background: #ffffff;
|
||||
}
|
||||
|
||||
.room-card:active {
|
||||
background: #eef4ff;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
margin: 32rpx 0 16rpx;
|
||||
font-size: 32rpx;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.room-name {
|
||||
font-size: 34rpx;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.muted {
|
||||
margin-top: 8rpx;
|
||||
color: #667085;
|
||||
}
|
||||
|
||||
.price {
|
||||
margin-top: 12rpx;
|
||||
color: #b42318;
|
||||
font-size: 34rpx;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.open {
|
||||
margin-top: 8rpx;
|
||||
color: #17823b;
|
||||
}
|
||||
|
||||
.closed,
|
||||
.error {
|
||||
margin-top: 8rpx;
|
||||
color: #c73535;
|
||||
}
|
||||
|
||||
.empty {
|
||||
padding: 64rpx 0;
|
||||
color: #888888;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user