feat(escort): 医院选择改为可搜索自定义组件
This commit is contained in:
@@ -0,0 +1,132 @@
|
|||||||
|
// 医院选择:列表可搜索(名称 / 主体名 / 全拼 / 拼音首字母),找不到时可手动输入
|
||||||
|
const SEARCH_PLACEHOLDER = '搜索医院名称或拼音'
|
||||||
|
const OPTION_HEIGHT = 112
|
||||||
|
|
||||||
|
// 关键词去掉空白、转小写:中文原样匹配,拼音统一小写比较
|
||||||
|
const normalizeKeyword = (value) => String(value || '').trim().toLowerCase().replace(/\s+/g, '')
|
||||||
|
|
||||||
|
function filterHospitals(options, keyword) {
|
||||||
|
const kw = normalizeKeyword(keyword)
|
||||||
|
if (!kw) return options || []
|
||||||
|
|
||||||
|
return (options || []).filter((item) => [
|
||||||
|
item.name,
|
||||||
|
item.entityName,
|
||||||
|
item.pinyin,
|
||||||
|
item.pinyinFL,
|
||||||
|
].some((field) => normalizeKeyword(field).includes(kw)))
|
||||||
|
}
|
||||||
|
|
||||||
|
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: [],
|
||||||
|
observer(newValue) {
|
||||||
|
this.refreshFiltered(newValue, this.data.keyword)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
placeholder: { type: String, value: '请选择就诊医院' },
|
||||||
|
disabled: { type: Boolean, value: false },
|
||||||
|
compact: { type: Boolean, value: false },
|
||||||
|
},
|
||||||
|
|
||||||
|
data: {
|
||||||
|
open: false,
|
||||||
|
keyword: '',
|
||||||
|
filtered: [],
|
||||||
|
optionsHeight: 0,
|
||||||
|
searchPlaceholder: SEARCH_PLACEHOLDER,
|
||||||
|
},
|
||||||
|
|
||||||
|
lifetimes: {
|
||||||
|
attached() {
|
||||||
|
this.refreshFiltered(this.data.options, '')
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
methods: {
|
||||||
|
refreshFiltered(options = this.data.options, keyword = this.data.keyword) {
|
||||||
|
const filtered = filterHospitals(options, keyword)
|
||||||
|
const visibleRows = Math.min(filtered.length, 4)
|
||||||
|
this.setData({
|
||||||
|
filtered,
|
||||||
|
optionsHeight: visibleRows * OPTION_HEIGHT,
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
onOpen() {
|
||||||
|
if (this.data.disabled || this.data.manual) return
|
||||||
|
if (this.data.open) {
|
||||||
|
this.onClose()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.setData({ open: true, keyword: '' })
|
||||||
|
this.refreshFiltered(this.data.options, '')
|
||||||
|
},
|
||||||
|
|
||||||
|
onClose() {
|
||||||
|
this.setData({ open: false, keyword: '', optionsHeight: 0 })
|
||||||
|
},
|
||||||
|
|
||||||
|
onKeywordInput(e) {
|
||||||
|
const keyword = e.detail.value
|
||||||
|
this.setData({ keyword })
|
||||||
|
this.refreshFiltered(this.data.options, keyword)
|
||||||
|
},
|
||||||
|
|
||||||
|
onSelect(e) {
|
||||||
|
if (this.data.disabled) return
|
||||||
|
const index = Number(e.currentTarget.dataset.index)
|
||||||
|
const hospital = this.data.filtered[index]
|
||||||
|
if (!hospital) return
|
||||||
|
|
||||||
|
this.onClose()
|
||||||
|
this.triggerEvent('change', {
|
||||||
|
name: hospital.name,
|
||||||
|
manual: false,
|
||||||
|
hospital,
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
// 搜索词没有匹配时,直接把当前输入当作医院名,转入手动输入
|
||||||
|
onUseKeyword() {
|
||||||
|
const name = String(this.data.keyword || '').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 })
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"component": true,
|
||||||
|
"usingComponents": {}
|
||||||
|
}
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
<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-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-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>
|
||||||
|
|
||||||
|
<scroll-view
|
||||||
|
wx:if="{{filtered.length > 0}}"
|
||||||
|
class="hospital-options"
|
||||||
|
scroll-y
|
||||||
|
style="height: {{optionsHeight}}rpx;"
|
||||||
|
>
|
||||||
|
<view
|
||||||
|
wx:for="{{filtered}}"
|
||||||
|
wx:key="_id"
|
||||||
|
class="hospital-option"
|
||||||
|
data-index="{{index}}"
|
||||||
|
bindtap="onSelect"
|
||||||
|
>
|
||||||
|
<view class="hospital-option-main">
|
||||||
|
<text class="hospital-option-name">{{item.name}}</text>
|
||||||
|
<text class="hospital-option-sub" wx:if="{{item.address}}">{{item.address}}</text>
|
||||||
|
</view>
|
||||||
|
<text class="hospital-option-selected" wx:if="{{item.name === value}}">已选</text>
|
||||||
|
</view>
|
||||||
|
</scroll-view>
|
||||||
|
|
||||||
|
<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>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
@@ -0,0 +1,218 @@
|
|||||||
|
/* 医院选择:行结构与页面表单保持一致,展开面板作为行内下拉 */
|
||||||
|
.hospital-row {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
padding: 24rpx 0;
|
||||||
|
border-bottom: 2rpx solid var(--line, #ECE3D6);
|
||||||
|
}
|
||||||
|
|
||||||
|
.is-compact .hospital-row {
|
||||||
|
min-height: 72rpx;
|
||||||
|
padding: 12rpx 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.is-disabled {
|
||||||
|
opacity: 0.6;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hospital-label-wrap {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: flex-start;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hospital-label {
|
||||||
|
color: var(--muted, #6F655C);
|
||||||
|
font-size: var(--fs-28, 28rpx);
|
||||||
|
letter-spacing: 1rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.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;
|
||||||
|
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-28, 28rpx);
|
||||||
|
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-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-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);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 展开面板:暖白纸面 + 浅橙描边,与全站二级信息块一致 */
|
||||||
|
.hospital-panel {
|
||||||
|
margin: 12rpx 0 8rpx;
|
||||||
|
padding: 16rpx;
|
||||||
|
border: 2rpx solid var(--brand-line, #FFE0C2);
|
||||||
|
border-radius: 20rpx;
|
||||||
|
background: var(--paper, #FAF8F5);
|
||||||
|
}
|
||||||
|
|
||||||
|
.hospital-search {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
padding-bottom: 12rpx;
|
||||||
|
border-bottom: 2rpx solid var(--line, #ECE3D6);
|
||||||
|
}
|
||||||
|
|
||||||
|
.hospital-search-input {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
color: var(--ink, #2B2521);
|
||||||
|
font-size: var(--fs-26, 26rpx);
|
||||||
|
}
|
||||||
|
|
||||||
|
.hospital-search-close {
|
||||||
|
flex-shrink: 0;
|
||||||
|
margin-left: 16rpx;
|
||||||
|
color: var(--muted, #6F655C);
|
||||||
|
font-size: var(--fs-24, 24rpx);
|
||||||
|
}
|
||||||
|
|
||||||
|
.hospital-search-close:active {
|
||||||
|
opacity: 0.6;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hospital-options {
|
||||||
|
margin-top: 4rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hospital-option {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
padding: 16rpx 4rpx;
|
||||||
|
border-bottom: 2rpx solid var(--line, #ECE3D6);
|
||||||
|
}
|
||||||
|
|
||||||
|
.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-28, 28rpx);
|
||||||
|
font-weight: 700;
|
||||||
|
line-height: 1.4;
|
||||||
|
word-break: break-all;
|
||||||
|
}
|
||||||
|
|
||||||
|
.is-compact .hospital-option-name {
|
||||||
|
font-size: var(--fs-26, 26rpx);
|
||||||
|
}
|
||||||
|
|
||||||
|
.hospital-option-sub {
|
||||||
|
display: block;
|
||||||
|
margin-top: 6rpx;
|
||||||
|
color: var(--muted, #6F655C);
|
||||||
|
font-size: var(--fs-24, 24rpx);
|
||||||
|
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-24, 24rpx);
|
||||||
|
}
|
||||||
|
|
||||||
|
.hospital-empty {
|
||||||
|
padding: 32rpx 0;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hospital-empty-text {
|
||||||
|
display: block;
|
||||||
|
color: var(--muted, #6F655C);
|
||||||
|
font-size: var(--fs-26, 26rpx);
|
||||||
|
}
|
||||||
|
|
||||||
|
.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;
|
||||||
|
}
|
||||||
@@ -20,6 +20,8 @@ Page({
|
|||||||
provinceIndex: 0,
|
provinceIndex: 0,
|
||||||
provinces: [],
|
provinces: [],
|
||||||
hospital: '',
|
hospital: '',
|
||||||
|
hospitalOptions: [],
|
||||||
|
hospitalManual: false,
|
||||||
appointmentDate: '',
|
appointmentDate: '',
|
||||||
appointmentTime: '',
|
appointmentTime: '',
|
||||||
minAppointmentDate: '',
|
minAppointmentDate: '',
|
||||||
@@ -64,6 +66,13 @@ Page({
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.applyBookingConfig(service)
|
this.applyBookingConfig(service)
|
||||||
|
// 启动时 app 已在预取医院;这里等它落定后刷新下拉,失败则退回手动输入
|
||||||
|
getApp().loadHospitals().then(() => {
|
||||||
|
this.refreshHospitalOptions()
|
||||||
|
if (!this.data.hospitalOptions.length && !this.data.hospitalManual) {
|
||||||
|
this.setData({ hospitalManual: true })
|
||||||
|
}
|
||||||
|
})
|
||||||
const serviceView = {
|
const serviceView = {
|
||||||
...service,
|
...service,
|
||||||
notices: (service.notices || []).map(text => ({ id: text, text }))
|
notices: (service.notices || []).map(text => ({ id: text, text }))
|
||||||
@@ -108,6 +117,7 @@ Page({
|
|||||||
timeEnd = `${String(Math.floor(latest / 60)).padStart(2, '0')}:${String(latest % 60).padStart(2, '0')}`
|
timeEnd = `${String(Math.floor(latest / 60)).padStart(2, '0')}:${String(latest % 60).padStart(2, '0')}`
|
||||||
}
|
}
|
||||||
const provinces = service.areas || []
|
const provinces = service.areas || []
|
||||||
|
this.selectedHospitalId = ''
|
||||||
this.setData({
|
this.setData({
|
||||||
minAppointmentDate,
|
minAppointmentDate,
|
||||||
fixedTime,
|
fixedTime,
|
||||||
@@ -118,8 +128,10 @@ Page({
|
|||||||
provinces,
|
provinces,
|
||||||
province: provinces[0] || '',
|
province: provinces[0] || '',
|
||||||
provinceIndex: 0,
|
provinceIndex: 0,
|
||||||
|
hospital: '',
|
||||||
|
hospitalManual: false,
|
||||||
requiresAddress: !!booking.requiresAddress
|
requiresAddress: !!booking.requiresAddress
|
||||||
})
|
}, () => this.refreshHospitalOptions(provinces[0] || ''))
|
||||||
},
|
},
|
||||||
|
|
||||||
getServiceIcon(title) {
|
getServiceIcon(title) {
|
||||||
@@ -170,6 +182,7 @@ Page({
|
|||||||
selectedPatient: null,
|
selectedPatient: null,
|
||||||
showOrderPopup: true
|
showOrderPopup: true
|
||||||
})
|
})
|
||||||
|
this.refreshHospitalOptions()
|
||||||
this.loadProfiles()
|
this.loadProfiles()
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -214,11 +227,42 @@ Page({
|
|||||||
|
|
||||||
onProvinceChange(e) {
|
onProvinceChange(e) {
|
||||||
const index = Number(e.detail.value)
|
const index = Number(e.detail.value)
|
||||||
this.setData({ provinceIndex: index, province: this.data.provinces[index] })
|
const province = this.data.provinces[index]
|
||||||
|
// 省份变了,已选医院可能不在新省份内,先清空再按新省份重建列表
|
||||||
|
this.selectedHospitalId = ''
|
||||||
|
this.setData({
|
||||||
|
provinceIndex: index,
|
||||||
|
province,
|
||||||
|
hospital: '',
|
||||||
|
hospitalManual: false
|
||||||
|
}, () => this.refreshHospitalOptions(province))
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// 按当前省份重建医院列表;已选医院按 _id 保留,避免网络刷新后选中值丢失
|
||||||
|
refreshHospitalOptions(province = this.data.province) {
|
||||||
|
const hospitalOptions = getApp().getHospitalsByProvince(province)
|
||||||
|
let hospital = ''
|
||||||
|
|
||||||
|
if (this.data.hospitalManual) {
|
||||||
|
hospital = this.data.hospital
|
||||||
|
} else {
|
||||||
|
const selected = hospitalOptions.find((item) => item._id === this.selectedHospitalId)
|
||||||
|
if (selected) {
|
||||||
|
hospital = selected.name
|
||||||
|
} else if (this.selectedHospitalId) {
|
||||||
|
// 已选医院在刷新后已不存在,退回未选状态
|
||||||
|
this.selectedHospitalId = ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.setData({ hospitalOptions, hospital })
|
||||||
|
},
|
||||||
|
|
||||||
|
// 医院选择组件回传:name 为最终值,manual 表示是否手动输入,hospital 为库内记录
|
||||||
onHospitalChange(e) {
|
onHospitalChange(e) {
|
||||||
this.setData({ hospital: e.detail.value })
|
const { name, manual, hospital } = e.detail
|
||||||
|
this.selectedHospitalId = hospital?._id || ''
|
||||||
|
this.setData({ hospital: name, hospitalManual: manual })
|
||||||
},
|
},
|
||||||
|
|
||||||
onDateChange(e) {
|
onDateChange(e) {
|
||||||
@@ -251,7 +295,7 @@ Page({
|
|||||||
validateOrder() {
|
validateOrder() {
|
||||||
const data = this.data
|
const data = this.data
|
||||||
if (!data.selectedProfileId || !data.selectedPatient) return '请选择就诊人'
|
if (!data.selectedProfileId || !data.selectedPatient) return '请选择就诊人'
|
||||||
if (!data.hospital.trim()) return '请输入就诊医院'
|
if (!data.hospital.trim()) return data.hospitalManual ? '请输入就诊医院' : '请选择就诊医院'
|
||||||
if (!data.appointmentDate) return '请选择预约日期'
|
if (!data.appointmentDate) return '请选择预约日期'
|
||||||
if (!data.appointmentTime) return '请选择预约时间'
|
if (!data.appointmentTime) return '请选择预约时间'
|
||||||
if (data.requiresAddress && !data.shippingAddress.trim()) return '请填写完整收货地址'
|
if (data.requiresAddress && !data.shippingAddress.trim()) return '请填写完整收货地址'
|
||||||
@@ -309,6 +353,7 @@ Page({
|
|||||||
|
|
||||||
resetForm() {
|
resetForm() {
|
||||||
const provinces = this.data.provinces
|
const provinces = this.data.provinces
|
||||||
|
this.selectedHospitalId = ''
|
||||||
this.setData({
|
this.setData({
|
||||||
selectedProfileId: '',
|
selectedProfileId: '',
|
||||||
patientName: '',
|
patientName: '',
|
||||||
@@ -317,6 +362,7 @@ Page({
|
|||||||
province: provinces[0] || '',
|
province: provinces[0] || '',
|
||||||
provinceIndex: 0,
|
provinceIndex: 0,
|
||||||
hospital: '',
|
hospital: '',
|
||||||
|
hospitalManual: false,
|
||||||
appointmentDate: '',
|
appointmentDate: '',
|
||||||
appointmentTime: '',
|
appointmentTime: '',
|
||||||
sessionIndex: 0,
|
sessionIndex: 0,
|
||||||
@@ -324,7 +370,7 @@ Page({
|
|||||||
genderIndex: 0,
|
genderIndex: 0,
|
||||||
remark: '',
|
remark: '',
|
||||||
shippingAddress: ''
|
shippingAddress: ''
|
||||||
})
|
}, () => this.refreshHospitalOptions(provinces[0] || ''))
|
||||||
this.idempotencyKey = ''
|
this.idempotencyKey = ''
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"usingComponents": {
|
"usingComponents": {
|
||||||
"t-icon": "tdesign-miniprogram/icon/icon"
|
"t-icon": "tdesign-miniprogram/icon/icon",
|
||||||
|
"hospital-select": "/components/hospital-select/index"
|
||||||
},
|
},
|
||||||
"navigationBarTitleText": "服务详情"
|
"navigationBarTitleText": "服务详情"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -150,11 +150,16 @@
|
|||||||
</picker>
|
</picker>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<!-- 就诊医院 -->
|
<!-- 就诊医院:自定义搜索选择,支持中文/拼音搜索与手动输入 -->
|
||||||
<view class="order-row">
|
<hospital-select
|
||||||
<text class="order-label">就诊医院</text>
|
label="就诊医院"
|
||||||
<input class="order-input" value="{{hospital}}" placeholder="请输入就诊医院" placeholder-class="input-placeholder" bindinput="onHospitalChange" />
|
value="{{hospital}}"
|
||||||
</view>
|
manual="{{hospitalManual}}"
|
||||||
|
options="{{hospitalOptions}}"
|
||||||
|
placeholder="请选择就诊医院"
|
||||||
|
disabled="{{submitting}}"
|
||||||
|
bindchange="onHospitalChange"
|
||||||
|
/>
|
||||||
|
|
||||||
<!-- 陪诊师性别要求 -->
|
<!-- 陪诊师性别要求 -->
|
||||||
<view class="order-row">
|
<view class="order-row">
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ Page({
|
|||||||
provinceIndex: 0,
|
provinceIndex: 0,
|
||||||
provinces: [],
|
provinces: [],
|
||||||
hospital: '',
|
hospital: '',
|
||||||
|
hospitalOptions: [],
|
||||||
|
hospitalManual: false,
|
||||||
appointmentDate: '',
|
appointmentDate: '',
|
||||||
appointmentTime: '',
|
appointmentTime: '',
|
||||||
minAppointmentDate: '',
|
minAppointmentDate: '',
|
||||||
@@ -69,6 +71,14 @@ Page({
|
|||||||
this.pageReady = true
|
this.pageReady = true
|
||||||
|
|
||||||
const app = getApp()
|
const app = getApp()
|
||||||
|
// 启动时 app 已在预取,这里只等它落定后用最新列表刷新下拉;
|
||||||
|
// 没有可用医院时退回手动输入,避免下拉是空的还阻断下单
|
||||||
|
app.loadHospitals().then(() => {
|
||||||
|
this.refreshHospitalOptions()
|
||||||
|
if (!this.data.hospitalOptions.length && !this.data.hospitalManual) {
|
||||||
|
this.setData({ hospitalManual: true })
|
||||||
|
}
|
||||||
|
})
|
||||||
await app.waitForAuth()
|
await app.waitForAuth()
|
||||||
if (app.globalData.user?._id) this.loadProfiles()
|
if (app.globalData.user?._id) this.loadProfiles()
|
||||||
},
|
},
|
||||||
@@ -96,6 +106,7 @@ Page({
|
|||||||
}
|
}
|
||||||
const provinces = service.areas || []
|
const provinces = service.areas || []
|
||||||
|
|
||||||
|
this.selectedHospitalId = ''
|
||||||
this.setData({
|
this.setData({
|
||||||
service,
|
service,
|
||||||
serviceIndex,
|
serviceIndex,
|
||||||
@@ -110,11 +121,13 @@ Page({
|
|||||||
provinces,
|
provinces,
|
||||||
province: provinces[0] || '',
|
province: provinces[0] || '',
|
||||||
provinceIndex: 0,
|
provinceIndex: 0,
|
||||||
|
hospital: '',
|
||||||
|
hospitalManual: false,
|
||||||
appointmentDate: '',
|
appointmentDate: '',
|
||||||
appointmentTime: '',
|
appointmentTime: '',
|
||||||
shippingAddress: '',
|
shippingAddress: '',
|
||||||
requiresAddress: !!booking.requiresAddress
|
requiresAddress: !!booking.requiresAddress
|
||||||
})
|
}, () => this.refreshHospitalOptions(provinces[0] || ''))
|
||||||
},
|
},
|
||||||
|
|
||||||
onServiceChange(e) {
|
onServiceChange(e) {
|
||||||
@@ -189,11 +202,42 @@ Page({
|
|||||||
|
|
||||||
onProvinceChange(e) {
|
onProvinceChange(e) {
|
||||||
const index = Number(e.detail.value)
|
const index = Number(e.detail.value)
|
||||||
this.setData({ provinceIndex: index, province: this.data.provinces[index] })
|
const province = this.data.provinces[index]
|
||||||
|
// 省份变了,已选医院可能不在新省份内,先清空再按新省份重建列表
|
||||||
|
this.selectedHospitalId = ''
|
||||||
|
this.setData({
|
||||||
|
provinceIndex: index,
|
||||||
|
province,
|
||||||
|
hospital: '',
|
||||||
|
hospitalManual: false
|
||||||
|
}, () => this.refreshHospitalOptions(province))
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// 按当前省份重建医院列表;已选医院按 _id 保留,避免网络刷新后选中值丢失
|
||||||
|
refreshHospitalOptions(province = this.data.province) {
|
||||||
|
const hospitalOptions = getApp().getHospitalsByProvince(province)
|
||||||
|
let hospital = ''
|
||||||
|
|
||||||
|
if (this.data.hospitalManual) {
|
||||||
|
hospital = this.data.hospital
|
||||||
|
} else {
|
||||||
|
const selected = hospitalOptions.find((item) => item._id === this.selectedHospitalId)
|
||||||
|
if (selected) {
|
||||||
|
hospital = selected.name
|
||||||
|
} else if (this.selectedHospitalId) {
|
||||||
|
// 已选医院在刷新后已不存在,退回未选状态
|
||||||
|
this.selectedHospitalId = ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.setData({ hospitalOptions, hospital })
|
||||||
|
},
|
||||||
|
|
||||||
|
// 医院选择组件回传:name 为最终值,manual 表示是否手动输入,hospital 为库内记录
|
||||||
onHospitalChange(e) {
|
onHospitalChange(e) {
|
||||||
this.setData({ hospital: e.detail.value })
|
const { name, manual, hospital } = e.detail
|
||||||
|
this.selectedHospitalId = hospital?._id || ''
|
||||||
|
this.setData({ hospital: name, hospitalManual: manual })
|
||||||
},
|
},
|
||||||
|
|
||||||
onDateChange(e) {
|
onDateChange(e) {
|
||||||
@@ -226,7 +270,7 @@ Page({
|
|||||||
validateOrder() {
|
validateOrder() {
|
||||||
const data = this.data
|
const data = this.data
|
||||||
if (!data.selectedProfileId || !data.selectedPatient) return '请选择就诊人'
|
if (!data.selectedProfileId || !data.selectedPatient) return '请选择就诊人'
|
||||||
if (!data.hospital.trim()) return '请输入就诊医院'
|
if (!data.hospital.trim()) return data.hospitalManual ? '请输入就诊医院' : '请选择就诊医院'
|
||||||
if (!data.appointmentDate) return '请选择预约日期'
|
if (!data.appointmentDate) return '请选择预约日期'
|
||||||
if (!data.appointmentTime) return '请选择预约时间'
|
if (!data.appointmentTime) return '请选择预约时间'
|
||||||
if (data.requiresAddress && !data.shippingAddress.trim()) return '请填写完整收货地址'
|
if (data.requiresAddress && !data.shippingAddress.trim()) return '请填写完整收货地址'
|
||||||
@@ -291,6 +335,7 @@ Page({
|
|||||||
|
|
||||||
resetForm() {
|
resetForm() {
|
||||||
const provinces = this.data.provinces
|
const provinces = this.data.provinces
|
||||||
|
this.selectedHospitalId = ''
|
||||||
this.setData({
|
this.setData({
|
||||||
selectedProfileId: '',
|
selectedProfileId: '',
|
||||||
patientName: '',
|
patientName: '',
|
||||||
@@ -299,6 +344,7 @@ Page({
|
|||||||
province: provinces[0] || '',
|
province: provinces[0] || '',
|
||||||
provinceIndex: 0,
|
provinceIndex: 0,
|
||||||
hospital: '',
|
hospital: '',
|
||||||
|
hospitalManual: false,
|
||||||
appointmentDate: '',
|
appointmentDate: '',
|
||||||
appointmentTime: '',
|
appointmentTime: '',
|
||||||
sessionIndex: 0,
|
sessionIndex: 0,
|
||||||
@@ -306,7 +352,7 @@ Page({
|
|||||||
genderIndex: 0,
|
genderIndex: 0,
|
||||||
remark: '',
|
remark: '',
|
||||||
shippingAddress: ''
|
shippingAddress: ''
|
||||||
})
|
}, () => this.refreshHospitalOptions(provinces[0] || ''))
|
||||||
this.idempotencyKey = this.createIdempotencyKey()
|
this.idempotencyKey = this.createIdempotencyKey()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
{
|
{
|
||||||
"usingComponents": {
|
"usingComponents": {
|
||||||
"t-icon": "tdesign-miniprogram/icon/icon",
|
"t-icon": "tdesign-miniprogram/icon/icon",
|
||||||
"t-loading": "tdesign-miniprogram/loading/loading"
|
"t-loading": "tdesign-miniprogram/loading/loading",
|
||||||
|
"hospital-select": "/components/hospital-select/index"
|
||||||
},
|
},
|
||||||
"navigationBarTitleText": "立即预约"
|
"navigationBarTitleText": "立即预约"
|
||||||
}
|
}
|
||||||
@@ -67,10 +67,15 @@
|
|||||||
</picker>
|
</picker>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<view class="order-row">
|
<hospital-select
|
||||||
<text class="order-label">就诊医院</text>
|
label="就诊医院"
|
||||||
<input class="order-input" value="{{hospital}}" placeholder="请输入就诊医院" placeholder-class="input-placeholder" bindinput="onHospitalChange" />
|
value="{{hospital}}"
|
||||||
</view>
|
manual="{{hospitalManual}}"
|
||||||
|
options="{{hospitalOptions}}"
|
||||||
|
placeholder="请选择就诊医院"
|
||||||
|
disabled="{{submitting}}"
|
||||||
|
bindchange="onHospitalChange"
|
||||||
|
/>
|
||||||
|
|
||||||
<view class="order-row">
|
<view class="order-row">
|
||||||
<text class="order-label">陪诊师性别</text>
|
<text class="order-label">陪诊师性别</text>
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ Page({
|
|||||||
// 医院预约规则与下单页一致,均由订单关联的服务目录下发
|
// 医院预约规则与下单页一致,均由订单关联的服务目录下发
|
||||||
showHospitalPopup: false,
|
showHospitalPopup: false,
|
||||||
provinces: [],
|
provinces: [],
|
||||||
|
hospitalOptions: [],
|
||||||
minAppointmentDate: '',
|
minAppointmentDate: '',
|
||||||
fixedTime: false,
|
fixedTime: false,
|
||||||
timeOptions: [],
|
timeOptions: [],
|
||||||
@@ -356,24 +357,39 @@ Page({
|
|||||||
// ===== 医院预约信息编辑(底部弹窗) =====
|
// ===== 医院预约信息编辑(底部弹窗) =====
|
||||||
|
|
||||||
// 打开弹窗:用当前展示值填充表单(scheduleDate 已是 YYYY-MM-DD,可直接喂给 date picker)
|
// 打开弹窗:用当前展示值填充表单(scheduleDate 已是 YYYY-MM-DD,可直接喂给 date picker)
|
||||||
onEditHospital() {
|
async onEditHospital() {
|
||||||
|
await getApp().loadHospitals()
|
||||||
const r = this.data.record
|
const r = this.data.record
|
||||||
const provinceIndex = Math.max(0, this.data.provinces.indexOf(r.hospitalProvince))
|
// 历史订单的省份若与目录写法不同(北京 / 北京市),落回目录里的标准值
|
||||||
|
const matchedProvinceIndex = this.data.provinces.findIndex(item => getApp().isSameProvince(item, r.hospitalProvince))
|
||||||
|
const province = matchedProvinceIndex >= 0
|
||||||
|
? this.data.provinces[matchedProvinceIndex]
|
||||||
|
: (r.hospitalProvince || this.data.provinces[0] || '')
|
||||||
|
const provinceIndex = Math.max(0, matchedProvinceIndex)
|
||||||
const sessions = this.data.service?.booking?.sessions || []
|
const sessions = this.data.service?.booking?.sessions || []
|
||||||
const sessionIndex = Math.max(0, sessions.findIndex(item => item.start === r.scheduleStartTime))
|
const sessionIndex = Math.max(0, sessions.findIndex(item => item.start === r.scheduleStartTime))
|
||||||
|
|
||||||
|
const hospitalOptions = getApp().getHospitalsByProvince(province)
|
||||||
|
const name = r.hospitalName || ''
|
||||||
|
const matched = hospitalOptions.find(item => item.name === name)
|
||||||
|
// 历史订单的医院可能已不在库中:自动退回手动输入并保留原值,保证仍能保存
|
||||||
|
const hospitalManual = !hospitalOptions.length || (!!name.trim() && !matched)
|
||||||
|
|
||||||
this.setData({
|
this.setData({
|
||||||
showHospitalPopup: true,
|
showHospitalPopup: true,
|
||||||
|
hospitalOptions,
|
||||||
editHospital: {
|
editHospital: {
|
||||||
province: r.hospitalProvince || this.data.provinces[0] || '',
|
province,
|
||||||
provinceIndex,
|
provinceIndex,
|
||||||
name: r.hospitalName || '',
|
name,
|
||||||
address: r.hospitalAddress || '',
|
address: r.hospitalAddress || '',
|
||||||
department: r.hospitalDepartment || '',
|
department: r.hospitalDepartment || '',
|
||||||
doctor: r.hospitalDoctor || '',
|
doctor: r.hospitalDoctor || '',
|
||||||
medicalRecordNo: r.medicalRecordNo || '',
|
medicalRecordNo: r.medicalRecordNo || '',
|
||||||
scheduleDate: r.scheduleDate || '',
|
scheduleDate: r.scheduleDate || '',
|
||||||
startTime: r.scheduleStartTime || '',
|
startTime: r.scheduleStartTime || '',
|
||||||
sessionIndex
|
sessionIndex,
|
||||||
|
hospitalManual
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
@@ -386,12 +402,29 @@ Page({
|
|||||||
|
|
||||||
onProvinceChange(e) {
|
onProvinceChange(e) {
|
||||||
const index = Number(e.detail.value)
|
const index = Number(e.detail.value)
|
||||||
|
const province = this.data.provinces[index]
|
||||||
|
const hospitalOptions = getApp().getHospitalsByProvince(province)
|
||||||
|
// 省份变了,已选医院可能不在新省份内,先清空再按新省份重建列表
|
||||||
this.setData({
|
this.setData({
|
||||||
'editHospital.provinceIndex': index,
|
'editHospital.provinceIndex': index,
|
||||||
'editHospital.province': this.data.provinces[index]
|
'editHospital.province': province,
|
||||||
|
'editHospital.name': '',
|
||||||
|
'editHospital.hospitalManual': false,
|
||||||
|
hospitalOptions
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// 医院选择组件回传:库内医院同时带出地址,手动输入保持用户填写
|
||||||
|
onHospitalSelectChange(e) {
|
||||||
|
const { name, manual, hospital } = e.detail
|
||||||
|
const patch = {
|
||||||
|
'editHospital.name': name,
|
||||||
|
'editHospital.hospitalManual': manual
|
||||||
|
}
|
||||||
|
if (hospital?.address) patch['editHospital.address'] = hospital.address
|
||||||
|
this.setData(patch)
|
||||||
|
},
|
||||||
|
|
||||||
onScheduleDateChange(e) {
|
onScheduleDateChange(e) {
|
||||||
this.setData({ 'editHospital.scheduleDate': e.detail.value })
|
this.setData({ 'editHospital.scheduleDate': e.detail.value })
|
||||||
},
|
},
|
||||||
@@ -416,7 +449,7 @@ Page({
|
|||||||
onSaveHospital() {
|
onSaveHospital() {
|
||||||
const form = this.data.editHospital
|
const form = this.data.editHospital
|
||||||
if (!form.name || !form.name.trim()) {
|
if (!form.name || !form.name.trim()) {
|
||||||
wx.showToast({ title: '请输入就诊医院', icon: 'none' })
|
wx.showToast({ title: form.hospitalManual ? '请输入就诊医院' : '请选择就诊医院', icon: 'none' })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (!form.scheduleDate) {
|
if (!form.scheduleDate) {
|
||||||
@@ -428,8 +461,10 @@ Page({
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 提交前再对齐一次服务目录口径,避免历史数据里的「北京」被后端判为未开通
|
||||||
|
const serviceProvince = this.data.provinces.find(item => getApp().isSameProvince(item, form.province))
|
||||||
const update = {
|
const update = {
|
||||||
'hospital.province': form.province || '',
|
'hospital.province': serviceProvince || form.province || '',
|
||||||
'hospital.name': form.name.trim(),
|
'hospital.name': form.name.trim(),
|
||||||
'hospital.address': (form.address || '').trim(),
|
'hospital.address': (form.address || '').trim(),
|
||||||
'hospital.department': (form.department || '').trim(),
|
'hospital.department': (form.department || '').trim(),
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
{
|
{
|
||||||
"navigationBarTitleText": "预约记录详情",
|
"navigationBarTitleText": "预约记录详情",
|
||||||
"usingComponents": {
|
"usingComponents": {
|
||||||
"t-icon": "tdesign-miniprogram/icon/icon"
|
"t-icon": "tdesign-miniprogram/icon/icon",
|
||||||
|
"hospital-select": "/components/hospital-select/index"
|
||||||
},
|
},
|
||||||
"enablePullDownRefresh": true,
|
"enablePullDownRefresh": true,
|
||||||
"backgroundTextStyle": "dark"
|
"backgroundTextStyle": "dark"
|
||||||
|
|||||||
@@ -283,17 +283,15 @@
|
|||||||
<view class="form-picker-value">{{editHospital.province || '请选择省份'}}</view>
|
<view class="form-picker-value">{{editHospital.province || '请选择省份'}}</view>
|
||||||
</picker>
|
</picker>
|
||||||
</view>
|
</view>
|
||||||
<view class="form-row">
|
<hospital-select
|
||||||
<text class="form-label">就诊医院</text>
|
label="就诊医院"
|
||||||
<input
|
value="{{editHospital.name}}"
|
||||||
class="form-input"
|
manual="{{editHospital.hospitalManual}}"
|
||||||
value="{{editHospital.name}}"
|
options="{{hospitalOptions}}"
|
||||||
placeholder="请输入医院名称"
|
placeholder="请选择医院"
|
||||||
placeholder-class="input-placeholder"
|
compact="{{true}}"
|
||||||
bindinput="onHospitalFieldInput"
|
bindchange="onHospitalSelectChange"
|
||||||
data-field="name"
|
/>
|
||||||
/>
|
|
||||||
</view>
|
|
||||||
<view class="form-row">
|
<view class="form-row">
|
||||||
<text class="form-label">医院地址</text>
|
<text class="form-label">医院地址</text>
|
||||||
<input
|
<input
|
||||||
|
|||||||
Reference in New Issue
Block a user