<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="统计时间" 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="900px" 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="统计时间" :span="2">
|
{{ parseTime(detailData.createTime) }}
|
</el-descriptions-item>
|
</el-descriptions>
|
|
<!-- 分段明细表格 -->
|
<div v-if="segmentList.length > 0" style="margin-top: 20px;">
|
<el-divider content-position="left">
|
<i class="el-icon-tickets"></i> 里程分段明细
|
</el-divider>
|
|
<el-table
|
:data="segmentList"
|
size="small"
|
:max-height="400"
|
stripe
|
border
|
v-loading="segmentLoading"
|
>
|
<el-table-column type="index" label="序号" width="50" align="center" />
|
<el-table-column label="开始时间" prop="segmentStartTime" width="160" align="center">
|
<template slot-scope="scope">
|
{{ parseTime(scope.row.segmentStartTime, '{y}-{m}-{d} {h}:{i}:{s}') }}
|
</template>
|
</el-table-column>
|
<el-table-column label="结束时间" prop="segmentEndTime" width="160" align="center">
|
<template slot-scope="scope">
|
{{ parseTime(scope.row.segmentEndTime, '{y}-{m}-{d} {h}:{i}:{s}') }}
|
</template>
|
</el-table-column>
|
<el-table-column label="里程(km)" prop="segmentDistance" width="100" align="center">
|
<template slot-scope="scope">
|
<span class="mileage-value">{{ (scope.row.segmentDistance || 0).toFixed(2) }}</span>
|
</template>
|
</el-table-column>
|
|
<el-table-column label="关联任务" prop="taskCode" align="center" min-width="120">
|
<template slot-scope="scope">
|
<el-tag v-if="scope.row.taskCode" size="small" type="success">{{ scope.row.taskCode }}</el-tag>
|
<span v-else style="color: #909399;">无任务</span>
|
</template>
|
</el-table-column>
|
<el-table-column label="计算方式" prop="calculateMethod" align="center" width="100">
|
<template slot-scope="scope">
|
<el-tag size="small" :type="scope.row.calculateMethod === 'haversine' ? 'primary' : 'info'">
|
{{ scope.row.calculateMethod === 'haversine' ? '球面距离' : '直线距离' }}
|
</el-tag>
|
</template>
|
</el-table-column>
|
</el-table>
|
</div>
|
|
<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, getSegmentsByDateRange } 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: {},
|
// 分段明细列表
|
segmentList: [],
|
// 分段明细加载状态
|
segmentLoading: false,
|
// 手动统计加载状态
|
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;
|
|
// 重置分段明细
|
this.segmentList = [];
|
|
// 加载统计详情
|
getMileageStats(statsId).then(response => {
|
this.detailData = response.data;
|
this.detailOpen = true;
|
|
// 如果有车辆ID和统计日期,加载分段明细
|
if (this.detailData.vehicleId && this.detailData.statDate) {
|
this.loadSegmentDetails(this.detailData.vehicleId, this.detailData.statDate);
|
}
|
});
|
},
|
|
/** 加载分段明细 */
|
loadSegmentDetails(vehicleId, statDate) {
|
this.segmentLoading = true;
|
|
// 格式化日期:统计日期的开始和结束时间
|
const startDate = this.parseTime(statDate, '{y}-{m}-{d}');
|
const endDate = this.parseTime(statDate, '{y}-{m}-{d}');
|
|
// 查询该日期的分段里程明细
|
getSegmentsByDateRange(vehicleId, startDate, endDate).then(response => {
|
if (response.code === 200 && response.data) {
|
this.segmentList = response.data;
|
console.log('分段明细数据:', this.segmentList);
|
} else {
|
this.segmentList = [];
|
}
|
}).catch(error => {
|
console.error('加载分段明细失败', error);
|
this.segmentList = [];
|
this.$modal.msgWarning('加载分段明细失败,但不影响统计数据查看');
|
}).finally(() => {
|
this.segmentLoading = false;
|
});
|
},
|
/** 删除按钮操作 */
|
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>
|