wlzboy
2025-10-27 559b2e34c983f615b6d6747f52c801022c561803
app/pages/task/create-emergency.vue
@@ -785,25 +785,67 @@
      this.taskForm.hospitalIn.departmentId = selected.id  // 保存科室ID
    },
    
    // 加载默认区院列表(前100条)
    // 加载默认医院列表(前100条)
    loadDefaultHospitals() {
      // 传入空字符串或特殊标识获取前100条,同时传入地域过滤
      // 转出医院:只加载当前区域的医院(带地域过滤)
      searchHospitals('', this.selectedRegion).then(response => {
        this.defaultHospitals = response.data || []
        // 同时初始化两个搜索结果为默认数据
        this.hospitalOutResults = [...this.defaultHospitals]
        this.hospitalInResults = [...this.defaultHospitals]
        this.hospitalOutResults = response.data || []
        console.log('加载转出医院(当前区域):', this.selectedRegion, '数量:', this.hospitalOutResults.length)
      }).catch(error => {
        console.error('加载默认区院列表失败:', error)
        this.defaultHospitals = []
        console.error('加载转出医院列表失败:', error)
        this.hospitalOutResults = []
      })
      // 转入医院:加载所有医院(不带地域过滤,后续会按地域排序)
      searchHospitals('', this.selectedRegion).then(response => {
        const allHospitals = response.data || []
        // 将医院按地域排序:本地区域优先
        this.hospitalInResults = this.sortHospitalsByRegion(allHospitals)
        console.log('加载转入医院(全部区域):', '数量:', this.hospitalInResults.length)
      }).catch(error => {
        console.error('加载转入医院列表失败:', error)
        this.hospitalInResults = []
      })
    },
    // 按地域排序医院:本地区域优先
    sortHospitalsByRegion(hospitals) {
      if (!this.selectedRegion || !hospitals || hospitals.length === 0) {
        return hospitals
      }
      const region = this.selectedRegion
      const localHospitals = []
      const otherHospitals = []
      hospitals.forEach(hospital => {
        // 判断医院是否在本地区域(省、市、区任一包含地域关键词)
        const isLocal =
          (hospital.hopsProvince && hospital.hopsProvince.includes(region)) ||
          (hospital.hopsCity && hospital.hopsCity.includes(region)) ||
          (hospital.hopsArea && hospital.hopsArea.includes(region))
        if (isLocal) {
          localHospitals.push(hospital)
        } else {
          otherHospitals.push(hospital)
        }
      })
      // 本地医院在前,其他医院在后
      return [...localHospitals, ...otherHospitals]
    },
    
    // 转出医院输入框获得焦点
    onHospitalOutFocus() {
      // 如果没有搜索关键词,显示默认的100条数据
      // 如果没有搜索关键词,只显示当前区域的医院
      if (!this.hospitalOutSearchKeyword || this.hospitalOutSearchKeyword.trim() === '') {
        this.hospitalOutResults = [...this.defaultHospitals]
        searchHospitals('', this.selectedRegion).then(response => {
          this.hospitalOutResults = response.data || []
        }).catch(error => {
          console.error('加载转出医院失败:', error)
          this.hospitalOutResults = []
        })
      }
      this.showHospitalOutResults = true
    },
@@ -818,27 +860,33 @@
        clearTimeout(this.searchTimer)
      }
      
      // 如果关键词为空,显示默认100条
      // 如果关键词为空,只显示当前区域的医院
      if (!keyword || keyword.trim() === '') {
        this.hospitalOutResults = [...this.defaultHospitals]
        searchHospitals('', this.selectedRegion).then(response => {
          this.hospitalOutResults = response.data || []
        }).catch(error => {
          console.error('加载转出医院失败:', error)
          this.hospitalOutResults = []
        })
        this.showHospitalOutResults = true
        return
      }
      
      // 有关键词时,去服务端搜索
      // 有关键词时,去服务端搜索(仅限当前区域)
      this.searchTimer = setTimeout(() => {
        this.searchHospitalOut(keyword)
      }, 300)
    },
    
    // 搜索转出医院
    // 搜索转出医院(仅限当前区域)
    searchHospitalOut(keyword) {
      // 传入关键词和地域过滤
      // 传入关键词和地域过滤,只搜索当前区域的医院
      searchHospitals(keyword, this.selectedRegion).then(response => {
        this.hospitalOutResults = response.data || []
        this.showHospitalOutResults = true
        console.log('搜索转出医院:', keyword, '区域:', this.selectedRegion, '结果数:', this.hospitalOutResults.length)
      }).catch(error => {
        console.error('搜索医院失败:', error)
        console.error('搜索转出医院失败:', error)
        this.hospitalOutResults = []
      })
    },
@@ -868,9 +916,16 @@
    
    // 转入医院输入框获得焦点
    onHospitalInFocus() {
      // 如果没有搜索关键词,显示默认的100条数据
      // 如果没有搜索关键词,显示所有医院(本地区域优先)
      if (!this.hospitalInSearchKeyword || this.hospitalInSearchKeyword.trim() === '') {
        this.hospitalInResults = [...this.defaultHospitals]
        searchHospitals('', '').then(response => {
          const allHospitals = response.data || []
          // 按地域排序:本地区域优先
          this.hospitalInResults = this.sortHospitalsByRegion(allHospitals)
        }).catch(error => {
          console.error('加载转入医院失败:', error)
          this.hospitalInResults = []
        })
      }
      this.showHospitalInResults = true
    },
@@ -885,27 +940,37 @@
        clearTimeout(this.searchTimer)
      }
      
      // 如果关键词为空,显示默认100条
      // 如果关键词为空,显示所有医院(本地区域优先)
      if (!keyword || keyword.trim() === '') {
        this.hospitalInResults = [...this.defaultHospitals]
        searchHospitals('', '').then(response => {
          const allHospitals = response.data || []
          // 按地域排序:本地区域优先
          this.hospitalInResults = this.sortHospitalsByRegion(allHospitals)
        }).catch(error => {
          console.error('加载转入医院失败:', error)
          this.hospitalInResults = []
        })
        this.showHospitalInResults = true
        return
      }
      
      // 有关键词时,去服务端搜索
      // 有关键词时,去服务端搜索(不限区域,但结果按地域排序)
      this.searchTimer = setTimeout(() => {
        this.searchHospitalIn(keyword)
      }, 300)
    },
    
    // 搜索转入医院
    // 搜索转入医院(不限区域,但本地区域优先)
    searchHospitalIn(keyword) {
      // 传入关键词和地域过滤
      searchHospitals(keyword, this.selectedRegion).then(response => {
        this.hospitalInResults = response.data || []
      // 传入关键词,不传地域过滤(搜索所有区域)
      searchHospitals(keyword, '').then(response => {
        const allHospitals = response.data || []
        // 按地域排序:本地区域优先
        this.hospitalInResults = this.sortHospitalsByRegion(allHospitals)
        this.showHospitalInResults = true
        console.log('搜索转入医院:', keyword, '结果数:', this.hospitalInResults.length)
      }).catch(error => {
        console.error('搜索医院失败:', error)
        console.error('搜索转入医院失败:', error)
        this.hospitalInResults = []
      })
    },