wlzboy
2025-11-27 668e570bd1db6bd00e4293b6977e6d3d051053ce
app/pages/task/create-emergency.vue
@@ -30,6 +30,16 @@
        />
      </view>
      
      <DepartureSelector
        :address.sync="departureAddress"
        :longitude.sync="departureLongitude"
        :latitude.sync="departureLatitude"
        :region="selectedRegion"
        :required="false"
        @address-selected="onDepartureAddressSelected"
        @location-success="onDepartureLocationSuccess"
      />
      <view class="form-item">
        <view class="form-label required">任务类型</view>
        <picker mode="selector" :range="emergencyTaskTypeOptions" range-key="text" @change="onEmergencyTaskTypeChange">
@@ -321,8 +331,9 @@
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 { searchHospitals, searchHospitalsByDeptRegion } from "@/api/hospital"
import DepartureSelector from '@/components/DepartureSelector.vue'
import { calculateDistance, baiduDistanceByAddress, baiduPlaceSuggestion } from "@/api/map"
import { searchHospitals, getFrequentOutHospitals, getFrequentInHospitals, searchHospitalsByDeptRegion } from "@/api/hospital"
import { listBranchUsers } from "@/api/system/user"
import { searchIcd10 } from "@/api/icd10"
import { calculateTransferPrice } from "@/api/price"
@@ -343,7 +354,8 @@
    MapSelector,
    OrganizationSelector,
    HospitalSelector,
    DiseaseSelector
    DiseaseSelector,
    DepartureSelector
  },
  data() {
    return {
@@ -352,6 +364,9 @@
      selectedOrganizationId: null, // 归属机构ID(部门ID)
      selectedOrganizationServiceOrderClass: '', // 归属机构的服务单编码
      selectedRegion: '', // 从归属机构中提取的地域信息(如:广州、深圳等)
      departureAddress: '', // 出发地地址
      departureLongitude: null, // 出发地经度
      departureLatitude: null, // 出发地纬度
      selectedEmergencyTaskType: '', // 选中的任务类型文本
      selectedEmergencyTaskTypeId: null, // 选中的任务类型ID
      selectedDocumentType: '', // 选中的单据类型文本
@@ -403,10 +418,6 @@
      documentTypeOptions: [], // 单据类型选项(用于picker显示)
      departmentOptions: [], // 科室字典数据
      loading: false,
      addressCoordinates: {
        hospitalOutAddress: null,
        hospitalInAddress: null
      },
      // 智能识别相关
      rawText: '',
      parseLoading: false
@@ -517,10 +528,18 @@
    },
    
    onOrganizationChange(orgData) {
      // orgData 包含:deptId, deptName, serviceOrderClass, region
      // orgData 包含:deptId, deptName, serviceOrderClass, region, departureAddress, departureLongitude, departureLatitude
      this.selectedOrganizationId = orgData.deptId
      this.selectedOrganizationServiceOrderClass = orgData.serviceOrderClass
      this.selectedRegion = orgData.region
      // 自动填充出发地信息(机构的地址和坐标)
      if (orgData.departureAddress) {
        this.departureAddress = orgData.departureAddress
        this.departureLongitude = orgData.departureLongitude || null
        this.departureLatitude = orgData.departureLatitude || null
        console.log('自动填充机构出发地:', this.departureAddress, '坐标:', this.departureLongitude, this.departureLatitude)
      }
      
      console.log('选中归属机构:', orgData.deptName, '部门ID:', orgData.deptId, '服务单编码:', orgData.serviceOrderClass, '地域:', orgData.region)
    },
@@ -635,16 +654,10 @@
      }
    },
    
    // 转出医院地址选择(当选择"家中"时使用百度地图地址建议)
    // 转出医院地址选择事件(简化,移除GPS处理)
    onHospitalOutAddressSelected(data) {
      // data 包含:address, location
      if (data.location) {
        this.addressCoordinates.hospitalOutAddress = data.location
        // 如果转入地址也已填写,自动计算距离
        if (this.taskForm.hospitalIn.address) {
          this.calculateDistanceByManualAddress()
        }
      }
    },
    
@@ -665,16 +678,10 @@
      }
    },
    
    // 转入医院地址选择(当选择"家中"时使用百度地图地址建议)
    // 转入医院地址选择事件(简化,移除GPS处理)
    onHospitalInAddressSelected(data) {
      // data 包含:address, location
      if (data.location) {
        this.addressCoordinates.hospitalInAddress = data.location
        // 如果转出地址也已填写,自动计算距离
        if (this.taskForm.hospitalOut.address) {
          this.calculateDistanceByManualAddress()
        }
      }
    },
    
