diff --git a/components/hospital-select/index.js b/components/hospital-select/index.js index cf99e6b..095be26 100644 --- a/components/hospital-select/index.js +++ b/components/hospital-select/index.js @@ -1,7 +1,5 @@ // 医院选择:列表可搜索(名称 / 主体名 / 全拼 / 拼音首字母);列表里没有的走「其他医院」手填 const SEARCH_PLACEHOLDER = '搜索医院名称或拼音' -// 单行选项高度:字号放大后重新核算(名称 32rpx + 地址 28rpx + 上下留白) -const OPTION_HEIGHT = 132 // 关键词去掉空白、转小写:中文原样匹配,拼音统一小写比较 const normalizeKeyword = (value) => String(value || '').trim().toLowerCase().replace(/\s+/g, '') @@ -33,19 +31,14 @@ Component({ placeholder: { type: String, value: '请选择就诊医院' }, disabled: { type: Boolean, value: false }, compact: { type: Boolean, value: false }, - // 默认由组件自己上滚页面;放在弹窗内的 scroll-view 时, - // 页面滚动无法带动弹窗内容,需置 false 交给页面做容器内滚动 - autoPageScroll: { type: Boolean, value: true }, - // 展开面板上滚时,医院行锚定到距页面顶部的距离(rpx); - // 传入上方行的总高度,可让「就诊人姓名」等上一行滚到页面顶部 - scrollAnchorOffset: { type: Number, value: 0 }, }, data: { open: false, keyword: '', filtered: [], - optionsHeight: 0, + panelHeight: 0, + keyboardHeight: 0, manualEntry: false, manualName: '', searchPlaceholder: SEARCH_PLACEHOLDER, @@ -60,11 +53,7 @@ Component({ methods: { refreshFiltered(options = this.data.options, keyword = this.data.keyword) { const filtered = filterHospitals(options, keyword) - const visibleRows = Math.min(filtered.length, 6) - this.setData({ - filtered, - optionsHeight: visibleRows * OPTION_HEIGHT, - }) + this.setData({ filtered }) }, onOpen() { @@ -73,43 +62,24 @@ Component({ this.onClose() return } - this.setData({ open: true, keyword: '', manualEntry: false }) + this.windowHeight = wx.getWindowInfo ? wx.getWindowInfo().windowHeight : wx.getSystemInfoSync().windowHeight + this.setData({ open: true, keyword: '', manualEntry: false, keyboardHeight: 0, + panelHeight: Math.floor(this.windowHeight * 0.82) }) this.refreshFiltered(this.data.options, '') - // 页面可监听 open 事件,在自定义滚动容器内做定位 this.triggerEvent('open') - if (!this.data.autoPageScroll) return - // 面板展开后若被页面底部遮挡,自动上滚页面,保证下拉列表完整可见 - wx.nextTick(() => this.scrollPanelIntoView()) - }, - - scrollPanelIntoView() { - const query = this.createSelectorQuery() - query.select('.hospital-row').boundingClientRect() - query.select('.hospital-panel').boundingClientRect() - query.selectViewport().scrollOffset() - query.exec((res) => { - const rowRect = res && res[0] - const panelRect = res && res[1] - const scroll = res && res[2] - if (!rowRect || !scroll) return - const rpx = wx.getSystemInfoSync().windowWidth / 750 - const margin = 20 - // 目标1:医院行上滚到距顶部 scrollAnchorOffset 处(默认页面顶部) - let delta = rowRect.top - this.data.scrollAnchorOffset * rpx - // 目标2:面板完整可见,两者取滚动量更大的一方 - if (panelRect) { - delta = Math.max(delta, panelRect.bottom + margin - wx.getSystemInfoSync().windowHeight) - } - if (Math.abs(delta) < 1) return - wx.pageScrollTo({ - scrollTop: scroll.scrollTop + delta, - duration: 300, - }) - }) }, onClose() { - this.setData({ open: false, keyword: '', optionsHeight: 0, manualEntry: false }) + this.setData({ open: false, keyword: '', keyboardHeight: 0, manualEntry: false }) + wx.hideKeyboard() + this.triggerEvent('close') + }, + + onKeyboardHeightChange(e) { + if (!this.data.open) return + const keyboardHeight = Math.max(0, Number(e.detail.height) || 0) + const available = Math.max(0, this.windowHeight - keyboardHeight) + this.setData({ keyboardHeight, panelHeight: Math.floor(Math.min(this.windowHeight * 0.82, available)) }) }, // 遮罩占位:catchtouchmove 阻止穿透滚动页面 @@ -148,9 +118,12 @@ Component({ onCancelManual() { this.setData({ manualEntry: false, manualName: '' }) + this.onKeyboardHeightChange({ detail: { height: 0 } }) + wx.hideKeyboard() }, onConfirmManual() { + if (this.data.disabled) return const name = String(this.data.manualName || '').trim() if (!name) return diff --git a/components/hospital-select/index.wxml b/components/hospital-select/index.wxml index 593ba72..699561c 100644 --- a/components/hospital-select/index.wxml +++ b/components/hospital-select/index.wxml @@ -1,73 +1,46 @@ - - - - + + {{label}} - + {{value || placeholder}} - - - - - - - - - - - - - - - - 确定 - 返回列表 - - - - - - {{item.name}} - {{item.address}} - - 已选 - - - - - {{keyword ? '没有找到匹配的医院' : '暂无可选医院'}} - - - - - 其他医院(列表里没有?手动填写名称) + + + + + + + + {{manualEntry ? '手动填写医院' : '选择医院'}} + + + + + + + + + + + + + + + + + + + {{item.name}} + {{item.address}} + + + + {{keyword ? '没有找到匹配的医院' : '暂无可选医院'}} + + 手动填写医院 + + + + \ No newline at end of file diff --git a/components/hospital-select/index.wxss b/components/hospital-select/index.wxss index 87e45b1..977f4d2 100644 --- a/components/hospital-select/index.wxss +++ b/components/hospital-select/index.wxss @@ -1,268 +1,38 @@ -/* 医院选择:行结构与页面表单保持一致,展开面板作为行内下拉 */ -/* 展开时整组件抬到遮罩之上:遮罩盖住页面其余内容(含底部栏 100),面板仍可点 */ -.hospital-select.is-open { - position: relative; - z-index: 151; -} - -/* 展开遮罩:浅墨半透明,点击任意空白处收起;层级低于页面支付弹窗(200/201) */ -.hospital-mask { - position: fixed; - top: 0; - right: 0; - bottom: 0; - left: 0; - z-index: 1; - background: rgba(43, 37, 33, 0.3); -} - -/* 展开时行与面板抬到遮罩之上(同属 .is-open 层叠上下文,仅内部比较) */ -.hospital-select.is-open .hospital-row, -.hospital-select.is-open .hospital-panel { - position: relative; - z-index: 2; -} - -.hospital-row { - display: flex; - align-items: center; - justify-content: space-between; - padding: 24rpx 0; - border-bottom: 2rpx solid var(--line); -} - -.is-compact .hospital-row { - min-height: 72rpx; - padding: 12rpx 0; -} - -.is-disabled { - opacity: 0.6; -} - -/* 行标签与取值统一 30rpx,与页面表单(.order-label / .order-value)同档。 - 标签走裸字 muted:表单里浅橙底只留给可选项,标签不冒充控件 - (与 itemorder / itemdetail 的 .order-label、health/profileedit 的标签同一口径) */ -.hospital-label { - flex-shrink: 0; - color: var(--muted, #6F655C); - font-size: var(--fs-30, 30rpx); - letter-spacing: 1rpx; -} - -/* compact 档用于「预约记录 · 编辑」表单,跟该页 .form-label(28) / .form-input(30) 对齐 */ -.is-compact .hospital-label { - font-size: var(--fs-28, 28rpx); -} - -.hospital-value { - display: flex; - flex: 1; - min-width: 0; - align-items: center; - justify-content: flex-end; - margin-left: 24rpx; -} - -.hospital-value-text { - min-width: 0; - overflow: hidden; - color: var(--ink, #2B2521); - font-size: var(--fs-30, 30rpx); - font-weight: 700; - text-align: right; - text-overflow: ellipsis; - white-space: nowrap; -} - -.is-compact .hospital-value-text { - font-weight: 400; -} - -.hospital-value-text.is-placeholder { - color: var(--muted, #6F655C); - font-weight: 400; -} - -.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; - box-sizing: border-box; - padding: 16rpx 20rpx; - color: var(--ink, #2B2521); - font-size: var(--fs-30, 30rpx); - /* 字段填充走暖白纸面 + 发丝边(与 .order-textarea 同款);原 #E6F4EA 是旧绿主题残留 */ - background: var(--paper); - border: 2rpx solid var(--line); - border-radius: 12rpx; -} - -.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; - height: 16rpx; - margin-left: 16rpx; - border-right: 2rpx solid var(--muted, #6F655C); - border-bottom: 2rpx solid var(--muted, #6F655C); - transform: rotate(45deg); - transition: transform 0.2s ease; -} - -.hospital-chevron.is-open { - transform: rotate(-135deg); -} - -/* 展开面板:白底 + 2rpx 浅橙描边托形,与白卡靠橙边区分(不用阴影) */ -.hospital-panel { - margin: 12rpx 0 24rpx; - padding: 0 20rpx 20rpx; - border: 2rpx solid var(--brand-line, #FFE0C2); - border-radius: 20rpx; - background: var(--white, #FFFFFF); -} - -.hospital-search { - display: flex; - align-items: center; - padding: 8rpx 0 12rpx; - border-bottom: 2rpx solid var(--sep, #E5DACC); -} - -.hospital-search-input { - flex: 1; - min-width: 0; - box-sizing: border-box; - padding: 16rpx 20rpx; - color: var(--ink, #2B2521); - font-size: var(--fs-30, 30rpx); - /* 字段填充走暖白纸面 + 发丝边(与 .order-textarea 同款);原 #E6F4EA 是旧绿主题残留 */ - background: var(--paper); - border: 2rpx solid var(--line); - border-radius: 12rpx; -} - -/* 收起按钮:上箭头图标(CSS 边框三角,不依赖字体图标),留足点击热区 */ -.hospital-search-close { - display: flex; - flex-shrink: 0; - align-items: center; - justify-content: center; - margin-left: 16rpx; - padding: 12rpx; -} - -.hospital-collapse-arrow { - width: 20rpx; - height: 20rpx; - border-top: 4rpx solid var(--brand-ink, #9B4508); - border-right: 4rpx solid var(--brand-ink, #9B4508); - transform: rotate(-45deg); -} - -.hospital-search-close:active { - opacity: 0.6; -} - -.hospital-options { - margin-top: 0; -} - -.hospital-option { - display: flex; - align-items: center; - justify-content: space-between; - padding: 16rpx 0; - border-bottom: 2rpx solid var(--sep, #E5DACC); -} - -.hospital-option:last-child { - border-bottom: none; -} - -.hospital-option:active { - background: var(--brand-soft, #FFF4E8); -} - -.hospital-option-main { - flex: 1; - min-width: 0; -} - -.hospital-option-name { - display: block; - color: var(--ink, #2B2521); - font-size: var(--fs-30, 30rpx); - font-weight: 700; - line-height: 1.4; - word-break: break-all; -} - -.hospital-option-sub { - display: block; - margin-top: 6rpx; - color: var(--muted, #6F655C); - font-size: var(--fs-26, 26rpx); - line-height: 1.4; - word-break: break-all; -} - -.hospital-option-selected { - flex-shrink: 0; - margin-left: 16rpx; - color: var(--brand-ink, #9B4508); - font-size: var(--fs-26, 26rpx); -} - -.hospital-empty { - padding: 32rpx 0; - text-align: center; -} - -.hospital-empty-text { - display: block; - color: var(--muted, #6F655C); - font-size: var(--fs-30, 30rpx); -} - +/* 普通表单行;浮层由 root-portal 挂到页面根部,不撑开原表单。 */ +.hospital-row { display: flex; align-items: center; justify-content: space-between; box-sizing: border-box; min-height: 100rpx; padding: 24rpx 0; border-bottom: 2rpx solid var(--line, #ECE3D6); } +.is-compact .hospital-row { min-height: 88rpx; padding: 20rpx 0; } +.is-disabled { opacity: 0.6; } +.hospital-label { flex-shrink: 0; color: var(--muted, #6F655C); font-size: var(--fs-30, 30rpx); letter-spacing: 1rpx; line-height: 1.6; } +.is-compact .hospital-label { font-size: var(--fs-28, 28rpx); } +.hospital-value { display: flex; flex: 1; min-width: 0; align-items: center; justify-content: flex-end; gap: 12rpx; margin-left: 24rpx; } +.hospital-value-text { min-width: 0; color: var(--ink, #2B2521); font-size: var(--fs-30, 30rpx); font-weight: 500; text-align: right; line-height: 1.6; word-break: break-all; } +.hospital-value-text.is-placeholder, .hospital-placeholder { color: var(--muted, #6F655C); font-weight: 400; } +.hospital-chevron { flex-shrink: 0; width: 16rpx; height: 16rpx; border-right: 2rpx solid var(--muted, #6F655C); border-bottom: 2rpx solid var(--muted, #6F655C); transform: rotate(45deg); } +.hospital-overlay { position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 1000; color: var(--ink, #2B2521); } +.hospital-mask { position: absolute; top: 0; right: 0; bottom: 0; left: 0; background: rgba(43, 37, 33, 0.3); } +.hospital-panel { position: absolute; left: 0; right: 0; display: flex; flex-direction: column; box-sizing: border-box; padding-bottom: env(safe-area-inset-bottom); border-radius: 32rpx 32rpx 0 0; background: var(--white, #FFFFFF); overflow: hidden; } +.hospital-panel.keyboard-open { padding-bottom: 0; } +.hospital-heading { display: flex; align-items: center; justify-content: space-between; flex-shrink: 0; min-height: 104rpx; padding: 0 20rpx 0 32rpx; } +.hospital-title { font-size: var(--fs-32, 32rpx); font-weight: 600; line-height: 1.5; } +.hospital-close { display: flex; align-items: center; justify-content: center; width: 88rpx; height: 88rpx; } +.close-mark { position: relative; width: 28rpx; height: 28rpx; } +.close-mark::before, .close-mark::after { content: ''; position: absolute; top: 13rpx; left: 0; width: 28rpx; height: 2rpx; background: var(--muted, #6F655C); transform: rotate(45deg); } +.close-mark::after { transform: rotate(-45deg); } +.hospital-search { flex-shrink: 0; padding: 0 32rpx 16rpx; } +.hospital-search-input, .hospital-manual-input { box-sizing: border-box; width: 100%; height: 88rpx; padding: 16rpx 20rpx; color: var(--ink, #2B2521); font-size: var(--fs-30, 30rpx); border: 2rpx solid var(--line, #ECE3D6); border-radius: 16rpx; background: var(--paper, #FAF8F5); } +.hospital-options { flex: 1; height: 0; min-height: 0; box-sizing: border-box; } +.hospital-option { display: flex; align-items: center; gap: 16rpx; margin: 0 32rpx; padding: 24rpx 0; border-bottom: 2rpx solid var(--line, #ECE3D6); } +.hospital-option:last-child { border-bottom: none; } +.hospital-option:active, .hospital-option.is-selected { background: var(--brand-soft, #FFF4E8); } +.hospital-option-main { flex: 1; min-width: 0; } +.hospital-option-name { display: block; color: var(--ink, #2B2521); font-size: var(--fs-30, 30rpx); font-weight: 500; line-height: 1.5; word-break: break-all; } +.hospital-option-sub { display: block; margin-top: 8rpx; color: var(--muted, #6F655C); font-size: var(--fs-26, 26rpx); line-height: 1.6; word-break: break-all; } +.hospital-option-selected { flex-shrink: 0; width: 20rpx; height: 12rpx; margin: -6rpx 8rpx 0; border-left: 3rpx solid var(--brand-ink, #9B4508); border-bottom: 3rpx solid var(--brand-ink, #9B4508); transform: rotate(-45deg); } +.hospital-empty { padding: 40rpx 32rpx; text-align: center; color: var(--muted, #6F655C); font-size: var(--fs-28, 28rpx); line-height: 1.6; } +.hospital-other { display: flex; align-items: center; justify-content: center; flex-shrink: 0; min-height: 96rpx; border-top: 2rpx solid var(--line, #ECE3D6); color: var(--brand-ink, #9B4508); font-size: var(--fs-30, 30rpx); } +.hospital-manual-panel { flex: 1; min-height: 0; padding: 0 32rpx 24rpx; overflow-y: auto; } +.manual-actions { display: flex; gap: 16rpx; margin-top: 24rpx; } +.manual-actions button[size="default"] { display: flex; align-items: center; justify-content: center; flex: 1; width: auto; min-height: 88rpx; margin: 0; padding: 16rpx; border-radius: 16rpx; font-size: var(--fs-30, 30rpx); line-height: 1.5; } +.manual-back { background: var(--paper, #FAF8F5); color: var(--ink, #2B2521); } +.manual-confirm { background: var(--brand-strong, #B8520A); color: var(--white, #FFFFFF); } +.manual-actions button::after { border: none; } \ No newline at end of file