wlzboy
15 小时以前 f08739f46afe856f60ebb1d21ab23d72947629ed
app/pagesTask/edit-emergency.vue
@@ -39,6 +39,26 @@
      />
      
      <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 required">转运时间</view>
        <uni-datetime-picker 
          v-model="taskForm.transferTime" 
@@ -231,8 +251,9 @@
import uniDatetimePicker from '@/uni_modules/uni-datetime-picker/components/uni-datetime-picker/uni-datetime-picker.vue'
import uniPopup from '@/uni_modules/uni-popup/components/uni-popup/uni-popup.vue'
import { getTask, updateTask } from "@/api/task"
import { baiduDistanceByAddress } from "@/api/map"
import { tiandituDistanceByAddress } from "@/api/map"
import { calculateTransferPrice } from "@/api/price"
import { getServiceOrdAreaTypes, getServiceOrderTypes } from "@/api/dictionary"
import MapSelector from './components/map-selector.vue'
import VehicleSelector from './components/VehicleSelector.vue'
import OrganizationSelector from './components/OrganizationSelector.vue'
@@ -280,6 +301,17 @@
      departureLatitude: null,
      selectedDiseases: [], // 已选择的病情列表(确保初始化为空数组)
      selectedStaff: [], // 已选择的人员列表(确保初始化为空数组)
      // 任务类型和单据类型相关
      selectedEmergencyTaskType: '', // 选中的任务类型文本
      selectedEmergencyTaskTypeId: null, // 选中的任务类型ID
      selectedDocumentType: '', // 选中的单据类型文本
      selectedDocumentTypeId: null, // 选中的单据类型ID
      pendingTaskTypeId: null, // 等待设置的任务类型ID
      pendingDocumentTypeId: null, // 等待设置的单据类型ID
      emergencyTaskTypes: [], // 任务类型列表(从 SQL Server 动态加载)
      emergencyTaskTypeOptions: [], // 任务类型选项(用于picker显示)
      documentTypes: [], // 单据类型列表
      documentTypeOptions: [], // 单据类型选项(用于picker显示)
      taskForm: {
        transferTime: '',
        patient: {
@@ -326,6 +358,10 @@
    if (options.id) {
      this.taskId = options.id
      this.loadTaskDetail()
      // 加载任务类型数据
      this.loadEmergencyTaskTypes()
      // 加载单据类型数据
      this.loadDocumentTypes()
    } else {
      this.$modal.showToast('任务ID不能为空')
      setTimeout(() => {
@@ -420,6 +456,31 @@
          // 转运距离和价格
          this.taskForm.transferDistance = info.transferDistance ? String(info.transferDistance) : ''
          this.taskForm.price = info.transferPrice ? String(info.transferPrice) : ''
          // 任务类型和单据类型
          if (info.taskTypeId) {
            // 直接设置任务类型,如果选项还未加载完成,则在加载完成后再次设置
            const taskType = this.emergencyTaskTypeOptions.find(option => option.id == info.taskTypeId)
            if (taskType) {
              this.selectedEmergencyTaskType = taskType.text
              this.selectedEmergencyTaskTypeId = taskType.id
            } else {
              // 如果选项还未加载完成,标记需要设置的ID
              this.pendingTaskTypeId = info.taskTypeId
            }
          }
          if (info.documentTypeId) {
            // 直接设置单据类型,如果选项还未加载完成,则在加载完成后再次设置
            const docType = this.documentTypeOptions.find(option => option.id == info.documentTypeId)
            if (docType) {
              this.selectedDocumentType = docType.text
              this.selectedDocumentTypeId = docType.id
            } else {
              // 如果选项还未加载完成,标记需要设置的ID
              this.pendingDocumentTypeId = info.documentTypeId
            }
          }
        } else {
          console.warn('任务详情中没有emergencyInfo字段,尝试从主对象获取数据')
          // 兼容处理:如果emergencyInfo不存在,尝试从主对象获取
@@ -511,6 +572,92 @@
      console.log('选中车辆:', vehicle)
    },
    
    // 加载任务类型数据(从 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.taskDetail && this.taskDetail.emergencyInfo && this.taskDetail.emergencyInfo.taskTypeId) {
          const currentType = this.emergencyTaskTypeOptions.find(option => option.id == this.taskDetail.emergencyInfo.taskTypeId)
          if (currentType) {
            this.selectedEmergencyTaskType = currentType.text
            this.selectedEmergencyTaskTypeId = currentType.id
          }
        }
        // 检查是否有待设置的任务类型ID
        if (this.pendingTaskTypeId) {
          const pendingType = this.emergencyTaskTypeOptions.find(option => option.id == this.pendingTaskTypeId)
          if (pendingType) {
            this.selectedEmergencyTaskType = pendingType.text
            this.selectedEmergencyTaskTypeId = pendingType.id
            this.pendingTaskTypeId = null
          }
        }
      }).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
    },
    // 加载单据类型数据
    loadDocumentTypes() {
      getServiceOrdAreaTypes().then(response => {
        const list = response.data || []
        this.documentTypes = list
        this.documentTypeOptions = list.map(item => ({
          id: item.vID,
          text: item.vtext
        }))
        // 如果任务详情已加载,设置当前选中的单据类型
        if (this.taskDetail && this.taskDetail.emergencyInfo && this.taskDetail.emergencyInfo.documentTypeId) {
          const currentType = this.documentTypeOptions.find(option => option.id == this.taskDetail.emergencyInfo.documentTypeId)
          if (currentType) {
            this.selectedDocumentType = currentType.text
            this.selectedDocumentTypeId = currentType.id
          }
        }
        // 检查是否有待设置的单据类型ID
        if (this.pendingDocumentTypeId) {
          const pendingType = this.documentTypeOptions.find(option => option.id == this.pendingDocumentTypeId)
          if (pendingType) {
            this.selectedDocumentType = pendingType.text
            this.selectedDocumentTypeId = pendingType.id
            this.pendingDocumentTypeId = null
          }
        }
      }).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
    },
    // 加载所有机构ID
    loadAllOrganizationIds() {
      // 通过 OrganizationSelector 组件获取所有机构
@@ -569,6 +716,7 @@
        this.taskForm.hospitalOut.department = '其它'
        this.taskForm.hospitalOut.departmentId = null
      }
      // 注意:选择新的医院时,不自动更新科室信息,保持用户已选择的科室
      
      // 如果转入地址已填写,自动计算距离
      if (this.taskForm.hospitalIn.address) {
@@ -599,6 +747,7 @@
        this.taskForm.hospitalIn.department = '其它'
        this.taskForm.hospitalIn.departmentId = null
      }
      // 注意:选择新的医院时,不自动更新科室信息,保持用户已选择的科室
      
      // 如果转出地址已填写,自动计算距离
      if (this.taskForm.hospitalOut.address) {
@@ -621,6 +770,7 @@
    
    // 转出科室变化
    onHospitalOutDepartmentChange(data) {
      console.log('转出科室变化:', data)
      if (data && typeof data === 'object') {
        this.taskForm.hospitalOut.department = data.department
        this.taskForm.hospitalOut.departmentId = data.departmentId
@@ -632,6 +782,7 @@
    
    // 转入科室变化
    onHospitalInDepartmentChange(data) {
      console.log('转入科室变化:', data)
      if (data && typeof data === 'object') {
        this.taskForm.hospitalIn.department = data.department
        this.taskForm.hospitalIn.departmentId = data.departmentId
@@ -811,6 +962,16 @@
        return false
      }
      
      if (!this.selectedEmergencyTaskType) {
        this.$modal.showToast('请选择任务类型')
        return false
      }
      if (!this.selectedDocumentType) {
        this.$modal.showToast('请选择单据类型')
        return false
      }
      if (!this.taskForm.patient.contact) {
        this.$modal.showToast('请输入联系人')
        return false
@@ -826,6 +987,12 @@
        return false
      }
      
      // 验证联系电话格式
      if (this.taskForm.patient.phone && !/^1[3-9]\d{9}$/.test(this.taskForm.patient.phone)) {
        this.$modal.showToast('请输入正确的手机号码')
        return false
      }
      if (!this.taskForm.hospitalOut.name) {
        this.$modal.showToast('请输入转出医院名称')
        return false
@@ -836,6 +1003,11 @@
        return false
      }
      
      if (!this.taskForm.hospitalOut.department) {
        this.$modal.showToast('请选择转出科室')
        return false
      }
      if (!this.taskForm.hospitalIn.name) {
        this.$modal.showToast('请输入转入医院名称')
        return false
@@ -843,6 +1015,46 @@
      
      if (!this.taskForm.hospitalIn.address) {
        this.$modal.showToast('请选择转入医院地址')
        return false
      }
      if (!this.taskForm.hospitalIn.department) {
        this.$modal.showToast('请选择转入科室')
        return false
      }
      // 验证成交价必填
      if (!this.taskForm.price || this.taskForm.price.trim() === '') {
        this.$modal.showToast('请输入成交价')
        return false
      }
      // 验证成交价格式(必须是数字)
      if (isNaN(this.taskForm.price) || parseFloat(this.taskForm.price) < 0) {
        this.$modal.showToast('请输入有效的成交价')
        return false
      }
      // 验证患者身份证格式(如果填写了)
      if (this.taskForm.patient.idCard && this.taskForm.patient.idCard.trim() !== '') {
        const idCard = this.taskForm.patient.idCard.trim()
        // 简单验证18位身份证
        if (!/^\d{17}[\dXx]$/.test(idCard)) {
          this.$modal.showToast('请输入正确的18位身份证号码')
          return false
        }
      }
      // 验证病情至少选择一项或填写其他描述
      if ((!this.selectedDiseases || this.selectedDiseases.length === 0) &&
          (!this.taskForm.patient.otherCondition || this.taskForm.patient.otherCondition.trim() === '')) {
        this.$modal.showToast('请选择病情或填写其他病情描述')
        return false
      }
      // 验证执行人员至少选择一个
      if (!this.selectedStaff || this.selectedStaff.length === 0) {
        this.$modal.showToast('请至少选择一个执行人员')
        return false
      }
      
@@ -885,6 +1097,9 @@
        deptId: this.selectedOrganizationId,
        vehicleIds: this.selectedVehicleId ? [this.selectedVehicleId] : [],
        plannedStartTime: this.taskForm.transferTime,
        // 任务类型和单据类型
        taskTypeId: this.selectedEmergencyTaskTypeId,
        documentTypeId: this.selectedDocumentTypeId,
        
        // 出发地地址和坐标(使用转出医院地址)
        departureAddress: this.departureAddress || this.taskForm.hospitalOut.address,
@@ -1008,7 +1223,8 @@
      
      // 调用百度地图API计算距离
      const region = this.selectedRegion || '广州'
      baiduDistanceByAddress(fromAddress, region, toAddress, region)
      //baiduDistanceByAddress(fromAddress, region, toAddress, region)
      tiandituDistanceByAddress(fromAddress,toAddress)
        .then(response => {
          uni.hideLoading()
          
@@ -1122,6 +1338,7 @@
    }
  }
}
</script>
<style lang="scss" scoped>