@@ -1072,7 +1079,7 @@
        // 病情ID列表(用于同步调度单的OrdICD_ID参数)
        diseaseIds: this.selectedDiseases.filter(d => d.id !== null).map(d => d.id),
        // 将转出医院地址作为出发地,转入医院地址作为目的地
        departureAddress: this.taskForm.hospitalOut.address || '',
        departureAddress: this.departureAddress || this.taskForm.hospitalOut.address || '',
        destinationAddress: this.taskForm.hospitalIn.address || '',
        patient: {
          ...this.taskForm.patient,
@@ -1085,34 +1092,27 @@
              icdName: d.icdName
            }))
        },
        // 医院信息(包含医院ID、科室名称、科室ID等完整信息)
        hospitalOut: this.taskForm.hospitalOut,  // 包含: id, name, department, departmentId, bedNumber, address
        hospitalIn: this.taskForm.hospitalIn,    // 包含: id, name, department, departmentId, bedNumber, address
        // 医院信息(包含医院ID、科室名称、科室ID、GPS坐标等完整信息)
        hospitalOut: {
          ...this.taskForm.hospitalOut
          // GPS坐标由后端自动获取
        },
        hospitalIn: {
          ...this.taskForm.hospitalIn
          // GPS坐标由后端自动获取
        },
        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
      // 出发地GPS坐标(优先使用自定义的出发地坐标)
      if (this.departureLongitude && this.departureLatitude) {
        submitData.departureLongitude = this.departureLongitude
        submitData.departureLatitude = this.departureLatitude
      }
      
      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
      }
      // 目标地GPS坐标由后端根据转入医院地址自动获取
      
      return submitData
    },
@@ -1151,6 +1151,79 @@
    
   goBack() {
      uni.navigateBack()
    },
    // 获取当前位置
    getCurrentLocation() {
      uni.showLoading({
        title: '获取位置中...'
      })
      // 使用uni-app的GPS定位功能
      uni.getLocation({
        type: 'gcj02', // 返回国测局坐标,适用于国内地图
        success: (res) => {
          console.log('获取到GPS坐标:', res)
          const latitude = res.latitude
          const longitude = res.longitude
          // 保存GPS坐标
          this.departureLatitude = latitude
          this.departureLongitude = longitude
          // 调用逆地理编码接口,将坐标转换为地址
          reverseGeocoder(latitude, longitude)
            .then(response => {
              uni.hideLoading()
              if (response.code === 200 && response.data) {
                // 获取详细地址
                const address = response.data.address || response.data.formattedAddress || ''
                this.departureAddress = address
                console.log('逆地理编码成功:', address)
                this.$modal.showToast('已获取当前位置')
              } else {
                console.error('逆地理编码失败:', response.msg)
                this.$modal.showToast('位置解析失败,请手动输入地址')
              }
            })
            .catch(error => {
              uni.hideLoading()
              console.error('逆地理编码失败:', error)
              // 即使地址解析失败,也保留GPS坐标
              this.$modal.showToast('位置解析失败,但GPS坐标已保存')
            })
        },
        fail: (err) => {
          uni.hideLoading()
          console.error('获取位置失败:', err)
          // 提示用户可能的原因
          let errorMsg = '获取位置失败'
          if (err.errMsg && err.errMsg.includes('auth deny')) {
            errorMsg = '请在设置中开启位置权限'
          } else if (err.errMsg && err.errMsg.includes('timeout')) {
            errorMsg = '定位超时,请稍后重试'
          }
          this.$modal.showToast(errorMsg)
        }
      })
    },
    // 出发地地址选择(从地图建议中选择)
    onDepartureAddressSelected(data) {
      // data 包含: address, longitude, latitude, location
      console.log('出发地地址选择:', data)
      // 组件已经通过 .sync 更新了 departureAddress, departureLongitude, departureLatitude
    },
    // 出发地GPS定位成功
    onDepartureLocationSuccess(data) {
      // data 包含: address, longitude, latitude
      console.log('出发地GPS定位成功:', data)
      // 组件已经通过 .sync 更新了 departureAddress, departureLongitude, departureLatitude
    },
    
    // ==================== 智能识别相关方法 ====================
@@ -1781,6 +1854,13 @@
        font-size: 28rpx;
      }
      
      .form-tip {
        margin-top: 10rpx;
        font-size: 24rpx;
        color: #999;
        line-height: 1.5;
      }
      .disease-container {
        .disease-tags {
          display: flex;