wlzboy
2025-11-09 13a31edf7f569cdcf15d3c43a476a2c947f47fbf
app/pages/task/create-emergency.vue
@@ -4,27 +4,55 @@
      <view class="back-btn" @click="goBack">
        <uni-icons type="arrowleft" size="20"></uni-icons>
      </view>
      <view class="title">创建急救转运任务</view>
      <view class="title">创建转运任务</view>
    </view>
    
    <view class="form-section">
      <view class="form-item">
        <view class="form-label">任务车辆</view>
        <picker mode="selector" :range="vehicles" @change="onVehicleChange">
        <view class="form-label required">任务车辆</view>
        <picker mode="selector" :range="vehicles" :value="selectedVehicleIndex" @change="onVehicleChange">
          <view class="form-input picker-input">
            {{ selectedVehicle || '请选择任务车辆' }}
            <uni-icons type="arrowright" size="16" color="#999"></uni-icons>
          </view>
        </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>
      </view>
      
      <view class="form-item">
        <view class="form-label required">任务类型</view>
        <picker mode="selector" :range="emergencyTaskTypeOptions" range-key="text" @change="onEmergencyTaskTypeChange">
          <view class="form-input picker-input">
            {{ selectedEmergencyTaskType || '请选择任务类型' }}
            <uni-icons type="arrowright" size="16" color="#999"></uni-icons>
          </view>
        </picker>
      </view>
      <view class="form-item">
        <view class="form-label required">单据类型</view>
        <picker mode="selector" :range="documentTypeOptions" range-key="text" @change="onDocumentTypeChange">
          <view class="form-input picker-input">
            {{ selectedDocumentType || '请选择单据类型' }}
            <uni-icons type="arrowright" size="16" color="#999"></uni-icons>
          </view>
        </picker>
      </view>
      <view class="form-item">
        <view class="form-label">执行任务人员</view>
        <view class="staff-list">
          <view class="staff-item" v-for="(staff, index) in selectedStaff" :key="staff.userId">
            <view class="staff-info">
              <text class="staff-name">{{ staff.nickName }}</text>
              <text class="staff-role">({{ staff.postName || staff.roleName || '未知职位' }})</text>
              <text class="staff-role">({{ getUserTypeName(staff.type) || '未知职位' }})</text>
            </view>
            <uni-icons 
              v-if="index > 0" 
@@ -47,28 +75,10 @@
        </view>
      </view>
      
      <view class="form-item">
        <view class="form-label">归属机构</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>
      </view>
      
      <view class="form-item">
        <view class="form-label">任务类型</view>
        <picker mode="selector" :range="emergencyTaskTypes" @change="onEmergencyTaskTypeChange">
          <view class="form-input picker-input">
            {{ selectedEmergencyTaskType || '请选择任务类型' }}
            <uni-icons type="arrowright" size="16" color="#999"></uni-icons>
          </view>
        </picker>
      </view>
      <view class="form-item">
        <view class="form-label">转运时间</view>
        <view class="form-label required">转运时间</view>
        <uni-datetime-picker 
          v-model="taskForm.transferTime" 
          type="datetime" 
@@ -79,7 +89,7 @@
      
      <view class="form-section-title">患者信息</view>
      <view class="form-item">
        <view class="form-label">联系人</view>
        <view class="form-label required">联系人</view>
        <input 
          class="form-input" 
          placeholder="请输入联系人" 
@@ -88,7 +98,7 @@
      </view>
      
      <view class="form-item">
        <view class="form-label">联系电话</view>
        <view class="form-label required">联系电话</view>
        <input 
          class="form-input" 
          type="number" 
@@ -98,7 +108,7 @@
      </view>
      
      <view class="form-item">
        <view class="form-label">患者姓名</view>
        <view class="form-label required">患者姓名</view>
        <input 
          class="form-input" 
          placeholder="请输入患者姓名" 
@@ -163,7 +173,7 @@
      
      <view class="form-section-title">转出医院信息</view>
      <view class="form-item">
        <view class="form-label">医院名称</view>
        <view class="form-label required">医院名称</view>
        <view class="hospital-search-container">
          <input 
            class="form-input" 
@@ -179,21 +189,33 @@
              :key="hospital.hospId"
              @click="selectHospitalOut(hospital)"
            >
              <view class="hospital-name">{{ hospital.hospName }}</view>
              <view class="hospital-address">{{ hospital.hospAddress }}</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>
        </view>
      </view>
      
      <view class="form-item">
        <view class="form-label">科室</view>
        <picker mode="selector" :range="departmentOptions" range-key="dictLabel" @change="onHospitalOutDepartmentChange">
        <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">
