| | |
| | | </template> |
| | | |
| | | <script> |
| | | import { searchHospitals } from "@/api/hospital" |
| | | import { searchHospitals, searchHospitalsByKeywords } from "@/api/hospital" |
| | | import { searchTianDiTuAddress } from "@/api/map" |
| | | |
| | | export default { |
| | |
| | | }, 300) |
| | | }, |
| | | |
| | | // 搜索医院 |
| | | // 搜索医院(智能选择接口) |
| | | searchHospital(keyword) { |
| | | searchHospitals(keyword, this.deptId).then(response => { |
| | | // 如果关键词为空或者是"家中",使用原来的接口 |
| | | if (!keyword || keyword.trim() === '' || keyword.trim() === '家中') { |
| | | searchHospitals(keyword || '', this.deptId).then(response => { |
| | | this.searchResults = response.data || [] |
| | | this.showResults = true |
| | | }).catch(error => { |
| | |
| | | this.searchResults = [] |
| | | // this.showResults = false |
| | | }) |
| | | } else { |
| | | // 有关键词时,使用新的分词匹配接口 |
| | | searchHospitalsByKeywords(keyword, this.deptId).then(response => { |
| | | // 转换数据格式:提取 hospital 对象 |
| | | const rawData = response.data || [] |
| | | this.searchResults = rawData.map(item => { |
| | | // 如果数据结构是 {hospital: {...}, matchScore: ...} |
| | | if (item.hospital) { |
| | | return item.hospital |
| | | } |
| | | // 如果已经是医院对象,直接返回 |
| | | return item |
| | | }) |
| | | this.showResults = true |
| | | }).catch(error => { |
| | | // console.error('搜索医院失败:', error) |
| | | this.searchResults = [] |
| | | // this.showResults = false |
| | | }) |
| | | } |
| | | }, |
| | | |
| | | // 输入框获得焦点 |
| | |
| | | } |
| | | }, |
| | | |
| | | // 加载默认医院列表 |
| | | // 加载默认医院列表(使用原来的接口) |
| | | loadDefaultHospitals() { |
| | | // 使用原来的接口加载默认列表 |
| | | searchHospitals('', this.deptId).then(response => { |
| | | this.defaultHospitals = response.data || [] |
| | | this.searchResults = this.defaultHospitals |