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;
}