wlzboy
2025-12-30 a4b14a35a2209a30e53472e6333b13aa4a55b0eb
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>
@@ -58,7 +58,7 @@
<script>
import { searchHospitals } from "@/api/hospital"
import { baiduPlaceSuggestion } from "@/api/map"
import { searchTianDiTuAddress } from "@/api/map"
export default {
  name: 'HospitalSelector',
@@ -185,8 +185,9 @@
        this.searchResults = response.data || []
        this.showResults = true
      }).catch(error => {
        console.error('搜索医院失败:', error)
        // console.error('搜索医院失败:', error)
        this.searchResults = []
        // this.showResults = false
      })
    },
    
@@ -215,30 +216,36 @@
        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 = []
      })
    },
    
    // 选择医院
    selectHospital(hospital) {
      this.selectedHospitalName = hospital.hospName
      this.searchKeyword = hospital.hospName
      // 添加null检查
      if (!hospital) {
        console.warn('选择的医院对象为空');
        return;
      }
      this.selectedHospitalName = hospital.hospName || '';
      this.searchKeyword = hospital.hospName || '';
      
      const hospitalData = {
        id: hospital.hospId,
        name: hospital.hospName,
        id: hospital.hospId || null,
        name: hospital.hospName || '',
        address: hospital.hospName === '家中' ? '' : this.buildFullAddress(hospital)
      }
      
      this.showResults = false
      this.searchResults = []
      this.showResults = false;
      this.searchResults = [];
      
      // 触发更新事件
      this.$emit('input', hospitalData)
      this.$emit('change', hospitalData)
      this.$emit('input', hospitalData);
      this.$emit('change', hospitalData);
    },
    
@@ -288,7 +295,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
@@ -297,7 +304,7 @@
          this.showAddressSuggestions = false
        }
      }).catch(error => {
        console.error('搜索地址失败:', error)
        // console.error('搜索地址失败:', error)
        this.addressSuggestions = []
        this.showAddressSuggestions = false
      })
@@ -312,7 +319,7 @@
        
    // 选择地址建议
    selectAddressSuggestion(item) {
      const fullAddress = item.district + item.address
      const fullAddress = (item.district || '') + (item.address || '')
      this.$emit('input', {
        ...this.value,
        address: fullAddress