wlzboy
2025-11-16 f67945d53b20f6a45ae50b27d74c966eb1355bb4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="88px">
      <el-form-item label="归属分公司" prop="deptId">
        <el-select
          v-model="queryParams.deptId"
          placeholder="请选择分公司"
          clearable
          filterable
          size="small"
          style="width: 200px"
        >
          <el-option
            v-for="dept in deptOptions"
            :key="dept.deptId"
            :label="dept.deptName"
            :value="dept.deptId"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="车牌号" prop="vehicleNo">
        <el-input
          v-model="queryParams.vehicleNo"
          placeholder="请输入车牌号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="统计日期" prop="statDate">
        <el-date-picker
          v-model="queryParams.statDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择统计日期"
          clearable
          size="small"
        />
      </el-form-item>
      <el-form-item label="日期范围">
        <el-date-picker
          v-model="dateRange"
          size="small"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
 
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-s-operation"
          size="mini"
          @click="handleCalculate"
          v-hasPermi="['system:mileageStats:calculate']"
        >手动统计</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="info"
          plain
          icon="el-icon-s-grid"
          size="mini"
          @click="handleBatchCalculate"
          v-hasPermi="['system:mileageStats:batch']"
        >批量统计</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:mileageStats:export']"
        >导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:mileageStats:remove']"
        >删除</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
 
    <el-table v-loading="loading" :data="statsList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="车牌号" align="center" prop="vehicleNo" width="120" fixed />
      <el-table-column label="归属分公司" align="center" prop="deptName" width="150" show-overflow-tooltip />
      <el-table-column label="统计日期" align="center" prop="statDate" width="120">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.statDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="总里程(km)" align="center" prop="totalMileage" width="110">
        <template slot-scope="scope">
          <span class="mileage-value">{{ scope.row.totalMileage || '0.00' }}</span>
        </template>
      </el-table-column>
      <el-table-column label="任务里程(km)" align="center" prop="taskMileage" width="120">
        <template slot-scope="scope">
          <span class="mileage-value task-mileage">{{ scope.row.taskMileage || '0.00' }}</span>
        </template>
      </el-table-column>
      <el-table-column label="非任务里程(km)" align="center" prop="nonTaskMileage" width="130">
        <template slot-scope="scope">
          <span class="mileage-value">{{ scope.row.nonTaskMileage || '0.00' }}</span>
        </template>
      </el-table-column>
      <el-table-column label="任务占比" align="center" prop="taskRatio" width="100">
        <template slot-scope="scope">
          <el-tag :type="getRatioType(scope.row.taskRatio)">
            {{ formatRatio(scope.row.taskRatio) }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column label="GPS点数" align="center" prop="gpsPointCount" width="90" />
      <el-table-column label="任务数" align="center" prop="taskCount" width="80" />
      <el-table-column label="分段数" align="center" prop="segmentCount" width="80" />
      <el-table-column label="统计时间" align="center" prop="createTime" width="160">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="120">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleView(scope.row)"
            v-hasPermi="['system:mileageStats:query']"
          >详情</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:mileageStats:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
 
    <!-- 手动统计对话框 -->
    <el-dialog title="手动里程统计" :visible.sync="calculateOpen" width="500px" append-to-body>
      <el-form ref="calculateForm" :model="calculateForm" :rules="calculateRules" label-width="100px">
        <el-form-item label="车辆ID" prop="vehicleId">
          <el-input v-model="calculateForm.vehicleId" placeholder="请输入车辆ID" type="number" />
        </el-form-item>
        <el-form-item label="统计日期" prop="statDate">
          <el-date-picker
            v-model="calculateForm.statDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择统计日期"
            style="width: 100%"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitCalculate" :loading="calculateLoading">开始统计</el-button>
        <el-button @click="calculateOpen = false">取 消</el-button>
      </div>
    </el-dialog>
 
    <!-- 批量统计对话框 -->
    <el-dialog title="批量里程统计" :visible.sync="batchCalculateOpen" width="500px" append-to-body>
      <el-form ref="batchCalculateForm" :model="batchCalculateForm" :rules="batchCalculateRules" label-width="100px">
        <el-form-item label="统计日期" prop="statDate">
          <el-date-picker
            v-model="batchCalculateForm.statDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择统计日期"
            style="width: 100%"
          />
        </el-form-item>
        <el-alert
          title="提示"
          type="warning"
          description="批量统计将对所有活跃车辆进行指定日期的里程计算,可能需要较长时间,请耐心等待。"
          :closable="false"
          show-icon
        />
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitBatchCalculate" :loading="batchCalculateLoading">开始统计</el-button>
        <el-button @click="batchCalculateOpen = false">取 消</el-button>
      </div>
    </el-dialog>
 
    <!-- 详情对话框 -->
    <el-dialog title="里程统计详情" :visible.sync="detailOpen" width="600px" append-to-body>
      <el-descriptions :column="2" border>
        <el-descriptions-item label="车牌号">{{ detailData.vehicleNo }}</el-descriptions-item>
        <el-descriptions-item label="归属分公司">{{ detailData.deptName || '-' }}</el-descriptions-item>
        <el-descriptions-item label="统计日期">
          {{ parseTime(detailData.statDate, '{y}-{m}-{d}') }}
        </el-descriptions-item>
        <el-descriptions-item label="总里程">
          <span class="detail-value">{{ detailData.totalMileage }} km</span>
        </el-descriptions-item>
        <el-descriptions-item label="任务里程">
          <span class="detail-value task-mileage">{{ detailData.taskMileage }} km</span>
        </el-descriptions-item>
        <el-descriptions-item label="非任务里程">
          <span class="detail-value">{{ detailData.nonTaskMileage }} km</span>
        </el-descriptions-item>
        <el-descriptions-item label="任务占比">
          <el-tag :type="getRatioType(detailData.taskRatio)">
            {{ formatRatio(detailData.taskRatio) }}
          </el-tag>
        </el-descriptions-item>
        <el-descriptions-item label="GPS点数">{{ detailData.gpsPointCount }}</el-descriptions-item>
        <el-descriptions-item label="任务数">{{ detailData.taskCount }}</el-descriptions-item>
        <el-descriptions-item label="分段数">{{ detailData.segmentCount }}</el-descriptions-item>
        <el-descriptions-item label="数据来源">
          <el-tag :type="detailData.dataSource === 'segment' ? 'success' : 'info'" size="small">
            {{ detailData.dataSource === 'segment' ? '从分段汇总' : '直接计算' }}
          </el-tag>
        </el-descriptions-item>
        <el-descriptions-item label="统计时间" :span="2">
          {{ parseTime(detailData.createTime) }}
        </el-descriptions-item>
      </el-descriptions>
      <div slot="footer" class="dialog-footer">
        <el-button @click="detailOpen = false">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>
 
<script>
import { listMileageStats, getMileageStats, delMileageStats, calculateMileageStats, batchCalculateMileageStats } from "@/api/system/mileageStats";
import { listDept } from "@/api/system/dept";
 
export default {
  name: "MileageStats",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 车辆里程统计表格数据
      statsList: [],
      // 分公司选项
      deptOptions: [],
      // 日期范围
      dateRange: [],
      // 弹出层标题
      title: "",
      // 是否显示手动统计弹出层
      calculateOpen: false,
      // 是否显示批量统计弹出层
      batchCalculateOpen: false,
      // 是否显示详情弹出层
      detailOpen: false,
      // 详情数据
      detailData: {},
      // 手动统计加载状态
      calculateLoading: false,
      // 批量统计加载状态
      batchCalculateLoading: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        vehicleId: null,
        vehicleNo: null,
        deptId: null,
        statDate: null
      },
      // 手动统计表单
      calculateForm: {
        vehicleId: null,
        statDate: null
      },
      // 批量统计表单
      batchCalculateForm: {
        statDate: null
      },
      // 手动统计表单校验
      calculateRules: {
        vehicleId: [
          { required: true, message: "车辆ID不能为空", trigger: "blur" }
        ],
        statDate: [
          { required: true, message: "统计日期不能为空", trigger: "change" }
        ]
      },
      // 批量统计表单校验
      batchCalculateRules: {
        statDate: [
          { required: true, message: "统计日期不能为空", trigger: "change" }
        ]
      }
    };
  },
  created() {
    this.getList();
    this.getDeptList();
  },
  methods: {
    /** 查询分公司列表 */
    getDeptList() {
      listDept().then(response => {
        this.deptOptions = response.data || [];
      });
    },
    /** 查询车辆里程统计列表 */
    getList() {
      this.loading = true;
      listMileageStats(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        this.statsList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.statsId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 手动统计按钮操作 */
    handleCalculate() {
      this.reset();
      this.calculateOpen = true;
    },
    /** 批量统计按钮操作 */
    handleBatchCalculate() {
      this.batchCalculateForm = {
        statDate: null
      };
      this.batchCalculateOpen = true;
    },
    /** 提交手动统计 */
    submitCalculate() {
      this.$refs["calculateForm"].validate(valid => {
        if (valid) {
          this.calculateLoading = true;
          calculateMileageStats(this.calculateForm.vehicleId, this.calculateForm.statDate).then(response => {
            this.$modal.msgSuccess("里程统计完成");
            this.calculateOpen = false;
            this.calculateLoading = false;
            this.getList();
          }).catch(() => {
            this.calculateLoading = false;
          });
        }
      });
    },
    /** 提交批量统计 */
    submitBatchCalculate() {
      this.$refs["batchCalculateForm"].validate(valid => {
        if (valid) {
          this.$modal.confirm('确认要对所有活跃车辆进行里程统计吗?').then(() => {
            this.batchCalculateLoading = true;
            batchCalculateMileageStats(this.batchCalculateForm.statDate).then(response => {
              this.$modal.msgSuccess(response.msg || "批量里程统计完成");
              this.batchCalculateOpen = false;
              this.batchCalculateLoading = false;
              this.getList();
            }).catch(() => {
              this.batchCalculateLoading = false;
            });
          });
        }
      });
    },
    /** 查看详情按钮操作 */
    handleView(row) {
      const statsId = row.statsId;
      getMileageStats(statsId).then(response => {
        this.detailData = response.data;
        this.detailOpen = true;
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const statsIds = row.statsId || this.ids;
      this.$modal.confirm('是否确认删除选中的车辆里程统计数据?').then(function() {
        return delMileageStats(statsIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/mileageStats/export', {
        ...this.queryParams
      }, `车辆里程统计_${new Date().getTime()}.xlsx`)
    },
    /** 格式化任务占比显示 */
    formatRatio(ratio) {
      if (ratio === null || ratio === undefined) {
        return '0%';
      }
      return (ratio * 100).toFixed(2) + '%';
    },
    /** 根据占比获取标签类型 */
    getRatioType(ratio) {
      if (ratio === null || ratio === undefined) {
        return 'info';
      }
      const percent = ratio * 100;
      if (percent >= 80) {
        return 'success';
      } else if (percent >= 60) {
        return '';
      } else if (percent >= 40) {
        return 'warning';
      } else {
        return 'danger';
      }
    },
    // 表单重置
    reset() {
      this.calculateForm = {
        vehicleId: null,
        statDate: null
      };
      this.resetForm("calculateForm");
    }
  }
};
</script>
 
<style scoped>
.mileage-value {
  font-weight: bold;
  color: #409EFF;
}
 
.task-mileage {
  color: #67C23A;
}
 
.detail-value {
  font-size: 16px;
  font-weight: bold;
}
</style>