wlzboy
2026-01-24 2f09efc660bf2cc94cbc5291ad25ca06fc9bdadf
app/pagesTask/components/HospitalSelector.vue
@@ -45,7 +45,7 @@
            @click="selectAddressSuggestion(item)"
          >
            <view class="suggestion-name">{{ item.name }}</view>
            <view class="suggestion-address">{{ item.district }}{{ item.address }}</view>
            <view class="suggestion-address">{{ (item.district || '') + (item.address || '') }}</view>
          </view>
        </view>
      </view>
@@ -57,8 +57,8 @@
</template>
<script>
import { searchHospitals } from "@/api/hospital"
import { baiduPlaceSuggestion } from "@/api/map"
import { searchHospitals, searchHospitalsByKeywords } from "@/api/hospital"
import { searchTianDiTuAddress } from "@/api/map"
export default {
  name: 'HospitalSelector',
@@ -179,15 +179,38 @@
      }, 300)
    },
    
    // 搜索医院
    // 搜索医院(智能选择接口)
    searchHospital(keyword) {
      searchHospitals(keyword, this.deptId).then(response => {
        this.searchResults = response.data || []
        this.showResults = true
      }).catch(error => {
        console.error('搜索医院失败:', error)
        this.searchResults = []
      })
      // 如果关键词为空或者是"家中",使用原来的接口
      if (!keyword || keyword.trim() === '' || keyword.trim() === '家中') {
        searchHospitals(keyword || '', this.deptId).then(response => {
          this.searchResults = response.data || []
          this.showResults = true
        }).catch(error => {
          // console.error('搜索医院失败:', 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
        })
      }
    },
    
    // 输入框获得焦点
@@ -208,16 +231,17 @@
      }
    },
    
    // 加载默认医院列表
    // 加载默认医院列表(使用原来的接口)
    loadDefaultHospitals() {
      // 使用原来的接口加载默认列表
      searchHospitals('', this.deptId).then(response => {
        this.defaultHospitals = response.data || []
        this.searchResults = this.defaultHospitals
        this.showResults = true
        this.hasLoadedDefault = true
        console.log('加载默认医院列表,数量:', this.defaultHospitals.length)
        // console.log('加载默认医院列表,数量:', this.defaultHospitals.length)
      }).catch(error => {
        console.error('加载默认医院列表失败:', error)
        // console.error('加载默认医院列表失败:', error)
        this.defaultHospitals = []
      })
    },
@@ -294,7 +318,7 @@
        
    // 搜索地址建议
    searchAddress(query) {
      baiduPlaceSuggestion(query, this.region).then(response => {
      searchTianDiTuAddress(query, this.region).then(response => {
        if (response.code === 200 && response.data) {
          this.addressSuggestions = response.data
          this.showAddressSuggestions = true
@@ -303,7 +327,7 @@
          this.showAddressSuggestions = false
        }
      }).catch(error => {
        console.error('搜索地址失败:', error)
        // console.error('搜索地址失败:', error)
        this.addressSuggestions = []
        this.showAddressSuggestions = false
      })
@@ -318,7 +342,7 @@
        
    // 选择地址建议
    selectAddressSuggestion(item) {
      const fullAddress = item.district + item.address
      const fullAddress = (item.district || '') + (item.address || '')
      this.$emit('input', {
        ...this.value,
        address: fullAddress