@@ -207,14 +229,33 @@
      
      <view class="form-item">
        <view class="form-label">转出地址</view>
        <view class="form-input picker-input disabled">
        <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">医院名称</view>
        <view class="form-label required">医院名称</view>
        <view class="hospital-search-container">
          <input 
            class="form-input" 
@@ -230,21 +271,33 @@
              :key="hospital.hospId"
              @click="selectHospitalIn(hospital)"
            >
              <view class="hospital-name">{{ hospital.hospName }}</view>
              <view class="hospital-address">{{ hospital.hospAddress }}</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>
        </view>
      </view>
      
      <view class="form-item">
        <view class="form-label">科室</view>
        <picker mode="selector" :range="departmentOptions" range-key="dictLabel" @change="onHospitalInDepartmentChange">
        <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">
@@ -258,13 +311,32 @@
      
      <view class="form-item">
        <view class="form-label">转入地址</view>
        <view class="form-input picker-input disabled">
        <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">转运公里数</view>
        <view class="form-label required">转运公里数</view>
        <input 
          class="form-input" 
          type="digit" 
@@ -274,7 +346,7 @@
      </view>
      
      <view class="form-item">
        <view class="form-label">成交价</view>
        <view class="form-label required">成交价</view>
        <input 
          class="form-input" 
          type="digit" 
@@ -313,14 +385,14 @@
        <view class="staff-filter">
          <view 
            class="filter-item" 
            :class="{ active: staffFilterType === 'all' }"
            @click="filterStaff('all')"
          >全部</view>
          <view
            class="filter-item"
            :class="{ active: staffFilterType === 'driver' }"
            @click="filterStaff('driver')"
          >司机</view>
          <view
            class="filter-item"
            :class="{ active: staffFilterType === 'doctor' }"
            @click="filterStaff('doctor')"
          >医生</view>
          <view 
            class="filter-item" 
            :class="{ active: staffFilterType === 'nurse' }"
@@ -342,7 +414,7 @@
              </view>
              <view class="staff-detail-row">
                <text class="staff-dept">{{ staff.deptName }}</text>
                <text class="staff-post">{{ staff.postName || staff.roleName || '未知职位' }}</text>
                <text class="staff-post">{{ staff.postName || staff.roleName  || '未知职位' }}</text>
              </view>
            </view>
            <uni-icons 
@@ -433,12 +505,14 @@
import uniPopup from '@/uni_modules/uni-popup/components/uni-popup/uni-popup.vue'
import { addTask } from "@/api/task"
import { listAvailableVehicles, getUserBoundVehicle } from "@/api/vehicle"
import { calculateDistance } from "@/api/map"
import { searchHospitals } from "@/api/hospital"
import { calculateDistance, baiduDistanceByAddress, baiduPlaceSuggestion } from "@/api/map"
import { searchHospitals, getFrequentOutHospitals, getFrequentInHospitals, searchHospitalsByDeptRegion } from "@/api/hospital"
import { listUser } from "@/api/system/user"
import { searchIcd10 } from "@/api/icd10"
import { getUserProfile } from "@/api/system/user"
import { getDicts } from "@/api/dict"
import { getServiceOrdAreaTypes, getServiceOrderTypes, getHospitalDepartments } from "@/api/dictionary"
import { listBranchCompany, getDept } from "@/api/system/dept"
import MapSelector from '@/components/map-selector.vue'
export default {
@@ -452,7 +526,13 @@
      selectedVehicle: '',
      selectedVehicleId: null,
      selectedOrganization: '',
      selectedEmergencyTaskType: '',
      selectedOrganizationId: null, // 归属机构ID(部门ID)
      selectedOrganizationServiceOrderClass: '', // 归属机构的服务单编码
      selectedRegion: '', // 从归属机构中提取的地域信息(如:广州、深圳等)
      selectedEmergencyTaskType: '', // 选中的任务类型文本
      selectedEmergencyTaskTypeId: null, // 选中的任务类型ID
      selectedDocumentType: '', // 选中的单据类型文本
      selectedDocumentTypeId: null, // 选中的单据类型ID
      mapSelectorType: '',
      // 医院搜索相关
      hospitalOutSearchKeyword: '',
@@ -463,12 +543,18 @@
      showHospitalInResults: false,
      searchTimer: null,
      defaultHospitals: [], // 默认的100条医院数据
      // 地址搜索提示相关
      addressOutSuggestions: [], // 转出地址提示列表
      showAddressOutSuggestions: false,
      addressInSuggestions: [], // 转入地址提示列表
      showAddressInSuggestions: false,
      addressSearchTimer: null, // 地址搜索防抖定时器
      // 人员选择相关
      selectedStaff: [], // 已选择的人员列表
      allStaffList: [], // 所有人员列表
      filteredStaffList: [], // 过滤后的人员列表
      staffSearchKeyword: '', // 人员搜索关键词
      staffFilterType: 'all', // 人员筛选类型:all/driver/nurse
      staffFilterType: 'driver', // 人员筛选类型:driver/doctor/nurse,默认选中司机
      // 病情选择相关
      selectedDiseases: [], // 已选择的病情列表
      tempSelectedDiseases: [], // 临时选择的病情列表(用于弹窗)
@@ -486,14 +572,18 @@
          condition: ''
        },
        hospitalOut: {
          id: null,  // 医院ID
          name: '',
          department: '',
          departmentId: null,  // 科室ID
          bedNumber: '',
          address: ''
        },
        hospitalIn: {
          id: null,  // 医院ID
          name: '',
          department: '',
          departmentId: null,  // 科室ID
          bedNumber: '',
          address: ''
        },
