wlzboy
2025-11-22 fd047fa7234dc11643dab8ecbf38e8d7a8ba0854
app/pages/task/create-emergency.vue
@@ -22,13 +22,12 @@
        </picker>
      </view>
        <view class="form-item">
        <view class="form-label required">归属机构</view>
        <picker mode="selector" :range="organizations" @change="onOrganizationChange">
          <view class="form-input picker-input">
            {{ selectedOrganization || '请选择归属机构' }}
            <uni-icons type="arrowright" size="16" color="#999"></uni-icons>
          </view>
        </picker>
        <OrganizationSelector
          v-model="selectedOrganizationId"
          :required="true"
          :auto-select-user-dept="true"
          @change="onOrganizationChange"
        />
      </view>
      
      <view class="form-item">
@@ -144,200 +143,38 @@
        />
      </view>
      
      <view class="form-item">
        <view class="form-label">病情</view>
        <view class="disease-container">
          <view class="disease-tags" v-if="selectedDiseases.length > 0">
            <view
              class="disease-tag"
              v-for="(disease, index) in selectedDiseases"
              :key="index"
            >
              <text class="disease-name">{{ disease.icdName }}</text>
              <uni-icons
                type="closeempty"
                size="16"
                color="#fff"
                @click="removeDisease(index)"
              ></uni-icons>
            </view>
          </view>
          <view class="add-disease-btn" @click="showDiseaseSelector">
            <uni-icons type="plusempty" size="20" color="#007AFF"></uni-icons>
            <text>添加病情</text>
          </view>
          <textarea
            class="form-textarea"
            placeholder="其他病情描述(选填)"
            v-model="taskForm.patient.condition"
            style="margin-top: 20rpx;"
      <DiseaseSelector
        v-model="selectedDiseases"
        :other-description.sync="taskForm.patient.condition"
          />
        </view>
      </view>
      
      <view class="form-section-title">转出医院信息</view>
      <view class="form-item">
        <view class="form-label required">医院名称</view>
        <view class="hospital-search-container">
          <input
            class="form-input"
            placeholder="请输入医院名称或地址搜索"
            v-model="hospitalOutSearchKeyword"
            @input="onHospitalOutSearch"
            @focus="onHospitalOutFocus"
      <HospitalSelector
        label="医院名称"
        address-label="转出地址"
        :required="true"
        :department-required="true"
        v-model="taskForm.hospitalOut"
        :dept-id="selectedOrganizationId"
        :region="selectedRegion"
        :department-options="departmentOptions"
        @change="onHospitalOutChange"
        @address-selected="onHospitalOutAddressSelected"
          />
          <view class="search-results" v-if="showHospitalOutResults && hospitalOutResults.length > 0">
            <view
              class="search-result-item"
              v-for="hospital in hospitalOutResults"
              :key="hospital.hospId"
              @click="selectHospitalOut(hospital)"
            >
              <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>
        </view>
      </view>
      <view class="form-item">
        <view class="form-label required">科室</view>
        <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">
        <view class="form-label">床号</view>
        <input
          class="form-input"
          placeholder="请输入床号"
          v-model="taskForm.hospitalOut.bedNumber"
        />
      </view>
      <view class="form-item">
        <view class="form-label">转出地址</view>
        <view class="address-input-container" v-if="taskForm.hospitalOut.name === '家中'">
          <input
            class="form-input"
            placeholder="请输入详细地址"
            v-model="taskForm.hospitalOut.address"
            @input="onAddressOutInput"
            @focus="onAddressOutFocus"
          />
          <view class="address-suggestions" v-if="showAddressOutSuggestions && addressOutSuggestions.length > 0">
            <view
              class="address-suggestion-item"
              v-for="(item, index) in addressOutSuggestions"
              :key="index"
              @click="selectAddressOut(item)">
              <view class="suggestion-name">{{ item.name }}</view>
              <view class="suggestion-address">{{ item.district }}{{ item.address }}</view>
            </view>
          </view>
        </view>
        <view v-else class="form-input picker-input disabled">
          {{ taskForm.hospitalOut.address || '选择医院后自动填充' }}
        </view>
      </view>
      
      <view class="form-section-title">转入医院信息</view>
      <view class="form-item">
        <view class="form-label required">医院名称</view>
        <view class="hospital-search-container">
          <input
            class="form-input"
            placeholder="请输入医院名称或地址搜索"
            v-model="hospitalInSearchKeyword"
            @input="onHospitalInSearch"
            @focus="onHospitalInFocus"
      <HospitalSelector
        label="医院名称"
        address-label="转入地址"
        :required="true"
        :department-required="true"
        v-model="taskForm.hospitalIn"
        :dept-id="selectedOrganizationId"
        :region="selectedRegion"
        :department-options="departmentOptions"
        @change="onHospitalInChange"
        @address-selected="onHospitalInAddressSelected"
          />
          <view class="search-results" v-if="showHospitalInResults && hospitalInResults.length > 0">
            <view
              class="search-result-item"
              v-for="hospital in hospitalInResults"
              :key="hospital.hospId"
              @click="selectHospitalIn(hospital)"
            >
              <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>
        </view>
      </view>
      <view class="form-item">
        <view class="form-label required">科室</view>
        <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">
        <view class="form-label">床号</view>
        <input
          class="form-input"
          placeholder="请输入床号"
          v-model="taskForm.hospitalIn.bedNumber"
        />
      </view>
      <view class="form-item">
        <view class="form-label">转入地址</view>
        <view class="address-input-container" v-if="taskForm.hospitalIn.name === '家中'">
          <input
            class="form-input"
            placeholder="请输入详细地址"
            v-model="taskForm.hospitalIn.address"
            @input="onAddressInInput"
            @focus="onAddressInFocus"
          />
          <view class="address-suggestions" v-if="showAddressInSuggestions && addressInSuggestions.length > 0">
            <view
              class="address-suggestion-item"
              v-for="(item, index) in addressInSuggestions"
              :key="index"
              @click="selectAddressIn(item)">
              <view class="suggestion-name">{{ item.name }}</view>
              <view class="suggestion-address">{{ item.district }}{{ item.address }}</view>
            </view>
          </view>
        </view>
        <view v-else class="form-input picker-input disabled">
          {{ taskForm.hospitalIn.address || '选择医院后自动填充' }}
        </view>
      </view>
      
      <view class="form-item">
        <view class="form-label required">转运公里数</view>
