wlzboy
2025-11-09 fa5ea853099e88be253fca4fb2b0c2b7af5f396e
app/pages/task/create-emergency.vue
@@ -189,7 +189,10 @@
              :key="hospital.hospId"
              @click="selectHospitalOut(hospital)"
            >
              <view class="hospital-name">{{ hospital.hospName }}</view>
              <view class="hospital-name">
                {{ hospital.hospName }}
                <text class="hospital-short" v-if="hospital.hospShort">{{ hospital.hospShort }}</text>
              </view>
              <view class="hospital-address">{{ buildFullAddress(hospital) }}</view>
            </view>
          </view>
@@ -198,12 +201,21 @@
      
      <view class="form-item">
        <view class="form-label required">科室</view>
        <picker mode="selector" :range="departmentOptions" range-key="text" @change="onHospitalOutDepartmentChange">
        <picker
          v-if="taskForm.hospitalOut.name !== '家中'"
          mode="selector"
          :range="departmentOptions"
          range-key="text"
          @change="onHospitalOutDepartmentChange"
        >
          <view class="form-input picker-input">
            {{ taskForm.hospitalOut.department || '请选择科室' }}
            <uni-icons type="arrowright" size="16" color="#999"></uni-icons>
          </view>
        </picker>
        <view v-else class="form-input picker-input disabled">
          其它
        </view>
      </view>
      
      <view class="form-item">
@@ -259,7 +271,10 @@
              :key="hospital.hospId"
              @click="selectHospitalIn(hospital)"
            >
              <view class="hospital-name">{{ hospital.hospName }}</view>
              <view class="hospital-name">
                {{ hospital.hospName }}
                <text class="hospital-short" v-if="hospital.hospShort">{{ hospital.hospShort }}</text>
              </view>
              <view class="hospital-address">{{ buildFullAddress(hospital) }}</view>
            </view>
          </view>
@@ -268,12 +283,21 @@
      
      <view class="form-item">
        <view class="form-label required">科室</view>
        <picker mode="selector" :range="departmentOptions" range-key="text" @change="onHospitalInDepartmentChange">
        <picker
          v-if="taskForm.hospitalIn.name !== '家中'"
          mode="selector"
          :range="departmentOptions"
          range-key="text"
          @change="onHospitalInDepartmentChange"
        >
          <view class="form-input picker-input">
            {{ taskForm.hospitalIn.department || '请选择科室' }}
            <uni-icons type="arrowright" size="16" color="#999"></uni-icons>
          </view>
        </picker>
        <view v-else class="form-input picker-input disabled">
          其它
        </view>
      </view>
      
      <view class="form-item">
