feat(hospital-select): 重构医院选择组件与相关样式

- 移除列表/手填切换模式,改为「其他医院」常驻入口内联手填
- 选项行高按放大后的字号重算,搜索框不再自动聚焦
- 服务详情、预约表单与相关页面同步 hospitalCustom 状态
- 统一就诊人添加按钮、个人档案、首页与培训页字号样式
This commit is contained in:
lik
2026-11-05 18:55:13 +08:00
parent 67157fa919
commit f70a8f8b72
9 changed files with 167 additions and 165 deletions
+26 -38
View File
@@ -1,6 +1,7 @@
// 医院选择:列表可搜索(名称 / 主体名 / 全拼 / 拼音首字母),找不到时可手动输入
// 医院选择:列表可搜索(名称 / 主体名 / 全拼 / 拼音首字母);列表里没有的走「其他医院」手填
const SEARCH_PLACEHOLDER = '搜索医院名称或拼音'
const OPTION_HEIGHT = 112
// 单行选项高度:字号放大后重新核算(名称 32rpx + 地址 28rpx + 上下留白)
const OPTION_HEIGHT = 132
// 关键词去掉空白、转小写:中文原样匹配,拼音统一小写比较
const normalizeKeyword = (value) => String(value || '').trim().toLowerCase().replace(/\s+/g, '')
@@ -22,14 +23,6 @@ Component({
properties: {
label: { type: String, value: '就诊医院' },
value: { type: String, value: '' },
manual: {
type: Boolean,
value: false,
observer() {
// 父级切换手动/列表模式时收起面板,避免两种形态叠在一起
if (this.data.open) this.setData({ open: false, keyword: '', optionsHeight: 0 })
},
},
options: {
type: Array,
value: [],
@@ -47,6 +40,8 @@ Component({
keyword: '',
filtered: [],
optionsHeight: 0,
manualEntry: false,
manualName: '',
searchPlaceholder: SEARCH_PLACEHOLDER,
},
@@ -67,17 +62,17 @@ Component({
},
onOpen() {
if (this.data.disabled || this.data.manual) return
if (this.data.disabled) return
if (this.data.open) {
this.onClose()
return
}
this.setData({ open: true, keyword: '' })
this.setData({ open: true, keyword: '', manualEntry: false })
this.refreshFiltered(this.data.options, '')
},
onClose() {
this.setData({ open: false, keyword: '', optionsHeight: 0 })
this.setData({ open: false, keyword: '', optionsHeight: 0, manualEntry: false })
},
onKeywordInput(e) {
@@ -100,34 +95,27 @@ Component({
})
},
// 搜索词没有匹配时,直接把当前输入当作医院名,转入手动输入
onUseKeyword() {
const name = String(this.data.keyword || '').trim()
// 「其他医院」:展开手填输入框;有搜索词时带入搜索词,否则带入当前已填名称
onStartManual() {
const keyword = String(this.data.keyword || '').trim()
const current = String(this.data.value || '').trim()
this.setData({ manualEntry: true, manualName: keyword || current })
},
onManualNameInput(e) {
this.setData({ manualName: e.detail.value })
},
onCancelManual() {
this.setData({ manualEntry: false, manualName: '' })
},
onConfirmManual() {
const name = String(this.data.manualName || '').trim()
if (!name) return
this.onClose()
this.triggerEvent('change', { name, manual: true, hospital: null })
},
onManualInput(e) {
this.triggerEvent('change', { name: e.detail.value, manual: true, hospital: null })
},
onToggleManual() {
if (this.data.disabled) return
if (!this.data.manual) {
this.onClose()
this.triggerEvent('change', { name: this.data.value || '', manual: true, hospital: null })
return
}
// 从手动切回列表:当前值能在列表里找到就还原选中,否则清空
const value = String(this.data.value || '').trim()
const matched = (this.data.options || []).find((item) => item.name === value)
this.onClose()
this.triggerEvent('change', matched
? { name: matched.name, manual: false, hospital: matched }
: { name: '', manual: false, hospital: null })
},
},
})
+23 -22
View File
@@ -1,41 +1,43 @@
<view class="hospital-select {{compact ? 'is-compact' : ''}} {{disabled ? 'is-disabled' : ''}}">
<view class="hospital-row">
<view class="hospital-label-wrap">
<text class="hospital-label">{{label}}</text>
<text class="hospital-mode" catchtap="onToggleManual">{{manual ? '从列表选择' : '手动输入'}}</text>
</view>
<input
wx:if="{{manual}}"
class="hospital-input"
value="{{value}}"
placeholder="{{placeholder}}"
placeholder-class="hospital-placeholder"
disabled="{{disabled}}"
bindinput="onManualInput"
/>
<view wx:else class="hospital-value" bindtap="onOpen">
<text class="hospital-label">{{label}}</text>
<view class="hospital-value" bindtap="onOpen">
<text class="hospital-value-text {{value ? '' : 'is-placeholder'}}">{{value || placeholder}}</text>
<view class="hospital-chevron {{open ? 'is-open' : ''}}"></view>
</view>
</view>
<view class="hospital-panel" wx:if="{{open && !manual}}">
<view class="hospital-panel" wx:if="{{open}}">
<view class="hospital-search">
<input
class="hospital-search-input"
value="{{keyword}}"
placeholder="{{searchPlaceholder}}"
placeholder-class="hospital-placeholder"
focus="{{open}}"
confirm-type="search"
bindinput="onKeywordInput"
/>
<text class="hospital-search-close" bindtap="onClose">收起</text>
</view>
<!-- 填写其他医院:列表里没有的医院走这里 -->
<view wx:if="{{manualEntry}}" class="hospital-manual-panel">
<input
class="hospital-manual-input"
value="{{manualName}}"
placeholder="请输入医院名称"
placeholder-class="hospital-placeholder"
focus="{{manualEntry}}"
confirm-type="done"
bindinput="onManualNameInput"
bindconfirm="onConfirmManual"
/>
<text class="hospital-manual-confirm" catchtap="onConfirmManual">确定</text>
<text class="hospital-manual-cancel" catchtap="onCancelManual">返回列表</text>
</view>
<scroll-view
wx:if="{{filtered.length > 0}}"
wx:elif="{{filtered.length > 0}}"
class="hospital-options"
scroll-y
style="height: {{optionsHeight}}rpx;"
@@ -57,12 +59,11 @@
<view wx:else class="hospital-empty">
<text class="hospital-empty-text">{{keyword ? '没有找到匹配的医院' : '暂无可选医院'}}</text>
<text class="hospital-use-input" wx:if="{{keyword}}" bindtap="onUseKeyword">使用「{{keyword}}」</text>
<text class="hospital-use-input" wx:else bindtap="onToggleManual">手动输入</text>
</view>
<view class="hospital-panel-footer" wx:if="{{keyword && filtered.length > 0}}">
<text class="hospital-use-input" bindtap="onUseKeyword">没有找到?使用「{{keyword}}」</text>
<!-- 其他医院:常驻入口,不用先搜出空结果才找得到 -->
<view wx:if="{{!manualEntry}}" class="hospital-other" bindtap="onStartManual">
<text class="hospital-other-text">其他医院(列表里没有?手动填写名称)</text>
</view>
</view>
</view>
+66 -58
View File
@@ -16,34 +16,18 @@
opacity: 0.6;
}
.hospital-label-wrap {
display: flex;
flex-direction: column;
align-items: flex-start;
flex-shrink: 0;
}
/* 行标签与取值统一 30rpx,与页面表单(.order-label / .order-value)同档 */
.hospital-label {
color: var(--muted, #6F655C);
font-size: var(--fs-28, 28rpx);
font-size: var(--fs-30, 30rpx);
letter-spacing: 1rpx;
}
/* compact 档用于「预约记录 · 编辑」表单,跟该页 .form-label(26) / .form-input(28) 对齐 */
.is-compact .hospital-label {
font-size: var(--fs-26, 26rpx);
}
.hospital-mode {
margin-top: 6rpx;
color: var(--brand-ink, #9B4508);
font-size: var(--fs-24, 24rpx);
line-height: 1.4;
}
.hospital-mode:active {
opacity: 0.6;
}
.hospital-value {
display: flex;
flex: 1;
@@ -57,7 +41,7 @@
min-width: 0;
overflow: hidden;
color: var(--ink, #2B2521);
font-size: var(--fs-28, 28rpx);
font-size: var(--fs-30, 30rpx);
font-weight: 700;
text-align: right;
text-overflow: ellipsis;
@@ -65,6 +49,7 @@
}
.is-compact .hospital-value-text {
font-size: var(--fs-28, 28rpx);
font-weight: 400;
}
@@ -73,20 +58,55 @@
font-weight: 400;
}
.hospital-input {
flex: 1;
min-width: 0;
margin-left: 24rpx;
color: var(--ink, #2B2521);
font-size: var(--fs-28, 28rpx);
text-align: right;
}
.hospital-placeholder {
color: var(--muted, #6F655C);
font-weight: 400;
}
/* 「其他医院」:面板底部常驻入口,展开手填输入框 */
.hospital-other {
margin-top: 16rpx;
padding: 20rpx 0;
border-top: 2rpx solid var(--sep, #E5DACC);
text-align: center;
}
.hospital-other-text {
color: var(--brand-ink, #9B4508);
font-size: var(--fs-30, 30rpx);
}
.hospital-other:active {
opacity: 0.6;
}
.hospital-manual-panel {
display: flex;
align-items: center;
padding: 20rpx 0 8rpx;
}
.hospital-manual-input {
flex: 1;
min-width: 0;
color: var(--ink, #2B2521);
font-size: var(--fs-30, 30rpx);
}
.hospital-manual-confirm {
flex-shrink: 0;
margin-left: 16rpx;
color: var(--brand-ink, #9B4508);
font-size: var(--fs-30, 30rpx);
}
.hospital-manual-cancel {
flex-shrink: 0;
margin-left: 16rpx;
color: var(--muted, #6F655C);
font-size: var(--fs-28, 28rpx);
}
.hospital-chevron {
flex-shrink: 0;
width: 16rpx;
@@ -102,32 +122,34 @@
transform: rotate(-135deg);
}
/* 展开面板直接铺在表单卡片上:去掉嵌套边框与内缩,列表横向更宽 */
/* 展开面板:浅橙衬底 + 2rpx 浅橙描边托形,与白卡拉开边界(不用阴影) */
.hospital-panel {
margin: 0;
padding: 0;
background: transparent;
margin: 12rpx 0 24rpx;
padding: 0 20rpx 20rpx;
border: 2rpx solid var(--brand-line, #FFE0C2);
border-radius: 20rpx;
background: var(--brand-soft, #FFF4E8);
}
.hospital-search {
display: flex;
align-items: center;
padding: 8rpx 0 12rpx;
border-bottom: 2rpx solid var(--line, #ECE3D6);
border-bottom: 2rpx solid var(--sep, #E5DACC);
}
.hospital-search-input {
flex: 1;
min-width: 0;
color: var(--ink, #2B2521);
font-size: var(--fs-26, 26rpx);
font-size: var(--fs-30, 30rpx);
}
.hospital-search-close {
flex-shrink: 0;
margin-left: 16rpx;
color: var(--muted, #6F655C);
font-size: var(--fs-24, 24rpx);
font-size: var(--fs-28, 28rpx);
}
.hospital-search-close:active {
@@ -143,7 +165,7 @@
align-items: center;
justify-content: space-between;
padding: 16rpx 0;
border-bottom: 2rpx solid var(--line, #ECE3D6);
border-bottom: 2rpx solid var(--sep, #E5DACC);
}
.hospital-option:last-child {
@@ -151,7 +173,7 @@
}
.hospital-option:active {
background: var(--brand-soft, #FFF4E8);
background: var(--white, #FFFFFF);
}
.hospital-option-main {
@@ -162,21 +184,22 @@
.hospital-option-name {
display: block;
color: var(--ink, #2B2521);
font-size: var(--fs-28, 28rpx);
font-size: var(--fs-30, 30rpx);
font-weight: 700;
line-height: 1.4;
word-break: break-all;
}
/* compact 档跟该页 .form-input(28rpx) 对齐 */
.is-compact .hospital-option-name {
font-size: var(--fs-26, 26rpx);
font-size: var(--fs-28, 28rpx);
}
.hospital-option-sub {
display: block;
margin-top: 6rpx;
color: var(--muted, #6F655C);
font-size: var(--fs-24, 24rpx);
font-size: var(--fs-26, 26rpx);
line-height: 1.4;
word-break: break-all;
}
@@ -185,7 +208,7 @@
flex-shrink: 0;
margin-left: 16rpx;
color: var(--brand-ink, #9B4508);
font-size: var(--fs-24, 24rpx);
font-size: var(--fs-26, 26rpx);
}
.hospital-empty {
@@ -196,21 +219,6 @@
.hospital-empty-text {
display: block;
color: var(--muted, #6F655C);
font-size: var(--fs-26, 26rpx);
font-size: var(--fs-30, 30rpx);
}
.hospital-use-input {
display: inline-block;
margin-top: 12rpx;
color: var(--brand-ink, #9B4508);
font-size: var(--fs-26, 26rpx);
}
.hospital-use-input:active {
opacity: 0.6;
}
.hospital-panel-footer {
padding-top: 12rpx;
text-align: center;
}
+13 -12
View File
@@ -21,7 +21,7 @@ Page({
provinces: [],
hospital: '',
hospitalOptions: [],
hospitalManual: false,
hospitalCustom: false,
appointmentDate: '',
appointmentTime: '',
minAppointmentDate: '',
@@ -66,12 +66,10 @@ Page({
}
this.applyBookingConfig(service)
// 启动时 app 已在预取医院;这里等它落定后刷新下拉,失败则退回手动输入
// 启动时 app 已在预取医院;这里等它落定后刷新下拉,
// 列表为空时组件内的「其他医院」入口仍可手填
getApp().loadHospitals().then(() => {
this.refreshHospitalOptions()
if (!this.data.hospitalOptions.length && !this.data.hospitalManual) {
this.setData({ hospitalManual: true })
}
})
const serviceView = {
...service,
@@ -129,7 +127,7 @@ Page({
province: provinces[0] || '',
provinceIndex: 0,
hospital: '',
hospitalManual: false,
hospitalCustom: false,
requiresAddress: !!booking.requiresAddress
}, () => this.refreshHospitalOptions(provinces[0] || ''))
},
@@ -234,7 +232,7 @@ Page({
provinceIndex: index,
province,
hospital: '',
hospitalManual: false
hospitalCustom: false
}, () => this.refreshHospitalOptions(province))
},
@@ -243,7 +241,8 @@ Page({
const hospitalOptions = getApp().getHospitalsByProvince(province)
let hospital = ''
if (this.data.hospitalManual) {
if (this.data.hospitalCustom) {
// 「其他医院」手填的名称不在库内,刷新列表时原样保留
hospital = this.data.hospital
} else {
const selected = hospitalOptions.find((item) => item._id === this.selectedHospitalId)
@@ -258,11 +257,11 @@ Page({
this.setData({ hospitalOptions, hospital })
},
// 医院选择组件回传:name 为最终值,manual 表示是否手动输入,hospital 为库内记录
// 医院选择组件回传:name 为最终值,manual 表示是否为「其他医院」手填,hospital 为库内记录
onHospitalChange(e) {
const { name, manual, hospital } = e.detail
this.selectedHospitalId = hospital?._id || ''
this.setData({ hospital: name, hospitalManual: manual })
this.setData({ hospital: name, hospitalCustom: manual })
},
onDateChange(e) {
@@ -295,7 +294,9 @@ Page({
validateOrder() {
const data = this.data
if (!data.selectedProfileId || !data.selectedPatient) return '请选择就诊人'
if (!data.hospital.trim()) return data.hospitalManual ? '请输入就诊医院' : '请选择就诊医院'
if (!data.hospital.trim()) {
return data.hospitalOptions.length ? '请选择就诊医院' : '请填写就诊医院名称'
}
if (!data.appointmentDate) return '请选择预约日期'
if (!data.appointmentTime) return '请选择预约时间'
if (data.requiresAddress && !data.shippingAddress.trim()) return '请填写完整收货地址'
@@ -362,7 +363,7 @@ Page({
province: provinces[0] || '',
provinceIndex: 0,
hospital: '',
hospitalManual: false,
hospitalCustom: false,
appointmentDate: '',
appointmentTime: '',
sessionIndex: 0,
+3 -4
View File
@@ -115,10 +115,10 @@
<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 class="patient-chip patient-chip-add" bindtap="goToAddProfile" aria-role="button" aria-label="增加就诊人">
<t-icon name="add" size="28rpx" color="#9B4508" />
<text class="patient-chip-name">增加</text>
</view>
</view>
</scroll-view>
@@ -154,7 +154,6 @@
<hospital-select
label="就诊医院"
value="{{hospital}}"
manual="{{hospitalManual}}"
options="{{hospitalOptions}}"
placeholder="请选择就诊医院"
disabled="{{submitting}}"
+20 -17
View File
@@ -463,7 +463,7 @@ page {
.order-service-title {
display: block;
font-size: var(--fs-30);
font-size: var(--fs-32);
font-weight: 700;
color: var(--ink);
line-height: 1.4;
@@ -499,7 +499,7 @@ page {
.order-label {
flex-shrink: 0;
font-size: var(--fs-28);
font-size: var(--fs-30);
color: var(--muted);
letter-spacing: 1rpx;
}
@@ -509,7 +509,7 @@ page {
min-width: 0;
margin-left: 24rpx;
text-align: right;
font-size: var(--fs-28);
font-size: var(--fs-30);
font-weight: 700;
color: var(--ink);
}
@@ -525,7 +525,7 @@ page {
min-width: 0;
margin-left: 24rpx;
text-align: right;
font-size: var(--fs-28);
font-size: var(--fs-30);
font-weight: 700;
color: var(--ink);
}
@@ -545,7 +545,7 @@ page {
.picker-value {
display: block;
text-align: right;
font-size: var(--fs-28);
font-size: var(--fs-30);
font-weight: 700;
color: var(--ink);
}
@@ -565,7 +565,7 @@ page {
border-radius: 12rpx;
background: var(--paper);
border: 2rpx solid var(--line);
font-size: var(--fs-28);
font-size: var(--fs-30);
color: var(--ink);
line-height: 1.5;
}
@@ -573,14 +573,14 @@ page {
.textarea-count {
align-self: flex-end;
margin-top: 10rpx;
font-size: var(--fs-24);
font-size: var(--fs-26);
color: var(--muted);
}
.address-tip {
align-self: flex-start;
margin-top: 10rpx;
font-size: var(--fs-24);
font-size: var(--fs-26);
color: var(--muted);
line-height: 1.6;
}
@@ -600,7 +600,9 @@ page {
.patient-chip {
display: inline-flex;
flex-direction: column;
min-width: 180rpx;
align-items: center;
justify-content: center;
min-width: 140rpx;
padding: 16rpx 24rpx;
border-radius: 16rpx;
background: var(--paper);
@@ -620,7 +622,7 @@ page {
}
.patient-chip-name {
font-size: var(--fs-26);
font-size: var(--fs-28);
font-weight: 700;
color: var(--ink-2);
}
@@ -629,14 +631,15 @@ page {
color: var(--brand-ink);
}
.patient-chip-phone {
margin-top: 6rpx;
font-size: var(--fs-26);
color: var(--ink-2);
}
.patient-chip-add {
flex-direction: row;
align-items: center;
justify-content: center;
gap: 4rpx;
/* 虚线描边 + 白底:与「已选就诊人」的实心浅橙底区分开,
一眼看出这是动作入口而不是某个就诊人 */
background: var(--white);
border: 2rpx dashed var(--brand-line);
}
.patient-chip-add .patient-chip-name {
@@ -665,7 +668,7 @@ page {
flex: 1;
min-width: 0;
margin-right: 8rpx;
font-size: var(--fs-24);
font-size: var(--fs-26);
font-weight: 700;
color: var(--brand-ink);
}
+6 -6
View File
@@ -54,7 +54,7 @@ page {
margin-top: 24rpx;
}
/* 行高约 87rpx(28rpx×1.4 + 上下 24rpx),贴近 iOS 44pt 触控目标 */
/* 行高约 90rpx(30rpx×1.4 + 上下 24rpx),贴近 iOS 44pt 触控目标 */
.form-row {
display: flex;
flex-wrap: wrap;
@@ -82,7 +82,7 @@ page {
.form-label {
flex-shrink: 0;
margin-right: 24rpx;
font-size: var(--fs-28);
font-size: var(--fs-30);
color: var(--muted);
letter-spacing: 1rpx;
}
@@ -91,7 +91,7 @@ page {
flex: 1;
min-width: 0;
text-align: right;
font-size: var(--fs-28);
font-size: var(--fs-30);
font-weight: 700;
color: var(--ink);
}
@@ -110,7 +110,7 @@ page {
.picker-value {
display: block;
text-align: right;
font-size: var(--fs-28);
font-size: var(--fs-30);
font-weight: 700;
color: var(--ink);
}
@@ -140,7 +140,7 @@ page {
}
.sex-text {
font-size: var(--fs-28);
font-size: var(--fs-30);
color: var(--muted);
}
@@ -165,7 +165,7 @@ page {
width: 100%;
height: 160rpx;
margin-top: 16rpx;
font-size: var(--fs-28);
font-size: var(--fs-30);
color: var(--ink);
line-height: 1.6;
}
+8 -7
View File
@@ -250,8 +250,9 @@ page {
.promo-btn-text {
margin-right: 4rpx;
/* 28rpx / 14px:按钮字不再是"看不清的附属小字",与正文同级 */
font-size: var(--fs-28);
/* 24rpx / 12px:按钮字收小一档,让「了解详情」退回附属提示的层级,
不与左侧标题争夺首屏注意力 */
font-size: var(--fs-24);
font-weight: 700;
color: var(--brand-ink);
letter-spacing: 1rpx;
@@ -485,7 +486,7 @@ page {
次级层级靠 --ink-2 的色阶表达,不用半档字重 */
.assist-name {
font-size: var(--fs-30);
font-weight: 400;
font-weight: 700;
color: var(--ink-2);
/* 行高 1.5:字号 32→30 会让这一行的盒高少 2.8rpx,
用 1.5 把盒高补回 45rpx(≈改前 32rpx × normal),
@@ -564,12 +565,12 @@ page {
}
.quick-name {
/* 30rpx / 15px:文字区约 179rpx,最长「预约记录」4 字 120rpx 仍单行。
与宫格项名同档 30rpx,但这里是卡名(可点入口),走 700 与 400 拉开 */
font-size: var(--fs-30);
/* 32rpx / 16px:卡名放大一号,作为可点入口的主标签。
文字区约 179rpx,最长「预约记录」4 字 128rpx 仍单行 */
font-size: var(--fs-32);
font-weight: 700;
color: var(--ink);
/* 行高 1.5:字号 32→30 少 2.8rpx,用行高补回,卡片高度与历史版本一致 */
/* 行高 1.5:放大后靠行高补回视觉高度,卡片整体高度与历史版本一致 */
line-height: 1.5;
}
+2 -1
View File
@@ -23,7 +23,8 @@
font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Microsoft YaHei', sans-serif;
-webkit-font-smoothing: antialiased;
--t-display: 88rpx;
/* 72rpx:价格数字收小一号(原 88rpx),避免大号数字压过卡片信息 */
--t-display: 72rpx;
--t-h1: 44rpx;
/* 36rpx 及以上不参与全局字号令牌(大字模式不放大),保持字面量 */
--t-h2: 36rpx;