@@ -475,64 +312,6 @@
        </view>
      </view>
    </uni-popup>
    <!-- 病情选择弹窗 -->
    <uni-popup ref="diseasePopup" type="bottom" :safe-area="true">
      <view class="disease-selector-popup">
        <view class="popup-header">
          <view class="popup-title">选择病情(ICD-10)</view>
          <view class="popup-close" @click="closeDiseaseSelector">
            <uni-icons type="closeempty" size="24" color="#333"></uni-icons>
          </view>
        </view>
        <view class="search-box">
          <uni-icons type="search" size="18" color="#999"></uni-icons>
          <input
            class="search-input"
            placeholder="搜索疾病名称、编码或助记码"
            v-model="diseaseSearchKeyword"
            @input="onDiseaseSearch"
          />
        </view>
        <scroll-view class="disease-list-popup" scroll-y="true">
          <view
            class="disease-item-popup"
            v-for="disease in diseaseSearchResults"
            :key="disease.id"
            @click="toggleDiseaseSelection(disease)"
          >
            <view class="disease-info">
              <view class="disease-name-row">
                <text class="disease-name">{{ disease.icdName }}</text>
                <text class="disease-code">[{{ disease.icdCode }}]</text>
              </view>
              <view class="disease-detail-row" v-if="disease.sm">
                <text class="disease-desc">{{ disease.sm }}</text>
              </view>
            </view>
            <uni-icons
              v-if="isDiseaseSelected(disease.id)"
              type="checkmarkempty"
              size="24"
              color="#007AFF"
            ></uni-icons>
            <view v-else class="checkbox-empty"></view>
          </view>
          <view class="no-data" v-if="diseaseSearchResults.length === 0">
            <uni-icons type="info" size="40" color="#ccc"></uni-icons>
            <text>{{ diseaseSearchKeyword ? '未找到相关疾病' : '暂无病情数据' }}</text>
          </view>
        </scroll-view>
        <view class="popup-footer">
          <button class="cancel-btn" @click="closeDiseaseSelector">取消</button>
          <button class="confirm-btn" @click="confirmDiseaseSelection">确定(已选{{ tempSelectedDiseases.length }})</button>
        </view>
      </view>
    </uni-popup>
  </scroll-view>