@@ -917,22 +941,30 @@
      })
    },
    
    // 按地域排序医院:本地区域优先
    // 按地域排序医院:本地区域优先,"家中"始终在最前面
    sortHospitalsByRegion(hospitals) {
      if (!this.selectedRegion || !hospitals || hospitals.length === 0) {
      if (!hospitals || hospitals.length === 0) {
        return hospitals
      }
      
      const region = this.selectedRegion
      const localHospitals = []
      const otherHospitals = []
      const homeHospital = []  // "家中"
      const localHospitals = []  // 本地医院
      const otherHospitals = []  // 其他医院
      
      hospitals.forEach(hospital => {
        // "家中"优先处理,放在最前面
        if (hospital.hospName === '家中') {
          homeHospital.push(hospital)
          return
        }
        // 判断医院是否在本地区域(省、市、区任一包含地域关键词)
        const isLocal =
        const isLocal = region && (
          (hospital.hopsProvince && hospital.hopsProvince.includes(region)) ||
          (hospital.hopsCity && hospital.hopsCity.includes(region)) ||
          (hospital.hopsArea && hospital.hopsArea.includes(region))
        )
        
        if (isLocal) {
          localHospitals.push(hospital)
@@ -941,8 +973,8 @@
        }
      })
      
      // 本地医院在前,其他医院在后
      return [...localHospitals, ...otherHospitals]
      // "家中"在最前,本地医院其次,其他医院在后
      return [...homeHospital, ...localHospitals, ...otherHospitals]
    },
    
    // 转出医院输入框获得焦点
@@ -958,23 +990,28 @@
        // 否则重新加载常用医院
        if (this.selectedOrganizationServiceOrderClass) {
          getFrequentOutHospitals(this.selectedOrganizationServiceOrderClass, this.selectedRegion).then(response => {
            this.hospitalOutResults = response.data || []
            const hospitals = response.data || []
            // 确保"家中"在最前面
            this.hospitalOutResults = this.sortHospitalsByRegion(hospitals)
            // 如果没有常用医院,降级为普通搜索
            if (this.hospitalOutResults.length === 0) {
              searchHospitals('', this.selectedRegion).then(res => {
                this.hospitalOutResults = res.data || []
                const hospitals = res.data || []
                this.hospitalOutResults = this.sortHospitalsByRegion(hospitals)
              })
            }
          }).catch(error => {
            console.error('加载常用转出医院失败:', error)
            searchHospitals('', this.selectedRegion).then(res => {
              this.hospitalOutResults = res.data || []
              const hospitals = res.data || []
              this.hospitalOutResults = this.sortHospitalsByRegion(hospitals)
            })
          })
        } else {
          // 没有服务单编码,使用普通搜索
          searchHospitals('', this.selectedRegion).then(response => {
            this.hospitalOutResults = response.data || []
            const hospitals = response.data || []
            this.hospitalOutResults = this.sortHospitalsByRegion(hospitals)
          }).catch(error => {
            console.error('加载转出医院失败:', error)
            this.hospitalOutResults = []
@@ -994,10 +1031,12 @@
        clearTimeout(this.searchTimer)
      }
      
      // 如果关键词为空,只显示当前区域的医院
      // 如果关键词为空,显示当前区域的医院
      if (!keyword || keyword.trim() === '') {
        searchHospitals('', this.selectedRegion).then(response => {
          this.hospitalOutResults = response.data || []
          const hospitals = response.data || []
          // 确保"家中"在最前面
          this.hospitalOutResults = this.sortHospitalsByRegion(hospitals)
        }).catch(error => {
          console.error('加载转出医院失败:', error)
          this.hospitalOutResults = []
@@ -1016,7 +1055,9 @@
    searchHospitalOut(keyword) {
      // 传入关键词和地域过滤,只搜索当前区域的医院
      searchHospitals(keyword, this.selectedRegion).then(response => {
        this.hospitalOutResults = response.data || []
        const hospitals = response.data || []
        // 确保"家中"在最前面
        this.hospitalOutResults = this.sortHospitalsByRegion(hospitals)
        this.showHospitalOutResults = true
        console.log('搜索转出医院:', keyword, '区域:', this.selectedRegion, '结果数:', this.hospitalOutResults.length)
      }).catch(error => {
@@ -1032,10 +1073,18 @@
      // 如果选择的是"家中",清空地址让用户手动输入;否则自动填充地址
      if (hospital.hospName === '家中') {
        this.taskForm.hospitalOut.address = ''
        // 科室自动设置为"其它"
        this.taskForm.hospitalOut.department = '其它'
        this.taskForm.hospitalOut.departmentId = null
      } else {
        // 合并省市区 + 详细地址
        const fullAddress = this.buildFullAddress(hospital)
        this.taskForm.hospitalOut.address = fullAddress
        // 清空科室,让用户重新选择
        if (this.taskForm.hospitalOut.department === '其它') {
          this.taskForm.hospitalOut.department = ''
          this.taskForm.hospitalOut.departmentId = null
        }
      }
      this.hospitalOutSearchKeyword = hospital.hospName
      this.showHospitalOutResults = false
@@ -1115,7 +1164,7 @@
      if (!keyword || keyword.trim() === '') {
        searchHospitals('', '').then(response => {
          const allHospitals = response.data || []
          // 按地域排序:本地区域优先
          // 按地域排序:"家中"最前,本地区域优先
          this.hospitalInResults = this.sortHospitalsByRegion(allHospitals)
        }).catch(error => {
          console.error('加载转入医院失败:', error)
@@ -1136,7 +1185,7 @@
      // 传入关键词,不传地域过滤(搜索所有区域)
      searchHospitals(keyword, '').then(response => {
        const allHospitals = response.data || []
        // 按地域排序:本地区域优先
        // 按地域排序:"家中"最前,本地区域优先
        this.hospitalInResults = this.sortHospitalsByRegion(allHospitals)
        this.showHospitalInResults = true
        console.log('搜索转入医院:', keyword, '结果数:', this.hospitalInResults.length)
@@ -1153,10 +1202,18 @@
      // 如果选择的是"家中",清空地址让用户手动输入;否则自动填充地址
      if (hospital.hospName === '家中') {
        this.taskForm.hospitalIn.address = ''
        // 科室自动设置为"其它"
        this.taskForm.hospitalIn.department = '其它'
        this.taskForm.hospitalIn.departmentId = null
      } else {
        // 合并省市区 + 详细地址
        const fullAddress = this.buildFullAddress(hospital)
        this.taskForm.hospitalIn.address = fullAddress
        // 清空科室,让用户重新选择
        if (this.taskForm.hospitalIn.department === '其它') {
          this.taskForm.hospitalIn.department = ''
          this.taskForm.hospitalIn.departmentId = null
        }
      }
      this.hospitalInSearchKeyword = hospital.hospName
      this.showHospitalInResults = false
@@ -2006,6 +2063,14 @@
              color: #333;
              font-weight: bold;
              margin-bottom: 8rpx;
              .hospital-short {
                display: block;
                font-size: 22rpx;
                color: #999;
                font-weight: normal;
                margin-top: 6rpx;
              }
            }
            
            .hospital-address {