xyc
昨天 b425da0611b39f20fc868645c59e17f72b70d148
traffic-audit-web/src/views/HolidayStat.vue
@@ -100,7 +100,10 @@
            <el-table :data="adjustments" border stripe size="small" style="margin-top:12px" v-loading="adjustmentLoading">
              <el-table-column prop="year" label="年份" width="90" align="center"></el-table-column>
              <el-table-column prop="flowDate" label="日期" width="130" align="center"></el-table-column>
              <el-table-column label="调整后国省道车流(万辆次)" width="230" align="right">
              <el-table-column label="调整前国省道车流量(万辆次)" width="240" align="right">
                <template slot-scope="s">{{ formatOriginalAdjustmentValue(s.row.originalValue) }}</template>
              </el-table-column>
              <el-table-column label="调整后国省道车流量(万辆次)" width="240" align="right">
                <template slot-scope="s">{{ formatAdjustmentValue(s.row.adjustedValue) }}</template>
              </el-table-column>
              <el-table-column prop="reason" label="调整原因" min-width="280" show-overflow-tooltip></el-table-column>
@@ -113,15 +116,20 @@
              </el-table-column>
            </el-table>
            <el-dialog :title="adjustmentForm.id ? '编辑调整' : '新增调整'" :visible.sync="adjustmentDialogVisible" width="560px" v-dialog-drag>
              <el-form label-width="160px">
              <el-form label-width="220px">
                <el-form-item label="年份">
                  <el-select v-model="adjustmentForm.year" style="width:100%" @change="adjustmentForm.flowDate = ''">
                  <el-select v-model="adjustmentForm.year" style="width:100%" @change="onAdjustmentYearChange">
                    <el-option v-for="item in availableAdjustmentYears" :key="item" :label="item + '年'" :value="item"></el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="日期">
                  <el-date-picker v-model="adjustmentForm.flowDate" type="date" value-format="yyyy-MM-dd"
                                  style="width:100%" :picker-options="adjustmentDatePickerOptions" placeholder="选择日期"></el-date-picker>
                                  style="width:100%" :picker-options="adjustmentDatePickerOptions" placeholder="选择日期"
                                  @change="onAdjustmentDateChange"></el-date-picker>
                </el-form-item>
                <el-form-item label="调整前国省道车流量(万辆次)">
                  <el-input :value="formatOriginalAdjustmentValue(adjustmentForm.originalValue)" readonly
                            :placeholder="adjustmentOriginalLoading ? '查询中...' : ''"></el-input>
                </el-form-item>
                <el-form-item label="调整后车流量(万辆次)">
                  <el-input-number v-model="adjustmentForm.adjustedValue" :min="0" :precision="4" :step="0.0001" controls-position="right" style="width:100%"></el-input-number>
@@ -249,10 +257,13 @@
      adjustmentLoading: false,
      adjustmentDialogVisible: false,
      adjustmentSaving: false,
      adjustmentOriginalLoading: false,
      adjustmentOriginalRequestId: 0,
      adjustmentForm: {
        id: null,
        year: new Date().getFullYear() - 1,
        flowDate: '',
        originalValue: null,
        adjustedValue: null,
        reason: ''
      }
@@ -319,11 +330,49 @@
        id: source.id || null,
        year: source.year || this.adjustmentYear,
        flowDate: source.flowDate || '',
        originalValue: source.originalValue === undefined || source.originalValue === null
          ? null : Number(source.originalValue),
        adjustedValue: source.adjustedValue === undefined || source.adjustedValue === null
          ? null : Number(source.adjustedValue),
        reason: source.reason || ''
      }
      this.adjustmentDialogVisible = true
      this.loadAdjustmentOriginalValue()
    },
    onAdjustmentYearChange() {
      this.adjustmentOriginalRequestId += 1
      this.adjustmentOriginalLoading = false
      this.adjustmentForm.flowDate = ''
      this.adjustmentForm.originalValue = null
    },
    onAdjustmentDateChange() {
      this.loadAdjustmentOriginalValue()
    },
    loadAdjustmentOriginalValue() {
      const year = this.adjustmentForm.year
      const flowDate = this.adjustmentForm.flowDate
      const requestId = ++this.adjustmentOriginalRequestId
      this.adjustmentForm.originalValue = null
      if (!year || !flowDate) {
        this.adjustmentOriginalLoading = false
        return
      }
      this.adjustmentOriginalLoading = true
      api.get('/holiday/adjustments/source-value', { params: { year: year, flowDate: flowDate } })
        .then(res => {
          if (requestId !== this.adjustmentOriginalRequestId) return
          if (res.code !== 200) throw new Error(res.message || '调整前值加载失败')
          this.adjustmentForm.originalValue = res.data === null || res.data === undefined || res.data === ''
            ? null : Number(res.data)
        })
        .catch(err => {
          if (requestId !== this.adjustmentOriginalRequestId) return
          this.adjustmentForm.originalValue = null
          this.showError(err, '调整前值加载失败')
        })
        .finally(() => {
          if (requestId === this.adjustmentOriginalRequestId) this.adjustmentOriginalLoading = false
        })
    },
    saveAdjustment() {
      const form = this.adjustmentForm
@@ -582,6 +631,10 @@
      if (!Number.isFinite(number)) return value
      return number.toFixed(4)
    },
    formatOriginalAdjustmentValue(value) {
      if (value === null || value === undefined || value === '') return ''
      return this.formatAdjustmentValue(value)
    },
    formatDateTime(value) {
      if (!value) return '—'
      return String(value).replace('T', ' ').slice(0, 19)