wlzboy
2025-12-25 ae478a3d5dab28dd598d39f27429e4a544b15ad2
app/pagesTask/edit.vue
@@ -53,7 +53,7 @@
          class="form-input" 
          type="digit" 
          placeholder="请输入行驶公里数" 
          v-model="taskForm.distance"
          v-model="taskForm.transferDistance"
        />
      </view>
      
@@ -150,6 +150,13 @@
      taskId: null,
      taskDetail: null,
      mapSelectorType: '',
      // 扩展 addressCoordinates 支持多种键名
      addressCoordinates: {
        start: null,
        end: null,
        startLocation: null,
        endLocation: null
      },
      taskForm: {
        taskDescription: '',
        taskType: '',
@@ -158,7 +165,7 @@
        plannedEndTime: '',
        startLocation: '',
        endLocation: '',
        distance: '',
        transferDistance: '',
        remark: ''
      },
      loading: false
@@ -202,7 +209,7 @@
        this.taskForm.plannedEndTime = this.taskDetail.plannedEndTime || ''
        this.taskForm.startLocation = this.taskDetail.departureAddress || ''
        this.taskForm.endLocation = this.taskDetail.destinationAddress || ''
        this.taskForm.distance = this.taskDetail.estimatedDistance || ''
        this.taskForm.transferDistance = this.taskDetail.transferDistance || ''
        this.taskForm.remark = this.taskDetail.remark || ''
        
        // 设置车辆信息
@@ -213,16 +220,22 @@
        
        // 设置地址坐标(使用mixin中的方法)
        if (this.taskDetail.departureLongitude && this.taskDetail.departureLatitude) {
          this.setStartLocation({
          const startLocation = {
            lng: this.taskDetail.departureLongitude,
            lat: this.taskDetail.departureLatitude
          })
          }
          this.setStartLocation(startLocation)
          // 同时保存到 startLocation 键
          this.addressCoordinates.startLocation = startLocation
        }
        if (this.taskDetail.destinationLongitude && this.taskDetail.destinationLatitude) {
          this.setEndLocation({
          const endLocation = {
            lng: this.taskDetail.destinationLongitude,
            lat: this.taskDetail.destinationLatitude
          })
          }
          this.setEndLocation(endLocation)
          // 同时保存到 endLocation 键
          this.addressCoordinates.endLocation = endLocation
        }
      }).catch(error => {
        console.error('加载任务详情失败:', error)
@@ -264,15 +277,19 @@
      
      if (this.mapSelectorType === 'startLocation') {
        this.taskForm.startLocation = formattedAddress
        this.setLocationByAddress('start', address)
        const location = this.setLocationByAddress('start', address)
        // 同时保存到 startLocation 键
        this.addressCoordinates.startLocation = location
      } else if (this.mapSelectorType === 'endLocation') {
        this.taskForm.endLocation = formattedAddress
        this.setLocationByAddress('end', address)
        const location = this.setLocationByAddress('end', address)
        // 同时保存到 endLocation 键
        this.addressCoordinates.endLocation = location
      }
      
      // 监听mixin中的距离计算完成事件
      this.$once('distance-calculated', (distance) => {
        this.taskForm.distance = this.formatDistance(distance)
        this.taskForm.transferDistance = this.formatDistance(distance)
      })
      
      this.closeMapSelector()
@@ -323,6 +340,7 @@
    },
    
    buildSubmitData() {
      // 构建提交数据 - 使用与 TaskCreateVO 一致的结构
      const submitData = {
        taskId: this.taskId,
        taskDescription: this.taskForm.taskDescription,
@@ -330,20 +348,21 @@
        vehicleIds: this.taskForm.vehicleId ? [this.taskForm.vehicleId] : [],
        plannedStartTime: this.taskForm.plannedStartTime,
        plannedEndTime: this.taskForm.plannedEndTime,
        // 出发地地址和坐标
        departureAddress: this.taskForm.startLocation,
        departureLongitude: this.addressCoordinates.startLocation ? this.addressCoordinates.startLocation.lng : null,
        departureLatitude: this.addressCoordinates.startLocation ? this.addressCoordinates.startLocation.lat : null,
        // 目标地地址和坐标
        destinationAddress: this.taskForm.endLocation,
        estimatedDistance: this.taskForm.distance ? parseFloat(this.taskForm.distance) : null,
        destinationLongitude: this.addressCoordinates.endLocation ? this.addressCoordinates.endLocation.lng : null,
        destinationLatitude: this.addressCoordinates.endLocation ? this.addressCoordinates.endLocation.lat : null,
        // 距离(主任务字段)
        transferDistance: this.taskForm.transferDistance ? parseFloat(this.taskForm.transferDistance) : null,
        remark: this.taskForm.remark
      }
      if (this.addressCoordinates.startLocation) {
        submitData.departureLongitude = this.addressCoordinates.startLocation.lng
        submitData.departureLatitude = this.addressCoordinates.startLocation.lat
      }
      if (this.addressCoordinates.endLocation) {
        submitData.destinationLongitude = this.addressCoordinates.endLocation.lng
        submitData.destinationLatitude = this.addressCoordinates.endLocation.lat
      }
      
      return submitData