feat(escort): 新增立即预约页并接入首页主按钮

首页「立即预约」此前跳到服务列表,用户仍需再选一次服务才能下单,
路径偏长。新增 pages/escort/itemorder 作为统一下单页:进来即可选陪诊项目、
选就诊人(姓名/电话由档案只读带入,避免手填出错)、填医院与时间后提交。

提交时按服务配置处理班次(固定班次走选择器,弹性时段走时间选择器),
需要寄件的跑腿类服务额外要求填写收货地址,并用同一幂等键保证重试不重复下单。
This commit is contained in:
lik
2026-11-04 22:18:24 +08:00
parent a3fa469369
commit 2ba45b515d
6 changed files with 841 additions and 3 deletions
+312
View File
@@ -0,0 +1,312 @@
const API = require('../../utils/api.js')
const { formatDate } = require('../../utils/date.js')
Page({
data: {
services: [],
serviceOptions: [],
serviceIndex: 0,
service: {},
serviceIcon: 'user-business',
totalPrice: '0.00',
pageLoading: true,
pageError: '',
submitting: false,
profiles: [],
selectedProfileId: '',
patientName: '',
patientPhone: '',
selectedPatient: null,
province: '',
provinceIndex: 0,
provinces: [],
hospital: '',
appointmentDate: '',
appointmentTime: '',
minAppointmentDate: '',
fixedTime: false,
timeOptions: [],
sessionIndex: 0,
timeStart: '',
timeEnd: '',
remark: '',
shippingAddress: '',
requiresAddress: false,
gender: '不限',
genderIndex: 0,
genderOptions: ['不限', '男', '女']
},
onLoad(options) {
this.requestedServiceId = Number(options.id)
this.idempotencyKey = this.createIdempotencyKey()
this.initializePage()
},
onShow() {
// 从新增/编辑就诊人页返回时刷新档案,首次进入由 initializePage 加载。
if (this.pageReady && getApp().globalData.user?._id) this.loadProfiles()
},
async initializePage() {
this.pageReady = false
this.setData({ pageLoading: true, pageError: '' })
const services = await getApp().loadServices()
if (!services || services.length === 0) {
this.setData({ pageLoading: false, pageError: '服务加载失败,请重试' })
return
}
const requestedIndex = services.findIndex((item) => item.id === this.requestedServiceId)
const consultationIndex = services.findIndex((item) => item.title.includes('问诊'))
const serviceIndex = requestedIndex >= 0 ? requestedIndex : (consultationIndex >= 0 ? consultationIndex : 0)
this.setData({
services,
serviceOptions: services.map((item) => item.title)
})
this.applyService(services[serviceIndex], serviceIndex)
this.setData({ pageLoading: false })
this.pageReady = true
const app = getApp()
await app.waitForAuth()
if (app.globalData.user?._id) this.loadProfiles()
},
retryLoad() {
this.initializePage()
},
createIdempotencyKey() {
return `order_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 12)}`
},
applyService(service, serviceIndex) {
const booking = service.booking || {}
const sessions = booking.sessions || []
const fixedTime = sessions.length > 0 && sessions.every((item) => !item.flexible)
const firstSession = sessions[0] || {}
const minDate = new Date()
minDate.setDate(minDate.getDate() + Number(booking.advanceDays || 0))
let timeEnd = firstSession.end || ''
if (!fixedTime && firstSession.end && booking.durationMinutes) {
const [hour, minute] = firstSession.end.split(':').map(Number)
const latest = hour * 60 + minute - booking.durationMinutes
timeEnd = `${String(Math.floor(latest / 60)).padStart(2, '0')}:${String(latest % 60).padStart(2, '0')}`
}
const provinces = service.areas || []
this.setData({
service,
serviceIndex,
serviceIcon: this.getServiceIcon(service.title),
totalPrice: service.price,
minAppointmentDate: formatDate(minDate),
fixedTime,
timeOptions: sessions.map((item) => `${item.start} - ${item.end}`),
sessionIndex: 0,
timeStart: firstSession.start || '',
timeEnd,
provinces,
province: provinces[0] || '',
provinceIndex: 0,
appointmentDate: '',
appointmentTime: '',
shippingAddress: '',
requiresAddress: !!booking.requiresAddress
})
},
onServiceChange(e) {
const index = Number(e.detail.value)
const service = this.data.services[index]
if (!service || index === this.data.serviceIndex) return
this.applyService(service, index)
},
getServiceIcon(title) {
if (title.includes('夜间')) return 'moon'
if (title.includes('陪诊')) return 'time'
return 'user-business'
},
async ensureLogin() {
const app = getApp()
await app.waitForAuth()
if (app.globalData.user?._id) return true
const modal = await new Promise((resolve) => {
wx.showModal({
title: '登录后预约',
content: '登录成功后将继续预约',
confirmText: '去登录',
confirmColor: '#B8520A',
success: resolve,
fail: (err) => {
console.log('登录提示弹窗失败', err)
resolve({ confirm: false })
}
})
})
if (!modal.confirm) return null
wx.removeStorageSync('has_logout')
return app.silentSignin()
},
loadProfiles() {
return API.healthProfile.getMyProfiles({ page: 1, pageSize: 50 })
.then((res) => {
if (res.code !== 0) throw new Error(res.msg || '就诊人加载失败')
const profiles = (res.data?.list || []).map((item) => ({
_id: item._id,
name: item.profile?.name || '',
mobile: item.profile?.mobile || '',
sex: item.profile?.sex || '',
birth: item.profile?.birth || ''
}))
this.setData({ profiles })
})
.catch((err) => {
console.log('获取就诊人列表失败', err)
wx.showToast({ title: '就诊人加载失败,请重试', icon: 'none' })
})
},
onSelectProfile(e) {
const id = e.currentTarget.dataset.id
const profile = this.data.profiles.find((item) => item._id === id)
if (!profile) return
this.setData({
selectedProfileId: id,
patientName: profile.name,
patientPhone: profile.mobile,
selectedPatient: profile
})
},
goToAddProfile() {
wx.navigateTo({ url: '/pages/health/profileedit' })
},
onProvinceChange(e) {
const index = Number(e.detail.value)
this.setData({ provinceIndex: index, province: this.data.provinces[index] })
},
onHospitalChange(e) {
this.setData({ hospital: e.detail.value })
},
onDateChange(e) {
this.setData({ appointmentDate: e.detail.value })
},
onTimeChange(e) {
if (this.data.fixedTime) {
const index = Number(e.detail.value)
const session = this.data.service.booking.sessions[index]
this.setData({ sessionIndex: index, appointmentTime: session.start })
return
}
this.setData({ appointmentTime: e.detail.value })
},
onGenderChange(e) {
const index = Number(e.detail.value)
this.setData({ genderIndex: index, gender: this.data.genderOptions[index] })
},
onRemarkChange(e) {
this.setData({ remark: e.detail.value })
},
onShippingAddressChange(e) {
this.setData({ shippingAddress: e.detail.value })
},
validateOrder() {
const data = this.data
if (!data.selectedProfileId || !data.selectedPatient) return '请选择就诊人'
if (!data.hospital.trim()) return '请输入就诊医院'
if (!data.appointmentDate) return '请选择预约日期'
if (!data.appointmentTime) return '请选择预约时间'
if (data.requiresAddress && !data.shippingAddress.trim()) return '请填写完整收货地址'
if (!/^1[3-9]\d{9}$/.test(data.selectedPatient.mobile.trim())) {
return '就诊人手机号有误,请到就诊人档案修改'
}
return ''
},
async submitOrder() {
if (this.data.submitting) return
this.setData({ submitting: true })
try {
const loggedIn = await this.ensureLogin()
if (loggedIn === null) return
if (!loggedIn || !getApp().globalData.user?._id) {
wx.showToast({ title: '登录失败,请重试', icon: 'none' })
return
}
if (this.data.profiles.length === 0) await this.loadProfiles()
const error = this.validateOrder()
if (error) {
wx.showToast({ title: error, icon: 'none' })
return
}
const data = this.data
const sexMap = { 男: 'male', 女: 'female' }
const orderData = {
idempotencyKey: this.idempotencyKey,
healthProfileId: data.selectedProfileId,
escort: {
serviceId: data.service.id,
sexRequirement: sexMap[data.gender] || 'none'
},
hospital: {
province: data.province,
name: data.hospital.trim()
},
schedule: {
date: data.appointmentDate,
startTime: data.appointmentTime
},
shippingAddress: { address: data.shippingAddress.trim() },
notes: { patientNote: data.remark.trim() }
}
// 网络重试沿用同一幂等键,服务端只创建一笔订单。
const res = await API.escort.createRecord(orderData)
if (res.code !== 0) throw new Error(res.msg || '下单失败')
wx.showToast({ title: '下单成功', icon: 'success' })
this.resetForm()
wx.navigateTo({ url: '/pages/escort/recordlist?tab=ongoing' })
} catch (err) {
console.log('下单失败', err)
wx.showToast({ title: err.message || '网络请求失败,请重试', icon: 'none' })
} finally {
this.setData({ submitting: false })
}
},
resetForm() {
const provinces = this.data.provinces
this.setData({
selectedProfileId: '',
patientName: '',
patientPhone: '',
selectedPatient: null,
province: provinces[0] || '',
provinceIndex: 0,
hospital: '',
appointmentDate: '',
appointmentTime: '',
sessionIndex: 0,
gender: '不限',
genderIndex: 0,
remark: '',
shippingAddress: ''
})
this.idempotencyKey = this.createIdempotencyKey()
}
})
+7
View File
@@ -0,0 +1,7 @@
{
"usingComponents": {
"t-icon": "tdesign-miniprogram/icon/icon",
"t-loading": "tdesign-miniprogram/loading/loading"
},
"navigationBarTitleText": "立即预约"
}
+134
View File
@@ -0,0 +1,134 @@
<!--pages/escort/itemorder.wxml-->
<view class="page-bg">
<view class="container" wx:if="{{service.id}}">
<view class="page-header">
<view class="header-accent"></view>
<text class="header-title">立即预约</text>
<text class="header-subtitle">选择陪诊项目,填写信息后即可提交预约</text>
</view>
<view class="booking-form">
<!-- 陪诊项目:切换后同步更新服务的预约规则 -->
<view class="service-picker-row">
<text class="order-label">陪诊项目</text>
<picker class="service-picker" mode="selector" range="{{serviceOptions}}" value="{{serviceIndex}}"
disabled="{{submitting}}" bindchange="onServiceChange">
<view class="order-service-info">
<view class="order-service-mark">
<t-icon name="{{serviceIcon}}" size="48rpx" color="#9B4508" />
</view>
<view class="order-service-text">
<text class="order-service-title">{{service.title}}</text>
<text class="order-service-price">¥{{service.price}}/次</text>
</view>
<view class="service-picker-arrow">
<t-icon name="chevron-down" size="40rpx" color="#9B4508" />
</view>
</view>
</picker>
</view>
<!-- 选择就诊人:订单必须关联健康档案,就诊人信息全部由此带入 -->
<view class="order-row column">
<text class="order-label">选择就诊人</text>
<scroll-view class="patient-scroll" scroll-x wx:if="{{profiles.length > 0}}">
<view class="patient-chips">
<view class="patient-chip {{selectedProfileId === item._id ? 'active' : ''}}" wx:for="{{profiles}}" wx:key="_id"
data-id="{{item._id}}" bindtap="onSelectProfile">
<text class="patient-chip-name">{{item.name}}</text>
<text class="patient-chip-phone">{{item.mobile}}</text>
</view>
<view class="patient-chip patient-chip-add" bindtap="goToAddProfile">
<text class="patient-chip-name">+ 添加就诊人</text>
</view>
</view>
</scroll-view>
<view class="add-profile-tip" wx:else bindtap="goToAddProfile">
<text class="add-profile-tip-text">还没有就诊人,去添加后可一键带入</text>
<t-icon name="chevron-right" size="24rpx" color="#9B4508" />
</view>
</view>
<!-- 就诊人姓名/电话只读,与所选档案严格一致 -->
<view class="order-row">
<text class="order-label">就诊人姓名</text>
<text class="order-value {{patientName ? '' : 'placeholder'}}">{{patientName || '请先选择就诊人'}}</text>
</view>
<view class="order-row">
<text class="order-label">联系电话</text>
<text class="order-value {{patientPhone ? '' : 'placeholder'}}">{{patientPhone || '请先选择就诊人'}}</text>
</view>
<view class="order-row">
<text class="order-label">就诊省份</text>
<picker class="order-picker" mode="selector" range="{{provinces}}" value="{{provinceIndex}}" bindchange="onProvinceChange">
<view class="picker-value {{province ? '' : 'placeholder'}}">{{province || '请选择省份'}}</view>
</picker>
</view>
<view class="order-row">
<text class="order-label">就诊医院</text>
<input class="order-input" value="{{hospital}}" placeholder="请输入就诊医院" placeholder-class="input-placeholder" bindinput="onHospitalChange" />
</view>
<view class="order-row">
<text class="order-label">陪诊师性别</text>
<picker class="order-picker" mode="selector" range="{{genderOptions}}" value="{{genderIndex}}" bindchange="onGenderChange">
<view class="picker-value {{gender ? '' : 'placeholder'}}">{{gender || '请选择性别要求'}}</view>
</picker>
</view>
<view class="order-row">
<text class="order-label">预约日期</text>
<picker class="order-picker" mode="date" value="{{appointmentDate}}" start="{{minAppointmentDate}}" bindchange="onDateChange">
<view class="picker-value {{appointmentDate ? '' : 'placeholder'}}">{{appointmentDate || '请选择预约日期'}}</view>
</picker>
</view>
<view class="order-row">
<text class="order-label">预约时间</text>
<picker wx:if="{{fixedTime}}" class="order-picker" mode="selector" range="{{timeOptions}}" value="{{sessionIndex}}" bindchange="onTimeChange">
<view class="picker-value {{appointmentTime ? '' : 'placeholder'}}">
{{appointmentTime ? timeOptions[sessionIndex] : '请选择服务班次'}}
</view>
</picker>
<picker wx:else class="order-picker" mode="time" value="{{appointmentTime}}" start="{{timeStart}}" end="{{timeEnd}}" bindchange="onTimeChange">
<view class="picker-value {{appointmentTime ? '' : 'placeholder'}}">{{appointmentTime || '请选择预约时间'}}</view>
</picker>
</view>
<!-- 收货地址仅对快递/跑腿服务展示,随订单保存快照 -->
<view class="order-row column" wx:if="{{requiresAddress}}">
<text class="order-label">收货地址</text>
<textarea class="order-textarea" value="{{shippingAddress}}" placeholder="请输入省市区、街道门牌等完整收货地址" maxlength="200" placeholder-class="input-placeholder" bindinput="onShippingAddressChange" />
<text class="address-tip">收货人与联系电话使用所选就诊人信息</text>
</view>
<view class="order-row column">
<text class="order-label">备注说明</text>
<textarea class="order-textarea" value="{{remark}}" placeholder="请输入其他需求或备注信息" maxlength="200" placeholder-class="input-placeholder" bindinput="onRemarkChange" />
<text class="textarea-count">{{remark.length}}/200</text>
</view>
</view>
<view class="bottom-placeholder"></view>
<view class="bottom-bar">
<view class="bottom-price">
<text class="bottom-price-label">合计</text>
<text class="price-sym">¥</text>
<text class="bottom-price-value">{{totalPrice}}</text>
</view>
<button class="submit-btn" bindtap="submitOrder" disabled="{{submitting}}" loading="{{submitting}}">{{submitting ? '提交中' : '提交预约'}}</button>
</view>
</view>
<view class="page-state" wx:if="{{pageLoading}}">
<t-loading theme="circular" size="40rpx" text="加载中..." />
</view>
<view class="page-state" wx:if="{{!pageLoading && pageError}}">
<text class="page-state-text">{{pageError}}</text>
<button class="page-retry" bindtap="retryLoad">重新加载</button>
</view>
</view>
+384
View File
@@ -0,0 +1,384 @@
/* pages/escort/itemorder.wxss */
page {
--shadow-bar: 0 -2rpx 8rpx rgba(63, 43, 25, 0.07);
background: var(--paper);
}
.page-bg {
min-height: 100vh;
background: var(--paper);
}
.container {
padding: 0 32rpx calc(40rpx + env(safe-area-inset-bottom));
}
.page-header {
padding-top: 32rpx;
}
.header-accent {
width: 64rpx;
height: 8rpx;
border-radius: 4rpx;
background: var(--brand-strong);
}
.header-title {
display: block;
margin-top: 22rpx;
color: var(--ink);
font-size: 48rpx;
font-weight: 700;
letter-spacing: 1rpx;
line-height: 1.3;
}
.header-subtitle {
display: block;
margin-top: 12rpx;
color: var(--muted);
font-size: 28rpx;
line-height: 1.6;
}
.booking-form {
margin-top: 32rpx;
padding: 0 28rpx;
border-radius: 28rpx;
background: var(--white);
box-shadow: var(--shadow-card);
}
.service-picker-row {
padding: 24rpx 0;
border-bottom: 2rpx solid var(--line);
}
.service-picker {
display: block;
margin-top: 16rpx;
}
.order-service-info {
display: flex;
align-items: center;
padding: 20rpx 24rpx;
border: 2rpx solid var(--brand-line);
border-radius: 20rpx;
background: var(--brand-soft);
}
.order-service-mark {
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
width: 80rpx;
height: 80rpx;
}
.order-service-text {
flex: 1;
min-width: 0;
margin: 0 16rpx 0 12rpx;
}
.order-service-title {
display: block;
color: var(--ink);
font-size: 30rpx;
font-weight: 700;
line-height: 1.4;
}
.order-service-price {
display: block;
margin-top: 6rpx;
color: var(--brand-ink);
font-size: 26rpx;
font-weight: 700;
}
.service-picker-arrow {
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
width: 56rpx;
height: 56rpx;
border: 2rpx solid var(--brand-line);
border-radius: 50%;
background: var(--white);
}
.order-row {
display: flex;
align-items: center;
justify-content: space-between;
padding: 24rpx 0;
border-bottom: 2rpx solid var(--line);
}
.order-row:last-child {
border-bottom: none;
}
.order-row.column {
flex-direction: column;
align-items: stretch;
justify-content: flex-start;
}
.order-label {
flex-shrink: 0;
color: var(--muted);
font-size: 28rpx;
letter-spacing: 1rpx;
}
.order-input,
.order-value {
flex: 1;
min-width: 0;
margin-left: 24rpx;
color: var(--ink);
font-size: 28rpx;
font-weight: 700;
text-align: right;
}
.input-placeholder,
.order-value.placeholder,
.picker-value.placeholder {
color: var(--muted);
font-weight: 400;
}
.order-picker {
flex: 1;
min-width: 0;
margin-left: 24rpx;
}
.picker-value {
display: block;
color: var(--ink);
font-size: 28rpx;
font-weight: 700;
text-align: right;
}
.order-textarea {
box-sizing: border-box;
width: 100%;
height: 160rpx;
margin-top: 16rpx;
padding: 20rpx;
border: 2rpx solid var(--line);
border-radius: 12rpx;
background: var(--paper);
color: var(--ink);
font-size: 28rpx;
line-height: 1.5;
}
.textarea-count {
align-self: flex-end;
margin-top: 10rpx;
color: var(--muted);
font-size: 24rpx;
}
.address-tip {
align-self: flex-start;
margin-top: 10rpx;
color: var(--muted);
font-size: 24rpx;
line-height: 1.6;
}
.patient-scroll {
width: 100%;
margin-top: 16rpx;
white-space: nowrap;
}
.patient-chips {
display: inline-flex;
gap: 16rpx;
}
.patient-chip {
display: inline-flex;
flex-direction: column;
box-sizing: border-box;
min-width: 180rpx;
padding: 16rpx 24rpx;
border: 2rpx solid var(--line);
border-radius: 16rpx;
background: var(--paper);
transition: opacity 0.15s ease;
}
.patient-chip:active,
.add-profile-tip:active {
opacity: 0.7;
}
.patient-chip.active {
border-color: var(--brand-strong);
background: var(--brand-soft);
}
.patient-chip-name {
color: var(--ink-2);
font-size: 26rpx;
font-weight: 700;
}
.patient-chip.active .patient-chip-name,
.patient-chip-add .patient-chip-name {
color: var(--brand-ink);
}
.patient-chip-phone {
margin-top: 6rpx;
color: var(--muted);
font-size: 24rpx;
}
.patient-chip-add {
justify-content: center;
}
.add-profile-tip {
display: flex;
align-items: center;
box-sizing: border-box;
width: 100%;
margin-top: 16rpx;
padding: 22rpx 24rpx;
border: 2rpx solid var(--brand-line);
border-radius: 16rpx;
background: var(--brand-soft);
transition: opacity 0.15s ease;
}
.add-profile-tip-text {
flex: 1;
min-width: 0;
margin-right: 8rpx;
color: var(--brand-ink);
font-size: 24rpx;
font-weight: 700;
}
.bottom-placeholder {
height: 152rpx;
}
.bottom-bar {
position: fixed;
right: 0;
bottom: 0;
left: 0;
z-index: 100;
display: flex;
align-items: center;
justify-content: space-between;
padding: 20rpx 32rpx;
padding-bottom: calc(20rpx + constant(safe-area-inset-bottom));
padding-bottom: calc(20rpx + env(safe-area-inset-bottom));
border-top: 2rpx solid var(--line);
background: var(--white);
box-shadow: var(--shadow-bar);
}
.bottom-price {
display: flex;
align-items: baseline;
}
.bottom-price-label {
margin-right: 8rpx;
color: var(--muted);
font-size: 26rpx;
}
.price-sym {
color: var(--brand-strong);
font-size: 28rpx;
font-weight: 700;
}
.bottom-price-value {
margin-left: 2rpx;
color: var(--brand-strong);
font-size: 44rpx;
font-weight: 700;
}
.submit-btn {
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
margin: 0;
padding: 22rpx 48rpx;
border: none;
border-radius: 999rpx;
background: var(--brand-strong);
box-shadow: var(--shadow-cta);
color: var(--white);
font-size: 30rpx;
font-weight: 700;
letter-spacing: 2rpx;
line-height: 1.4;
transition: transform 0.15s ease;
}
.submit-btn::after,
.page-retry::after {
border: none;
}
.submit-btn:active {
transform: scale(0.98);
}
.page-state {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
box-sizing: border-box;
min-height: 70vh;
padding: 48rpx 32rpx;
}
.page-state-text {
color: var(--muted);
font-size: 28rpx;
line-height: 1.6;
}
.page-retry {
margin: 28rpx 0 0;
padding: 12rpx 36rpx;
border: 2rpx solid var(--brand-strong);
border-radius: 999rpx;
background: transparent;
color: var(--brand-strong);
font-size: 28rpx;
font-weight: 500;
line-height: 1.5;
}
@media (prefers-reduced-motion: reduce) {
.patient-chip,
.add-profile-tip,
.submit-btn {
transition: none;
}
}
+2 -2
View File
@@ -205,10 +205,10 @@ Page({
});
},
// Hero 主按钮:直达服务列表,缩短「了解 → 下单」路径
// Hero 主按钮:直达立即预约页
goToBooking() {
wx.navigateTo({
url: '/pages/escort/itemlist'
url: '/pages/escort/itemorder'
});
},