feat(M08-A): 接入顾客端续费换房分享
This commit is contained in:
@@ -9,6 +9,11 @@ Page({
|
||||
order: null,
|
||||
history: [],
|
||||
cancellation: null,
|
||||
renewMinutes: 60,
|
||||
changeRoomId: '',
|
||||
shareTtlMinutes: 30,
|
||||
shareToken: '',
|
||||
sharePermissions: ['VIEW_ROOM', 'OPEN_DOOR'],
|
||||
},
|
||||
|
||||
onLoad(options) {
|
||||
@@ -79,6 +84,81 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
onRenewMinutesInput(event) {
|
||||
this.setData({ renewMinutes: Number(event.detail.value || 0) })
|
||||
},
|
||||
|
||||
onChangeRoomInput(event) {
|
||||
this.setData({ changeRoomId: String(event.detail.value || '').trim() })
|
||||
},
|
||||
|
||||
onShareTtlInput(event) {
|
||||
this.setData({ shareTtlMinutes: Number(event.detail.value || 0) })
|
||||
},
|
||||
|
||||
async renewOrder() {
|
||||
if (!this.data.orderId || !this.data.order) return
|
||||
const minutes = Number(this.data.renewMinutes || 0)
|
||||
if (!Number.isFinite(minutes) || minutes < 15) {
|
||||
this.setData({ errorMessage: '续费时长至少 15 分钟' })
|
||||
return
|
||||
}
|
||||
const currentEnd = new Date(this.data.order.endAt)
|
||||
const nextEnd = new Date(currentEnd.getTime() + minutes * 60000)
|
||||
await this.withOrderRequest(async () => {
|
||||
const response = await request(`/orders/${encodeURIComponent(this.data.orderId)}/renew`, {
|
||||
method: 'POST',
|
||||
data: {
|
||||
endAt: nextEnd.toISOString(),
|
||||
pricingPolicy: 'CURRENT',
|
||||
reason: `顾客小程序续费 ${minutes} 分钟`,
|
||||
},
|
||||
})
|
||||
await this.loadOrder(this.data.orderId)
|
||||
this.setData({
|
||||
successMessage: `续费已提交,补差 ${cents(response.data.amountDeltaCents)}`,
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
async changeRoom() {
|
||||
if (!this.data.orderId || !this.data.changeRoomId) {
|
||||
this.setData({ errorMessage: '请输入目标房间 ID' })
|
||||
return
|
||||
}
|
||||
await this.withOrderRequest(async () => {
|
||||
const response = await request(`/orders/${encodeURIComponent(this.data.orderId)}/change-room`, {
|
||||
method: 'POST',
|
||||
data: {
|
||||
roomId: this.data.changeRoomId,
|
||||
reason: '顾客小程序换房',
|
||||
},
|
||||
})
|
||||
await this.loadOrder(this.data.orderId)
|
||||
this.setData({
|
||||
successMessage: `换房已提交,差价 ${cents(response.data.amountDeltaCents)}`,
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
async createShare() {
|
||||
if (!this.data.orderId) return
|
||||
const ttlMinutes = Math.min(Math.max(Number(this.data.shareTtlMinutes || 30), 5), 1440)
|
||||
await this.withOrderRequest(async () => {
|
||||
const response = await request(`/orders/${encodeURIComponent(this.data.orderId)}/shares`, {
|
||||
method: 'POST',
|
||||
data: {
|
||||
permissions: this.data.sharePermissions,
|
||||
ttlMinutes,
|
||||
},
|
||||
})
|
||||
this.setData({
|
||||
shareToken: response.data.token,
|
||||
successMessage: `分享口令已生成,${response.data.expiresInMinutes} 分钟内有效`,
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
async withOrderRequest(work) {
|
||||
this.setData({ loading: true, errorMessage: '', successMessage: '' })
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user