feat(hospital-select): 重构医院选择组件与相关样式
- 移除列表/手填切换模式,改为「其他医院」常驻入口内联手填 - 选项行高按放大后的字号重算,搜索框不再自动聚焦 - 服务详情、预约表单与相关页面同步 hospitalCustom 状态 - 统一就诊人添加按钮、个人档案、首页与培训页字号样式
This commit is contained in:
@@ -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 })
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user