</template>
@@ -553,18 +332,23 @@
import { getServiceOrdAreaTypes, getServiceOrderTypes, getHospitalDepartments } from "@/api/dictionary"
import { listBranchCompany, getDept } from "@/api/system/dept"
import MapSelector from '@/components/map-selector.vue'
import OrganizationSelector from '@/components/OrganizationSelector.vue'
import HospitalSelector from '@/components/HospitalSelector.vue'
import DiseaseSelector from '@/components/DiseaseSelector.vue'
export default {
  components: {
    uniDatetimePicker,
    uniPopup,
    MapSelector
    MapSelector,
    OrganizationSelector,
    HospitalSelector,
    DiseaseSelector
  },
  data() {
    return {
      selectedVehicle: '',
      selectedVehicleId: null,
      selectedOrganization: '',
      selectedOrganizationId: null, // 归属机构ID(部门ID)
      selectedOrganizationServiceOrderClass: '', // 归属机构的服务单编码
      selectedRegion: '', // 从归属机构中提取的地域信息(如:广州、深圳等)
@@ -573,21 +357,6 @@
      selectedDocumentType: '', // 选中的单据类型文本
      selectedDocumentTypeId: null, // 选中的单据类型ID
      mapSelectorType: '',
      // 医院搜索相关
      hospitalOutSearchKeyword: '',
      hospitalOutResults: [],
      showHospitalOutResults: false,
      hospitalInSearchKeyword: '',
      hospitalInResults: [],
      showHospitalInResults: false,
      searchTimer: null,
      defaultHospitals: [], // 默认的100条医院数据
      // 地址搜索提示相关
      addressOutSuggestions: [], // 转出地址提示列表
      showAddressOutSuggestions: false,
      addressInSuggestions: [], // 转入地址提示列表
      showAddressInSuggestions: false,
      addressSearchTimer: null, // 地址搜索防抖定时器
      // 人员选择相关
      selectedStaff: [], // 已选择的人员列表
      allStaffList: [], // 所有人员列表
@@ -596,10 +365,6 @@
      staffFilterType: 'driver', // 人员筛选类型:driver/doctor/nurse,默认选中司机
      // 病情选择相关
      selectedDiseases: [], // 已选择的病情列表
      tempSelectedDiseases: [], // 临时选择的病情列表(用于弹窗)
      diseaseSearchKeyword: '', // 病情搜索关键词
      diseaseSearchResults: [], // 病情搜索结果
      diseaseSearchTimer: null, // 病情搜索防抖定时器
      taskForm: {
        transferTime: '',
        patient: {
@@ -631,8 +396,7 @@
      },
      vehicles: [],
      vehicleOptions: [],
      organizations: [], // 归属机构列表(从后台加载分公司数据)
      organizationOptions: [], // 归属机构选项(用于picker显示)
      emergencyTaskTypes: [], // 任务类型列表(从 SQL Server 动态加载)
      emergencyTaskTypeOptions: [], // 任务类型选项(用于picker显示)
      documentTypes: [], // 单据类型列表
@@ -680,8 +444,6 @@
    })
    this.initSelectedStaff()
    this.loadDeptStaff()
    // 加载分公司数据(会自动设置默认分公司并加载医院列表)
    this.loadBranchCompanies()
    // 加载科室字典数据
    this.loadDepartments()
    // 加载任务类型数据
@@ -754,52 +516,16 @@
      this.selectedVehicleId = this.vehicleOptions[index]?.id
    },
    
    onOrganizationChange(e) {
      const index = e.detail.value
      const selected = this.organizationOptions[index]
      this.selectedOrganization = selected.deptName
      this.selectedOrganizationId = selected.deptId // 保存部门ID
      this.selectedOrganizationServiceOrderClass = selected.serviceOrderClass || '' // 保存服务单编码
      // 从归属机构中提取地域关键词(去除“分公司”后缀)
      // 例如:“广州分公司” -> “广州”
      //如果出现广州总公司,也要去除“总公司”后缀
      this.selectedRegion = this.replaceRegion(selected.deptName);
      // 重新加载医院列表(带地域过滤)
      this.loadDefaultHospitals()
    onOrganizationChange(orgData) {
      // orgData 包含:deptId, deptName, serviceOrderClass, region
      this.selectedOrganizationId = orgData.deptId
      this.selectedOrganizationServiceOrderClass = orgData.serviceOrderClass
      this.selectedRegion = orgData.region
      console.log('选中归属机构:', orgData.deptName, '部门ID:', orgData.deptId, '服务单编码:', orgData.serviceOrderClass, '地域:', orgData.region)
    },
    replaceRegion(region){
      return region.replace(/(分公司|总公司|总部)$/g, '').trim();
   },
    // 加载分公司数据(parent_id=100的部门)
    loadBranchCompanies() {
      listBranchCompany().then(response => {
        const list = response.data || []
        // 过滤出 parent_id = 100 的部门(分公司)
        this.organizationOptions = list.filter(dept => dept.parentId === 100)
        // 生成picker的数据源(只显示名称)
        this.organizations = this.organizationOptions.map(dept => dept.deptName)
        // 默认设置为当前用户的分公司
        if (this.currentUser.branchCompanyName) {
          const index = this.organizationOptions.findIndex(
            dept => dept.deptName === this.currentUser.branchCompanyName
          )
          if (index !== -1) {
            this.selectedOrganization = this.currentUser.branchCompanyName
            this.selectedOrganizationId = this.organizationOptions[index].deptId // 保存部门ID
            this.selectedOrganizationServiceOrderClass = this.organizationOptions[index].serviceOrderClass || '' // 保存服务单编码
            // 提取地域关键词
            this.selectedRegion =this.replaceRegion(this.selectedOrganization);
            console.log('默认选中归属机构:', this.selectedOrganization, '部门ID:', this.selectedOrganizationId, '服务单编码:', this.selectedOrganizationServiceOrderClass, '地域:', this.selectedRegion)
            // 加载医院列表(带地域过滤)
            this.loadDefaultHospitals()
          }
        }
      }).catch(error => {
        console.error('加载分公司数据失败:', error)
        this.organizationOptions = []
        this.organizations = []
      })
    },
    
    // 加载科室数据(从 SQL Server 动态加载)
@@ -892,243 +618,15 @@
      this.selectedDocumentTypeId = selected.id
    },
    
    // 转出医院科室选择
    onHospitalOutDepartmentChange(e) {
      const index = e.detail.value
      const selected = this.departmentOptions[index]
      this.taskForm.hospitalOut.department = selected.text  // 保存科室名称
      this.taskForm.hospitalOut.departmentId = selected.id  // 保存科室ID
    },
    // 转入医院科室选择
    onHospitalInDepartmentChange(e) {
      const index = e.detail.value
      const selected = this.departmentOptions[index]
      this.taskForm.hospitalIn.department = selected.text  // 保存科室名称
      this.taskForm.hospitalIn.departmentId = selected.id  // 保存科室ID
    },
    // 加载默认医院列表(常用医院)
    loadDefaultHospitals() {
      // 检查是否有归属机构ID
      if (!this.selectedOrganizationId) {
        console.warn('未选择归属机构,无法加载医院列表')
        return
      }
      // 转出医院:根据归属机构的区域配置加载
      this.loadHospitalsByDeptRegion('out')
      // 转入医院:根据归属机构的区域配置加载
      this.loadHospitalsByDeptRegion('in')
    },
    // 降级加载医院(按地域过滤)
    loadDefaultHospitalsByRegion() {
      // 转出医院:只加载当前区域的医院(带地域过滤)
      searchHospitals('', this.selectedRegion).then(response => {
        this.hospitalOutResults = response.data || []
        console.log('加载转出医院(当前区域):', this.selectedRegion, '数量:', this.hospitalOutResults.length)
      }).catch(error => {
        console.error('加载转出医院列表失败:', error)
        this.hospitalOutResults = []
      })
      // 转入医院:加载所有医院(不带地域过滤,后续会按地域排序)
      searchHospitals('', '').then(response => {
        const allHospitals = response.data || []
        // 将医院按地域排序:本地区域优先
        this.hospitalInResults = this.sortHospitalsByRegion(allHospitals)
        console.log('加载转入医院(全部区域):', '数量:', this.hospitalInResults.length)
      }).catch(error => {
        console.error('加载转入医院列表失败:', error)
        this.hospitalInResults = []
      })
    },
    // 根据部门区域配置加载医院
    loadHospitalsByDeptRegion(type) {
      const deptId = this.selectedOrganizationId
      if (!deptId) {
        console.warn('部门ID不存在')
        return
      }
      // 调用后端接口,根据部门的区域配置查询医院
      searchHospitalsByDeptRegion('', deptId).then(response => {
        const hospitals = response.data || []
        if (type === 'out') {
          this.hospitalOutResults = hospitals
          console.log('加载转出医院(区域配置):部门', deptId, '数量:', this.hospitalOutResults.length)
        } else if (type === 'in') {
          // 转入医院按地域排序
          this.hospitalInResults = this.sortHospitalsByRegion(hospitals)
          console.log('加载转入医院(区域配置):部门', deptId, '数量:', this.hospitalInResults.length)
        }
      }).catch(error => {
        console.error('加载医院失败(区域配置):', error)
        // 失败后降级为普通搜索
        this.loadDefaultHospitalsByRegion()
      })
    },
    // 按地域排序医院:本地区域优先,"家中"始终在最前面
    sortHospitalsByRegion(hospitals) {
      if (!hospitals || hospitals.length === 0) {
        return hospitals
      }
      const region = this.selectedRegion
      const homeHospital = []  // "家中"
      const localHospitals = []  // 本地医院
      const otherHospitals = []  // 其他医院
      hospitals.forEach(hospital => {
        // "家中"优先处理,放在最前面
        if (hospital.hospName === '家中') {
          homeHospital.push(hospital)
          return
        }
        // 判断医院是否在本地区域(省、市、区任一包含地域关键词)
        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)
        } else {
          otherHospitals.push(hospital)
        }
      })
      // "家中"在最前,本地医院其次,其他医院在后
      return [...homeHospital, ...localHospitals, ...otherHospitals]
    },
    // 转出医院输入框获得焦点
    onHospitalOutFocus() {
      // 如果没有搜索关键词,显示常用转出医院
      if (!this.hospitalOutSearchKeyword || this.hospitalOutSearchKeyword.trim() === '') {
        // 如果已经加载过常用医院,直接显示
        if (this.hospitalOutResults.length > 0) {
          this.showHospitalOutResults = true
          return
        }
        // 否则重新加载常用医院
        if (this.selectedOrganizationServiceOrderClass) {
          getFrequentOutHospitals(this.selectedOrganizationServiceOrderClass, this.selectedRegion).then(response => {
            const hospitals = response.data || []
            // 确保"家中"在最前面
            this.hospitalOutResults = this.sortHospitalsByRegion(hospitals)
            // 如果没有常用医院,降级为普通搜索
            if (this.hospitalOutResults.length === 0) {
              searchHospitals('', this.selectedOrganizationId).then(res => {
                const hospitals = res.data || []
                this.hospitalOutResults = this.sortHospitalsByRegion(hospitals)
              })
            }
          }).catch(error => {
            console.error('加载常用转出医院失败:', error)
            searchHospitals('', this.selectedOrganizationId).then(res => {
              const hospitals = res.data || []
              this.hospitalOutResults = this.sortHospitalsByRegion(hospitals)
            })
          })
        } else {
          // 没有服务单编码,使用普通搜索
          searchHospitals('', this.selectedOrganizationId).then(response => {
            const hospitals = response.data || []
            this.hospitalOutResults = this.sortHospitalsByRegion(hospitals)
          }).catch(error => {
            console.error('加载转出医院失败:', error)
            this.hospitalOutResults = []
          })
        }
      }
      this.showHospitalOutResults = true
    },
    // 转出医院搜索
    onHospitalOutSearch(e) {
      const keyword = e.detail.value
      this.hospitalOutSearchKeyword = keyword
      // 防抖处理
      if (this.searchTimer) {
        clearTimeout(this.searchTimer)
      }
      // 如果关键词为空,显示当前区域的医院
      if (!keyword || keyword.trim() === '') {
        searchHospitals('', this.selectedOrganizationId).then(response => {
          const hospitals = response.data || []
          // 确保"家中"在最前面
          this.hospitalOutResults = this.sortHospitalsByRegion(hospitals)
        }).catch(error => {
          console.error('加载转出医院失败:', error)
          this.hospitalOutResults = []
        })
        this.showHospitalOutResults = true
        return
      }
      // 有关键词时,去服务端搜索(仅限当前区域)
      this.searchTimer = setTimeout(() => {
        this.searchHospitalOut(keyword)
      }, 300)
    },
    // 搜索转出医院(仅限当前区域)
    searchHospitalOut(keyword) {
      // 传入关键词和部门ID,只搜索当前区域的医院
      searchHospitals(keyword, this.selectedOrganizationId).then(response => {
        const hospitals = response.data || []
        // 确保"家中"在最前面
        this.hospitalOutResults = this.sortHospitalsByRegion(hospitals)
        this.showHospitalOutResults = true
        console.log('搜索转出医院:', keyword, '部门ID:', this.selectedOrganizationId, '结果数:', this.hospitalOutResults.length)
      }).catch(error => {
        console.error('搜索转出医院失败:', error)
        this.hospitalOutResults = []
      })
    },
    // 选择转出医院
    selectHospitalOut(hospital) {
      this.taskForm.hospitalOut.id = hospital.hospId  // 保存医院ID
      this.taskForm.hospitalOut.name = hospital.hospName
      // 如果选择的是"家中",清空地址让用户手动输入;否则自动填充地址
      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
      this.hospitalOutResults = []
      // 保存转出医院的城市信息
      this.taskForm.hospitalOut.city = hospital.hopsCity || ''
    // 转出医院变化
    onHospitalOutChange(hospitalData) {
      console.log('转出医院变化:', hospitalData)
      // 组件已经通过 v-model 更新了 taskForm.hospitalOut
      
      // 如果转入地址已填写,自动计算距离
      if (this.taskForm.hospitalIn.address) {
        // 如果两个都不是"家中",使用医院距离计算
        if (hospital.hospName !== '家中' && this.taskForm.hospitalIn.name !== '家中') {
        if (hospitalData.name !== '家中' && this.taskForm.hospitalIn.name !== '家中') {
          this.calculateHospitalDistance()
        } else {
          // 有一个是"家中",使用地址计算
@@ -1137,130 +635,44 @@
      }
    },
    
    // 转入医院输入框获得焦点
    onHospitalInFocus() {
      // 如果没有搜索关键词,显示常用转入医院
      if (!this.hospitalInSearchKeyword || this.hospitalInSearchKeyword.trim() === '') {
        // 如果已经加载过常用医院,直接显示
        if (this.hospitalInResults.length > 0) {
          this.showHospitalInResults = true
          return
        }
    // 转出医院地址选择(当选择"家中"时使用百度地图地址建议)
    onHospitalOutAddressSelected(data) {
      // data 包含:address, location
      if (data.location) {
        this.addressCoordinates.hospitalOutAddress = data.location
        
        // 否则重新加载常用医院
        if (this.selectedOrganizationServiceOrderClass) {
          getFrequentInHospitals(this.selectedOrganizationServiceOrderClass, '').then(response => {
            const allHospitals = response.data || []
            // 按地域排序:本地区域优先
            this.hospitalInResults = this.sortHospitalsByRegion(allHospitals)
            // 如果没有常用医院,降级为普通搜索
            if (this.hospitalInResults.length === 0) {
              searchHospitals('', null).then(res => {
                const allHospitals = res.data || []
                this.hospitalInResults = this.sortHospitalsByRegion(allHospitals)
              })
            }
          }).catch(error => {
            console.error('加载常用转入医院失败:', error)
            searchHospitals('', null).then(res => {
              const allHospitals = res.data || []
              this.hospitalInResults = this.sortHospitalsByRegion(allHospitals)
            })
          })
        } else {
          // 没有服务单编码,使用普通搜索
          searchHospitals('', null).then(response => {
            const allHospitals = response.data || []
            // 按地域排序:本地区域优先
            this.hospitalInResults = this.sortHospitalsByRegion(allHospitals)
          }).catch(error => {
            console.error('加载转入医院失败:', error)
            this.hospitalInResults = []
          })
        // 如果转入地址也已填写,自动计算距离
        if (this.taskForm.hospitalIn.address) {
          this.calculateDistanceByManualAddress()
        }
      }
      this.showHospitalInResults = true
    },
    
    // 转入医院搜索
    onHospitalInSearch(e) {
      const keyword = e.detail.value
      this.hospitalInSearchKeyword = keyword
      // 防抖处理
      if (this.searchTimer) {
        clearTimeout(this.searchTimer)
      }
      // 如果关键词为空,显示所有医院(本地区域优先)
      if (!keyword || keyword.trim() === '') {
        searchHospitals('', null).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) {
      // 传入关键词,不传部门ID(搜索所有区域)
      searchHospitals(keyword, null).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)
        this.hospitalInResults = []
      })
    },
    // 选择转入医院
    selectHospitalIn(hospital) {
      this.taskForm.hospitalIn.id = hospital.hospId  // 保存医院ID
      this.taskForm.hospitalIn.name = hospital.hospName
      // 如果选择的是"家中",清空地址让用户手动输入;否则自动填充地址
      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
      this.hospitalInResults = []
      // 保存转入医院的城市信息
      this.taskForm.hospitalIn.city = hospital.hopsCity || ''
    // 转入医院变化
    onHospitalInChange(hospitalData) {
      console.log('转入医院变化:', hospitalData)
      // 组件已经通过 v-model 更新了 taskForm.hospitalIn
      
      // 如果转出地址已填写,自动计算距离
      if (this.taskForm.hospitalOut.address) {
        // 如果两个都不是"家中",使用医院距离计算
        if (hospital.hospName !== '家中' && this.taskForm.hospitalOut.name !== '家中') {
        if (hospitalData.name !== '家中' && this.taskForm.hospitalOut.name !== '家中') {
          this.calculateHospitalDistance()
        } else {
          // 有一个是"家中",使用地址计算
          this.calculateDistanceByManualAddress()
        }
      }
    },
    // 转入医院地址选择(当选择"家中"时使用百度地图地址建议)
    onHospitalInAddressSelected(data) {
      // data 包含:address, location
      if (data.location) {
        this.addressCoordinates.hospitalInAddress = data.location
        // 如果转出地址也已填写,自动计算距离
        if (this.taskForm.hospitalOut.address) {
          this.calculateDistanceByManualAddress()
        }
      }
@@ -1396,7 +808,7 @@
      console.log('按关键词过滤后,数量:', list.length)
      
      this.filteredStaffList = list
      console.log('最终过滤结果:', this.filteredStaffList)
      // console.log('最终过滤结果:', this.filteredStaffList)
    },
    
    // 切换人员选中状态
@@ -1443,168 +855,6 @@
    addStaff() {
      this.showStaffSelector()
    },
    // ==================== 地址输入联想相关方法 ====================
    // 转出地址输入监听
    onAddressOutInput(e) {
      const query = e.detail.value
      this.taskForm.hospitalOut.address = query
      // 防抖处理
      if (this.addressSearchTimer) {
        clearTimeout(this.addressSearchTimer)
      }
      // 如果输入为空,隐藏提示列表
      if (!query || query.trim() === '') {
        this.showAddressOutSuggestions = false
        this.addressOutSuggestions = []
        return
      }
      // 输入长度大于2才开始搜索
      if (query.trim().length < 2) {
        this.showAddressOutSuggestions = false
        return
      }
      // 延迟300ms搜索
      this.addressSearchTimer = setTimeout(() => {
        this.searchAddressOut(query)
      }, 300)
    },
    // 转出地址输入框获得焦点
    onAddressOutFocus() {
      // 如果有地址且有搜索结果,显示提示列表
      if (this.taskForm.hospitalOut.address && this.addressOutSuggestions.length > 0) {
        this.showAddressOutSuggestions = true
      }
    },
    // 搜索转出地址
    searchAddressOut(query) {
      // 获取当前区域(优先使用归属机构的区域)
      const region = this.selectedRegion || '广州'
      baiduPlaceSuggestion(query, region).then(response => {
        if (response.code === 200 && response.data) {
          this.addressOutSuggestions = response.data
          this.showAddressOutSuggestions = true
        } else {
          this.addressOutSuggestions = []
          this.showAddressOutSuggestions = false
        }
      }).catch(error => {
        console.error('搜索转出地址失败:', error)
        this.addressOutSuggestions = []
        this.showAddressOutSuggestions = false
      })
    },
    // 选择转出地址
    selectAddressOut(item) {
      // 填充完整地址
      const fullAddress = item.district + item.address
      this.taskForm.hospitalOut.address = fullAddress
      // 保存经纬度(如果有)
      if (item.location) {
        this.taskForm.hospitalOut.latitude = item.location.lat
        this.taskForm.hospitalOut.longitude = item.location.lng
      }
      // 隐藏提示列表
      this.showAddressOutSuggestions = false
      this.addressOutSuggestions = []
      // 如果转入地址也已填写,自动计算距离
      if (this.taskForm.hospitalIn.address) {
        this.calculateDistanceByManualAddress()
      }
    },
    // 转入地址输入监听
    onAddressInInput(e) {
      const query = e.detail.value
      this.taskForm.hospitalIn.address = query
      // 防抖处理
      if (this.addressSearchTimer) {
        clearTimeout(this.addressSearchTimer)
      }
      // 如果输入为空,隐藏提示列表
      if (!query || query.trim() === '') {
        this.showAddressInSuggestions = false
        this.addressInSuggestions = []
        return
      }
      // 输入长度大于2才开始搜索
      if (query.trim().length < 2) {
        this.showAddressInSuggestions = false
        return
      }
      // 延迟300ms搜索
      this.addressSearchTimer = setTimeout(() => {
        this.searchAddressIn(query)
      }, 300)
    },
    // 转入地址输入框获得焦点
    onAddressInFocus() {
      // 如果有地址且有搜索结果,显示提示列表
      if (this.taskForm.hospitalIn.address && this.addressInSuggestions.length > 0) {
        this.showAddressInSuggestions = true
      }
    },
    // 搜索转入地址
    searchAddressIn(query) {
      // 获取当前区域(优先使用归属机构的区域)
      const region = this.selectedRegion || '广州'
      baiduPlaceSuggestion(query, region).then(response => {
        if (response.code === 200 && response.data) {
          this.addressInSuggestions = response.data
          this.showAddressInSuggestions = true
        } else {
          this.addressInSuggestions = []
          this.showAddressInSuggestions = false
        }
      }).catch(error => {
        console.error('搜索转入地址失败:', error)
        this.addressInSuggestions = []
        this.showAddressInSuggestions = false
      })
    },
    // 选择转入地址
    selectAddressIn(item) {
      // 填充完整地址
      const fullAddress = item.district + item.address
      this.taskForm.hospitalIn.address = fullAddress
      // 保存经纬度(如果有)
      if (item.location) {
        this.taskForm.hospitalIn.latitude = item.location.lat
        this.taskForm.hospitalIn.longitude = item.location.lng
      }
      // 隐藏提示列表
      this.showAddressInSuggestions = false
      this.addressInSuggestions = []
      // 如果转出地址也已填写,自动计算距离
      if (this.taskForm.hospitalOut.address) {
        this.calculateDistanceByManualAddress()
      }
    },
    // 手动输入地址时计算距离
    calculateDistanceByManualAddress() {
      const fromAddress = this.taskForm.hospitalOut.address
      const toAddress = this.taskForm.hospitalIn.address
@@ -1694,107 +944,7 @@
        // 计算失败时不提示用户,允许用户手动输入
      })
    },
    // ==================== 病情选择相关方法 ====================
    // 显示病情选择弹窗
    showDiseaseSelector() {
      // 初始化临时选择列表(复制当前已选择的病情)
      this.tempSelectedDiseases = [...this.selectedDiseases]
      this.diseaseSearchKeyword = ''
      // 默认加载所有病情
      this.loadAllDiseases()
      this.$refs.diseasePopup.open()
    },
    // 关闭病情选择弹窗
    closeDiseaseSelector() {
      this.$refs.diseasePopup.close()
      this.diseaseSearchKeyword = ''
      this.diseaseSearchResults = []
      this.tempSelectedDiseases = []
    },
    // 病情搜索
    onDiseaseSearch(e) {
      const keyword = e.detail.value
      this.diseaseSearchKeyword = keyword
      // 防抖处理
      if (this.diseaseSearchTimer) {
        clearTimeout(this.diseaseSearchTimer)
      }
      // 如果关键词为空,加载所有病情
      if (!keyword || keyword.trim() === '') {
        this.loadAllDiseases()
        return
      }
      // 有关键词时进行搜索
      this.diseaseSearchTimer = setTimeout(() => {
        this.searchDiseaseByKeyword(keyword)
      }, 300)
    },
    // 加载所有病情(默认显示)
    loadAllDiseases() {
      // 使用空字符串或特殊标识符来获取所有病情
      // 如果后端不支持空查询,可以传入一个通配符如'%'或者修改后端接口
      searchIcd10('').then(response => {
        this.diseaseSearchResults = response.data || []
      }).catch(error => {
        console.error('加载病情列表失败:', error)
        this.diseaseSearchResults = []
      })
    },
    // 根据关键词搜索病情
    searchDiseaseByKeyword(keyword) {
      searchIcd10(keyword).then(response => {
        this.diseaseSearchResults = response.data || []
      }).catch(error => {
        console.error('搜索病情失败:', error)
        this.diseaseSearchResults = []
      })
    },
    // 切换病情选中状态
    toggleDiseaseSelection(disease) {
      const index = this.tempSelectedDiseases.findIndex(d => d.id === disease.id)
      if (index > -1) {
        // 已选中,移除
        this.tempSelectedDiseases.splice(index, 1)
      } else {
        // 未选中,添加
        this.tempSelectedDiseases.push({
          id: disease.id,
          icdCode: disease.icdCode,
          icdName: disease.icdName,
          sm: disease.sm
        })
      }
    },
    // 判断病情是否已选中
    isDiseaseSelected(diseaseId) {
      return this.tempSelectedDiseases.some(d => d.id === diseaseId)
    },
    // 确认病情选择
    confirmDiseaseSelection() {
      // 将临时选择的病情复制到正式列表
      this.selectedDiseases = [...this.tempSelectedDiseases]
      this.closeDiseaseSelector()
    },
    // 移除病情
    removeDisease(index) {
      this.selectedDiseases.splice(index, 1)
    },
    // 设置默认转运时间为当前时间
    // 手动输入地址时计算距离
    setDefaultTransferTime() {
      const now = new Date()
      const year = now.getFullYear()
@@ -1886,8 +1036,14 @@
      // 合并病情信息:选中的ICD-10疾病 + 其他描述
      let conditionText = ''
      if (this.selectedDiseases.length > 0) {
        const diseaseNames = this.selectedDiseases.map(d => `${d.icdName}(${d.icdCode})`).join('、')
        // 过滤掉病情名称为空的项,并构建病情字符串
        const diseaseNames = this.selectedDiseases
          .filter(d => d.icdName && d.icdName.trim())
          .map(d => `${d.icdName}(${d.icdCode})`)
          .join('、')
        if (diseaseNames) {
        conditionText = diseaseNames
        }
      }
      if (this.taskForm.patient.condition && this.taskForm.patient.condition.trim()) {
        if (conditionText) {
@@ -1914,14 +1070,16 @@
        documentTypeId: this.selectedDocumentTypeId, // 单据类型ID
        taskTypeId: this.selectedEmergencyTaskTypeId, // 任务类型ID
        // 病情ID列表(用于同步调度单的OrdICD_ID参数)
        diseaseIds: this.selectedDiseases.map(d => d.id),
        diseaseIds: this.selectedDiseases.filter(d => d.id !== null).map(d => d.id),
        // 将转出医院地址作为出发地,转入医院地址作为目的地
        departureAddress: this.taskForm.hospitalOut.address || '',
        destinationAddress: this.taskForm.hospitalIn.address || '',
        patient: {
          ...this.taskForm.patient,
          condition: conditionText, // 使用合并后的病情信息
          diseases: this.selectedDiseases.map(d => ({
          diseases: this.selectedDiseases
            .filter(d => d.icdName && d.icdName.trim())
            .map(d => ({
            icdId: d.id,
            icdCode: d.icdCode,
            icdName: d.icdName
@@ -2989,145 +2147,6 @@
        background-color: #ccc;
        color: #999;
      }
    }
  }
}
// 病情选择弹窗样式
.disease-selector-popup {
  background-color: white;
  border-radius: 20rpx 20rpx 0 0;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  .popup-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 30rpx;
    border-bottom: 1rpx solid #f0f0f0;
    flex-shrink: 0;
    .popup-title {
      font-size: 32rpx;
      font-weight: bold;
      color: #333;
    }
    .popup-close {
      padding: 10rpx;
    }
  }
  .search-box {
    display: flex;
    align-items: center;
    margin: 20rpx 30rpx;
    padding: 15rpx 20rpx;
    background-color: #f5f5f5;
    border-radius: 10rpx;
    flex-shrink: 0;
    .search-input {
      flex: 1;
      margin-left: 10rpx;
      font-size: 28rpx;
    }
  }
  .disease-list-popup {
    flex: 1;
    overflow-y: auto;
    padding: 0 30rpx;
    .disease-item-popup {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 25rpx 20rpx;
      border-bottom: 1rpx solid #f0f0f0;
      &:active {
        background-color: #f5f5f5;
      }
      .disease-info {
        flex: 1;
        .disease-name-row {
          display: flex;
          align-items: center;
          margin-bottom: 8rpx;
          .disease-name {
            font-size: 30rpx;
            font-weight: bold;
            color: #333;
            margin-right: 15rpx;
          }
          .disease-code {
            font-size: 24rpx;
            color: #007AFF;
            background-color: #e6f2ff;
            padding: 4rpx 12rpx;
            border-radius: 6rpx;
          }
        }
        .disease-detail-row {
          .disease-desc {
            font-size: 24rpx;
            color: #999;
            line-height: 1.5;
          }
        }
      }
      .checkbox-empty {
        width: 40rpx;
        height: 40rpx;
        border: 2rpx solid #ddd;
        border-radius: 50%;
      }
    }
    .no-data {
      text-align: center;
      padding: 100rpx 0;
      color: #999;
      text {
        display: block;
        margin-top: 20rpx;
        font-size: 28rpx;
      }
    }
  }
  .popup-footer {
    display: flex;
    padding: 20rpx 30rpx;
    border-top: 1rpx solid #f0f0f0;
    gap: 20rpx;
    flex-shrink: 0;
    button {
      flex: 1;
      height: 80rpx;
      border-radius: 10rpx;
      font-size: 30rpx;
    }
    .cancel-btn {
      background-color: #f5f5f5;
      color: #666;
    }
    .confirm-btn {
      background-color: #007AFF;
      color: white;
    }
  }
}