@@ -502,8 +592,12 @@
      },
      vehicles: [],
      vehicleOptions: [],
      organizations: ['广州分公司', '深圳分公司', '珠海分公司', '佛山分公司'],
      emergencyTaskTypes: ['急救转运', '航空转运'],
      organizations: [], // 归属机构列表(从后台加载分公司数据)
      organizationOptions: [], // 归属机构选项(用于picker显示)
      emergencyTaskTypes: [], // 任务类型列表(从 SQL Server 动态加载)
      emergencyTaskTypeOptions: [], // 任务类型选项(用于picker显示)
      documentTypes: [], // 单据类型列表
      documentTypeOptions: [], // 单据类型选项(用于picker显示)
      departmentOptions: [], // 科室字典数据
      loading: false,
      addressCoordinates: {
@@ -516,40 +610,60 @@
    ...mapState({
      currentUser: state => ({
        userId: state.user.userId,
        name: state.user.name || '张三',
        nickName: state.user.nickName || state.user.name || '张三',
        name: state.user.nickName || '张三',
        nickName: state.user.nickName || '张三',
        position: '司机',
        deptId: state.user.deptId || 100,
        phonenumber: state.user.phonenumber || '',
        branchCompanyId: state.user.branchCompanyId,
        branchCompanyName: state.user.branchCompanyName
      })
    })
    }),
    // 计算车辆在picker中的索引,用于默认选中
    selectedVehicleIndex() {
      if (!this.selectedVehicle || this.vehicles.length === 0) {
        return 0
      }
      const index = this.vehicles.findIndex(v => v === this.selectedVehicle)
      return index !== -1 ? index : 0
    }
  },
  onLoad(options) {
    // 设置默认转运时间为当前时间
    this.setDefaultTransferTime()
    // 先加载车辆列表,然后加载绑定车辆信息
    this.getAvailableVehicles().then(() => {
      this.getUserBoundVehicleInfo()
    })
    this.initSelectedStaff()
    this.loadDeptStaff()
    // 设置默认归属机构
    if (this.currentUser.branchCompanyName) {
      this.selectedOrganization = this.currentUser.branchCompanyName
    }
    // 加载默认医院列表(前100条)
    this.loadDefaultHospitals()
    // 加载分公司数据(会自动设置默认分公司并加载医院列表)
    this.loadBranchCompanies()
    // 加载科室字典数据
    this.loadDepartments()
    // 加载任务类型数据
    this.loadEmergencyTaskTypes()
    // 加载单据类型数据
    this.loadDocumentTypes()
  },
  methods: {
    // 获取用户绑定的车辆信息
    getUserBoundVehicleInfo() {
      getUserProfile().then(response => {
        const userInfo = response.data || response
        if (userInfo.boundVehicle) {
          const boundVehicleNo = userInfo.boundVehicle.vehicleNumber
          const boundVehicleId = userInfo.boundVehicle.vehicleId
      const userId = this.currentUser.userId
      if (!userId) {
        console.warn('用户ID不存在,无法获取绑定车辆')
        return
      }
      getUserBoundVehicle(userId).then(response => {
        const boundVehicle = response.data
        if (boundVehicle && boundVehicle.vehicleId) {
          const boundVehicleNo = boundVehicle.vehicleNo
          const boundVehicleId = boundVehicle.vehicleId
          console.log('用户绑定的车辆:', boundVehicleNo, 'ID:', boundVehicleId)
          
          // 在车辆列表中查找绑定的车辆
          const vehicleIndex = this.vehicleOptions.findIndex(v => 
@@ -560,7 +674,12 @@
            // 设置默认选中的车辆
            this.selectedVehicle = this.vehicleOptions[vehicleIndex].name
            this.selectedVehicleId = this.vehicleOptions[vehicleIndex].id
            console.log('默认选中车辆:', this.selectedVehicle)
          } else {
            console.warn('绑定的车辆不在可用车辆列表中')
          }
        } else {
          console.log('用户未绑定车辆')
        }
      }).catch(error => {
        console.error('获取用户绑定车辆信息失败:', error)
@@ -568,17 +687,21 @@
    },
    
    getAvailableVehicles() {
      const deptId = this.currentUser.deptId
      return listAvailableVehicles(deptId, 'EMERGENCY').then(response => {
        const vehicleList = response.data || response.rows || []
      // 根据用户有权限管理的分公司,查询所有可用车辆
      return listAvailableVehicles(null, 'EMERGENCY').then(response => {
        const vehicleList = response.data || []
        this.vehicleOptions = vehicleList.map(vehicle => ({
          id: vehicle.vehicleId,
          name: vehicle.vehicleNo,
          type: vehicle.vehicleType,
          status: vehicle.status
          status: vehicle.status,
          deptNames: vehicle.deptNames || [] // 车辆归属的多个分公司
        }))
        // 只显示车牌号,不显示分公司
        this.vehicles = this.vehicleOptions.map(v => v.name)
      }).catch(() => {
        console.log('加载可用车辆数量:', this.vehicles.length)
      }).catch(error => {
        console.error('加载车辆列表失败:', error)
        this.vehicles = []
      })
    },
@@ -590,54 +713,300 @@
    },
    
    onOrganizationChange(e) {
      this.selectedOrganization = this.organizations[e.detail.value]
      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()
    },
    onEmergencyTaskTypeChange(e) {
      this.selectedEmergencyTaskType = this.emergencyTaskTypes[e.detail.value]
    },
    // 加载科室字典数据
    loadDepartments() {
      getDicts('hospital_department').then(response => {
        this.departmentOptions = response.data || []
    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)
        console.error('加载分公司数据失败:', error)
        this.organizationOptions = []
        this.organizations = []
      })
    },
    // 加载科室数据(从 SQL Server 动态加载)
    loadDepartments() {
      getHospitalDepartments().then(response => {
        const list = response.data || [];
        this.departmentOptions = list.map(item => ({
          id: item.vID,
          text: item.vtext,
          dictValue: item.vtext  // 为了保持兼容性,保留dictValue字段
        }));
        // console.log('科室数据加载成功:', this.departmentOptions);
      }).catch(error => {
        console.error('加载科室数据失败:', error)
        this.departmentOptions = []
      })
    },
    // 加载任务类型数据(从 SQL Server)
    loadEmergencyTaskTypes() {
      getServiceOrderTypes().then(response => {
        const list = response.data || []
        this.emergencyTaskTypes = list
        this.emergencyTaskTypeOptions = list.map(item => ({
          id: item.vID,
          text: item.vtext
        }))
        // 默认选中第一个任务类型
        if (this.emergencyTaskTypeOptions.length > 0) {
          this.selectedEmergencyTaskType = this.emergencyTaskTypeOptions[0].text
          this.selectedEmergencyTaskTypeId = this.emergencyTaskTypeOptions[0].id
          console.log('默认选中任务类型:', this.selectedEmergencyTaskType)
        }
      }).catch(error => {
        console.error('加载任务类型失败:', error)
        this.emergencyTaskTypes = []
        this.emergencyTaskTypeOptions = []
      })
    },
    // 任务类型选择
    onEmergencyTaskTypeChange(e) {
      const index = e.detail.value
      const selected = this.emergencyTaskTypeOptions[index]
      this.selectedEmergencyTaskType = selected.text
      this.selectedEmergencyTaskTypeId = selected.id
    },
    getUserTypeName(staffType){
      switch(staffType){
        case "nurse":
          return "护士";
        case "doctor":
          return "医生";
        case "driver":
          return "司机";
        default:
          return "司机";
      }
    },
    // 加载单据类型数据
    loadDocumentTypes() {
      getServiceOrdAreaTypes().then(response => {
        const list = response.data || []
        this.documentTypes = list
        this.documentTypeOptions = list.map(item => ({
          id: item.vID,
          text: item.vtext
        }))
        // 默认选中第一个单据类型
        if (this.documentTypeOptions.length > 0) {
          this.selectedDocumentType = this.documentTypeOptions[0].text
          this.selectedDocumentTypeId = this.documentTypeOptions[0].id
          console.log('默认选中单据类型:', this.selectedDocumentType)
        }
      }).catch(error => {
        console.error('加载单据类型失败:', error)
        this.documentTypes = []
        this.documentTypeOptions = []
      })
    },
    // 单据类型选择
    onDocumentTypeChange(e) {
      const index = e.detail.value
      const selected = this.documentTypeOptions[index]
      this.selectedDocumentType = selected.text
      this.selectedDocumentTypeId = selected.id
    },
    
    // 转出医院科室选择
    onHospitalOutDepartmentChange(e) {
      const index = e.detail.value
      this.taskForm.hospitalOut.department = this.departmentOptions[index].dictValue
      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
      this.taskForm.hospitalIn.department = this.departmentOptions[index].dictValue
      const selected = this.departmentOptions[index]
      this.taskForm.hospitalIn.department = selected.text  // 保存科室名称
      this.taskForm.hospitalIn.departmentId = selected.id  // 保存科室ID
    },
    
    // 加载默认医院列表(前100条)
    // 加载默认医院列表(常用医院)
    loadDefaultHospitals() {
      // 传入空字符串或特殊标识获取前100条
      searchHospitals('').then(response => {
        this.defaultHospitals = response.data || []
        // 同时初始化两个搜索结果为默认数据
        this.hospitalOutResults = [...this.defaultHospitals]
        this.hospitalInResults = [...this.defaultHospitals]
      // 检查是否有归属机构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.defaultHospitals = []
        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() {
      // 如果没有搜索关键词,显示默认的100条数据
      // 如果没有搜索关键词,显示常用转出医院
      if (!this.hospitalOutSearchKeyword || this.hospitalOutSearchKeyword.trim() === '') {
        this.hospitalOutResults = [...this.defaultHospitals]
        // 如果已经加载过常用医院,直接显示
        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
    },
@@ -652,55 +1021,121 @@
        clearTimeout(this.searchTimer)
      }
      
      // 如果关键词为空,显示默认100条
      // 如果关键词为空,显示当前区域的医院
      if (!keyword || keyword.trim() === '') {
        this.hospitalOutResults = [...this.defaultHospitals]
        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) {
      searchHospitals(keyword).then(response => {
        this.hospitalOutResults = response.data || []
      // 传入关键词和部门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)
        console.error('搜索转出医院失败:', error)
        this.hospitalOutResults = []
      })
    },
    
    // 选择转出医院
    selectHospitalOut(hospital) {
      this.taskForm.hospitalOut.id = hospital.hospId  // 保存医院ID
      this.taskForm.hospitalOut.name = hospital.hospName
      this.taskForm.hospitalOut.address = hospital.hospAddress
      // 如果选择的是"家中",清空地址让用户手动输入;否则自动填充地址
      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 = []
      
      // 如果有GPS坐标,保存下来
      // 注意:HospData表中可能没有GPS坐标,需要根据地址进行地理编码
      // 这里先置为null,后续可以通过地址解析获取
      this.addressCoordinates.hospitalOutAddress = null
      // 保存转出医院的城市信息
      this.taskForm.hospitalOut.city = hospital.hopsCity || ''
      
      // 如果两个医院都已选择,自动计算距离
      // 如果转入地址已填写,自动计算距离
      if (this.taskForm.hospitalIn.address) {
        // 这里可以调用地址解析和距离计算
        // 暂时留空,由用户手动输入距离
        // 如果两个都不是"家中",使用医院距离计算
        if (hospital.hospName !== '家中' && this.taskForm.hospitalIn.name !== '家中') {
          this.calculateHospitalDistance()
        } else {
          // 有一个是"家中",使用地址计算
          this.calculateDistanceByManualAddress()
        }
      }
    },
    
    // 转入医院输入框获得焦点
    onHospitalInFocus() {
      // 如果没有搜索关键词,显示默认的100条数据
      // 如果没有搜索关键词,显示常用转入医院
      if (!this.hospitalInSearchKeyword || this.hospitalInSearchKeyword.trim() === '') {
        this.hospitalInResults = [...this.defaultHospitals]
        // 如果已经加载过常用医院,直接显示
        if (this.hospitalInResults.length > 0) {
          this.showHospitalInResults = true
          return
        }
        // 否则重新加载常用医院
        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 = []
          })
        }
      }
      this.showHospitalInResults = true
    },
@@ -715,57 +1150,98 @@
        clearTimeout(this.searchTimer)
      }
      
      // 如果关键词为空,显示默认100条
      // 如果关键词为空,显示所有医院(本地区域优先)
      if (!keyword || keyword.trim() === '') {
        this.hospitalInResults = [...this.defaultHospitals]
        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) {
      searchHospitals(keyword).then(response => {
        this.hospitalInResults = response.data || []
      // 传入关键词,不传部门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)
        console.error('搜索转入医院失败:', error)
        this.hospitalInResults = []
      })
    },
    
    // 选择转入医院
    selectHospitalIn(hospital) {
      this.taskForm.hospitalIn.id = hospital.hospId  // 保存医院ID
      this.taskForm.hospitalIn.name = hospital.hospName
      this.taskForm.hospitalIn.address = hospital.hospAddress
      // 如果选择的是"家中",清空地址让用户手动输入;否则自动填充地址
      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 = []
      
      // 如果有GPS坐标,保存下来
      this.addressCoordinates.hospitalInAddress = null
      // 保存转入医院的城市信息
      this.taskForm.hospitalIn.city = hospital.hopsCity || ''
      
      // 如果两个医院都已选择,自动计算距离
      // 如果转出地址已填写,自动计算距离
      if (this.taskForm.hospitalOut.address) {
        // 这里可以调用地址解析和距离计算
        // 暂时留空,由用户手动输入距离
        // 如果两个都不是"家中",使用医院距离计算
        if (hospital.hospName !== '家中' && this.taskForm.hospitalOut.name !== '家中') {
          this.calculateHospitalDistance()
        } else {
          // 有一个是"家中",使用地址计算
          this.calculateDistanceByManualAddress()
        }
      }
    },
    
    // 初始化选中的人员(默认包含当前用户)
    initSelectedStaff() {
      this.selectedStaff = [{
      // 构建当前用户对象,包含完整的角色信息
      const currentUserStaff = {
        userId: this.currentUser.userId,
        nickName: this.currentUser.nickName,
        phonenumber: this.currentUser.phonenumber,
        postName: this.currentUser.position,
        deptId: this.currentUser.deptId
      }]
        deptId: this.currentUser.deptId,
        posts: this.currentUser.posts || [],
        roles: this.currentUser.roles || [],
        dept: this.currentUser.dept || null
      }
      // 为当前用户设置角色类型
      currentUserStaff.type = this.getUserType(currentUserStaff)
      this.selectedStaff = [currentUserStaff]
    },
    
    // 加载当前用户所在分公司的所有人员
@@ -811,17 +1287,22 @@
    getUserType(user) {
      const postName = user.posts && user.posts.length > 0 ? user.posts[0].postName : ''
      const roleName = user.roles && user.roles.length > 0 ? user.roles[0].roleName : ''
      const deptName = user.dept?.deptName || ''
      // console.log("获取用户类型:", postName, roleName,user)
      // 判断是否为司机
      if (postName.includes('司机') || roleName.includes('司机')) {
      if (postName.includes('司机') || roleName.includes('司机') || deptName.includes('车队') || deptName.includes('司机')) {
        return 'driver'
      }
      // 判断是否为医生
      if (postName.includes('医生') || roleName.includes('医生') || deptName.includes('医生')) {
        return 'doctor'
      }
      // 判断是否为护士
      if (postName.includes('护士') || roleName.includes('护士')) {
      if (postName.includes('护士') || roleName.includes('护士') || deptName.includes('护士')) {
        return 'nurse'
      }
      // 其他类型
      return 'other'
      // 其他类型,默认为司机
      return 'driver'
    },
    
    // 显示人员选择弹窗
@@ -834,7 +1315,7 @@
    closeStaffSelector() {
      this.$refs.staffPopup.close()
      this.staffSearchKeyword = ''
      this.staffFilterType = 'all'
      this.staffFilterType = 'driver' // 重置为默认的司机类型
    },
    
    // 人员搜索
@@ -856,6 +1337,8 @@
      // 按类型过滤
      if (this.staffFilterType === 'driver') {
        list = list.filter(staff => staff.type === 'driver')
      } else if (this.staffFilterType === 'doctor') {
        list = list.filter(staff => staff.type === 'doctor')
      } else if (this.staffFilterType === 'nurse') {
        list = list.filter(staff => staff.type === 'nurse')
      }
@@ -915,6 +1398,208 @@
    
    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
      if (!fromAddress || !toAddress) {
        return
      }
      console.log('计算手动输入地址距离:', fromAddress, '->', toAddress)
      // 显示加载提示
      uni.showLoading({
        title: '计算距离中...'
      })
      // 调用百度地图API计算距离
      const region = this.selectedRegion || '广州'
      baiduDistanceByAddress(fromAddress, region, toAddress, region)
        .then(response => {
          uni.hideLoading()
          if (response.code === 200 && response.data) {
            const distanceInMeters = response.data.distance
            // 转换为公里,保疙1位小数
            const distanceInKm = (distanceInMeters / 1000).toFixed(1)
            this.taskForm.transferDistance = distanceInKm
            console.log('距离计算成功:', distanceInKm, 'km')
            this.$modal.showToast(`距离: ${distanceInKm}公里`)
          } else {
            console.error('距离计算失败:', response.msg)
            this.$modal.showToast('距离计算失败,请手动输入')
          }
        })
        .catch(error => {
          uni.hideLoading()
          console.error('距离计算失败:', error)
          this.$modal.showToast('距离计算失败,请手动输入')
        })
    },
    
    // ==================== 病情选择相关方法 ====================
@@ -1016,9 +1701,48 @@
      this.selectedDiseases.splice(index, 1)
    },
    
    // 设置默认转运时间为当前时间
    setDefaultTransferTime() {
      const now = new Date()
      const year = now.getFullYear()
      const month = String(now.getMonth() + 1).padStart(2, '0')
      const day = String(now.getDate()).padStart(2, '0')
      const hours = String(now.getHours()).padStart(2, '0')
      const minutes = String(now.getMinutes()).padStart(2, '0')
      const seconds = String(now.getSeconds()).padStart(2, '0')
      // 格式化为 YYYY-MM-DD HH:mm:ss
      this.taskForm.transferTime = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
    },
    validateForm() {
      if (!this.selectedVehicleId) {
        this.$modal.showToast('请选择任务车辆')
        return false
      }
      if (!this.selectedOrganizationId) {
        this.$modal.showToast('请选择归属机构')
        return false
      }
      if (!this.selectedEmergencyTaskType) {
        this.$modal.showToast('请选择任务类型')
        return false
      }
      if (!this.selectedDocumentType) {
        this.$modal.showToast('请选择单据类型')
        return false
      }
      if (!this.taskForm.transferTime) {
        this.$modal.showToast('请选择转运时间')
        return false
      }
      if (!this.taskForm.patient.contact) {
        this.$modal.showToast('请输入联系人')
        return false
      }
      
@@ -1037,8 +1761,28 @@
        return false
      }
      
      if (!this.taskForm.hospitalOut.department) {
        this.$modal.showToast('请选择转出医院科室')
        return false
      }
      if (!this.taskForm.hospitalIn.name) {
        this.$modal.showToast('请输入转入医院名称')
        return false
      }
      if (!this.taskForm.hospitalIn.department) {
        this.$modal.showToast('请选择转入医院科室')
        return false
      }
      if (!this.taskForm.transferDistance) {
        this.$modal.showToast('请输入转运公里数')
        return false
      }
      if (!this.taskForm.price) {
        this.$modal.showToast('请输入成交价')
        return false
      }
      
@@ -1062,9 +1806,25 @@
      
      const submitData = {
        taskType: 'EMERGENCY_TRANSFER',
        deptId: this.selectedOrganizationId, // 归属机构ID(部门ID)
        vehicleIds: this.selectedVehicleId ? [this.selectedVehicleId] : [],
        assigneeIds: this.selectedStaff.map(staff => staff.userId), // 添加执行人员ID列表
        transferTime: this.taskForm.transferTime,
        assigneeIds: this.selectedStaff.map(staff => staff.userId), // 执行人员ID列表
        assigneeId: this.selectedStaff.length > 0 ? this.selectedStaff[0].userId : null, // 主要执行人
        // 执行人员详细信息(包含角色类型)
        assignees: this.selectedStaff.map(staff => ({
          userId: staff.userId,
          userName: staff.nickName,
          userType: staff.type // driver/doctor/nurse
        })),
        transferTime: this.taskForm.transferTime, // 转运时间
        plannedStartTime: this.taskForm.transferTime, // 计划开始时间
        documentTypeId: this.selectedDocumentTypeId, // 单据类型ID
        taskTypeId: this.selectedEmergencyTaskTypeId, // 任务类型ID
        // 病情ID列表(用于同步调度单的OrdICD_ID参数)
        diseaseIds: this.selectedDiseases.map(d => d.id),
        // 将转出医院地址作为出发地,转入医院地址作为目的地
        departureAddress: this.taskForm.hospitalOut.address || '',
        destinationAddress: this.taskForm.hospitalIn.address || '',
        patient: {
          ...this.taskForm.patient,
          condition: conditionText, // 使用合并后的病情信息
@@ -1074,22 +1834,33 @@
            icdName: d.icdName
          }))
        },
        hospitalOut: this.taskForm.hospitalOut,
        hospitalIn: this.taskForm.hospitalIn,
        // 医院信息(包含医院ID、科室名称、科室ID等完整信息)
        hospitalOut: this.taskForm.hospitalOut,  // 包含: id, name, department, departmentId, bedNumber, address
        hospitalIn: this.taskForm.hospitalIn,    // 包含: id, name, department, departmentId, bedNumber, address
        transferDistance: this.taskForm.transferDistance ? parseFloat(this.taskForm.transferDistance) : null,
        price: this.taskForm.price ? parseFloat(this.taskForm.price) : null
      }
      
      if (this.addressCoordinates.hospitalOutAddress) {
        // 转出医院GPS坐标写入扩展表
        if (!submitData.hospitalOut) submitData.hospitalOut = {}
        submitData.hospitalOut.longitude = this.addressCoordinates.hospitalOutAddress.lng
        submitData.hospitalOut.latitude = this.addressCoordinates.hospitalOutAddress.lat
        // 同时写入主任务表的出发地经纬度
        submitData.departureLongitude = this.addressCoordinates.hospitalOutAddress.lng
        submitData.departureLatitude = this.addressCoordinates.hospitalOutAddress.lat
      }
      
      if (this.addressCoordinates.hospitalInAddress) {
        // 转入医院GPS坐标写入扩展表
        if (!submitData.hospitalIn) submitData.hospitalIn = {}
        submitData.hospitalIn.longitude = this.addressCoordinates.hospitalInAddress.lng
        submitData.hospitalIn.latitude = this.addressCoordinates.hospitalInAddress.lat
        // 同时写入主任务表的目的地经纬度
        submitData.destinationLongitude = this.addressCoordinates.hospitalInAddress.lng
        submitData.destinationLatitude = this.addressCoordinates.hospitalInAddress.lat
      }
      
      return submitData
@@ -1107,11 +1878,18 @@
        addTask(submitData).then(response => {
          this.loading = false
          this.$modal.showToast('任务创建成功')
          // 延迟跳转,让用户看到成功提示
          setTimeout(() => {
            uni.redirectTo({
              url: '/pages/task/index'
            // 跳转到任务列表并触发刷新
            uni.switchTab({
              url: '/pages/task/index',
              success: () => {
                // 使用事件总线通知任务列表页面刷新
                uni.$emit('refreshTaskList')
              }
            })
          }, 1500)
          }, 1000)
        }).catch(error => {
          this.loading = false
          console.error('任务创建失败:', error)
@@ -1122,6 +1900,68 @@
    
    goBack() {
      uni.navigateBack()
    },
    // 合并医院地址(省 + 市 + 区 + 详细地址)
    buildFullAddress(hospital) {
      const parts = []
      if (hospital.hopsProvince) {
        parts.push(hospital.hopsProvince)
      }
      if (hospital.hopsCity) {
        parts.push(hospital.hopsCity)
      }
      if (hospital.hopsArea) {
        parts.push(hospital.hopsArea)
      }
      if (hospital.hospAddress) {
        parts.push(hospital.hospAddress)
      }
      return parts.join('')
    },
    // 自动计算两个医院之间的距离
    calculateHospitalDistance() {
      const fromAddress = this.taskForm.hospitalOut.address
      const fromCity = this.taskForm.hospitalOut.city
      const toAddress = this.taskForm.hospitalIn.address
      const toCity = this.taskForm.hospitalIn.city
      if (!fromAddress || !toAddress) {
        console.log('地址信息不完整,无法计算距离')
        return
      }
      console.log('开始计算距离:', fromAddress, '->', toAddress)
      // 显示加载提示
      uni.showLoading({
        title: '计算距离中...'
      })
      // 调用百度地图API计算距离
      baiduDistanceByAddress(fromAddress, fromCity, toAddress, toCity)
        .then(response => {
          uni.hideLoading()
          if (response.code === 200 && response.data) {
            const distanceInMeters = response.data.distance
            // 转换为公里,保留1位小数
            const distanceInKm = (distanceInMeters / 1000).toFixed(1)
            this.taskForm.transferDistance = distanceInKm
            console.log('距离计算成功:', distanceInKm, 'km')
            // this.$modal.showToast(`距离计算成功: ${distanceInKm}公里`)
          } else {
            console.error('距离计算失败:', response.msg)
            this.$modal.showToast('距离计算失败,请手动输入')
          }
        })
        .catch(error => {
          uni.hideLoading()
          console.error('距离计算失败:', error)
          this.$modal.showToast('距离计算失败,请手动输入')
        })
    }
  }
}
@@ -1178,6 +2018,13 @@
        font-size: 28rpx;
        margin-bottom: 15rpx;
        color: #333;
        &.required::before {
          content: '*';
          color: #ff4d4f;
          margin-right: 4rpx;
          font-weight: bold;
        }
      }
      
      .hospital-search-container {
@@ -1213,6 +2060,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 {
@@ -1223,6 +2078,49 @@
        }
      }
      
      .address-input-container {
        position: relative;
        .address-suggestions {
          position: absolute;
          top: 75rpx;
          left: 0;
          right: 0;
          max-height: 400rpx;
          background-color: white;
          border: 1rpx solid #eee;
          border-radius: 10rpx;
          box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.1);
          z-index: 100;
          overflow-y: auto;
          .address-suggestion-item {
            padding: 20rpx 30rpx;
            border-bottom: 1rpx solid #f0f0f0;
            &:last-child {
              border-bottom: none;
            }
            &:active {
              background-color: #f5f5f5;
            }
            .suggestion-name {
              font-size: 28rpx;
              color: #333;
              font-weight: bold;
              margin-bottom: 8rpx;
            }
            .suggestion-address {
              font-size: 24rpx;
              color: #999;
            }
          }
        }
      }
      .form-input {
        height: 70rpx;
        padding: 0 20rpx;