fix bug
This commit is contained in:
@@ -59,20 +59,57 @@
|
||||
{{ row.vehicleNo }}
|
||||
</el-button>
|
||||
</template>
|
||||
<template #previousMonthMileage="{ row }">
|
||||
<span>{{ formatMileage(row.previousMonthMileage, row.mileageUnit) }}</span>
|
||||
</template>
|
||||
<template #currentMonthMileage="{ row }">
|
||||
<span>{{ formatMileage(row.currentMonthMileage, row.mileageUnit) }}</span>
|
||||
</template>
|
||||
<template #monthlyMileage="{ row }">
|
||||
<span>{{ formatMileage(row.monthlyMileage, row.mileageUnit) }}</span>
|
||||
</template>
|
||||
<template #totalMileage="{ row }">
|
||||
<span>{{ formatMileage(row.totalMileage, row.mileageUnit) }}</span>
|
||||
</template>
|
||||
<template #vehicleNoForm>
|
||||
<el-autocomplete
|
||||
v-model="form.vehicleNo"
|
||||
:fetch-suggestions="fetchVehicleOptions"
|
||||
:disabled="Boolean(form.id)"
|
||||
clearable
|
||||
placeholder="输入车牌号模糊查询选择"
|
||||
:placeholder="vehicleNoPlaceholder"
|
||||
value-key="value"
|
||||
class="mileage-record-page__input"
|
||||
/>
|
||||
</template>
|
||||
<template #totalMileageStart-search="{ row }">
|
||||
<div class="mileage-record-page__range">
|
||||
<el-input
|
||||
v-model="row.totalMileageStart"
|
||||
clearable
|
||||
placeholder="请输入"
|
||||
type="number"
|
||||
class="mileage-record-page__range-input"
|
||||
/>
|
||||
<span class="mileage-record-page__range-separator">-</span>
|
||||
<el-input
|
||||
v-model="row.totalMileageEnd"
|
||||
clearable
|
||||
placeholder="请输入"
|
||||
type="number"
|
||||
class="mileage-record-page__range-input"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
<template #attachments="{ row }">
|
||||
<span>{{ formatAttachments(row.attachments) }}</span>
|
||||
</template>
|
||||
<template #attachmentsForm>
|
||||
<vehicle-attachment-upload v-model="form.attachments" :readonly="boxType === 'view'" />
|
||||
</template>
|
||||
<template #attachments-form>
|
||||
<vehicle-attachment-upload v-model="form.attachments" :readonly="boxType === 'view'" />
|
||||
</template>
|
||||
</avue-crud>
|
||||
<empty-pagination
|
||||
:page="page"
|
||||
@@ -81,7 +118,7 @@
|
||||
@load="onLoad(page, query)"
|
||||
/>
|
||||
<el-dialog title="里程记录数据导入" append-to-body v-model="excelBox" width="555px">
|
||||
<avue-form :option="excelOption" v-model="excelForm" :upload-after="uploadAfter">
|
||||
<avue-form :option="excelOption" v-model="excelForm">
|
||||
<template #excelTemplate>
|
||||
<el-button type="primary" @click="handleTemplate">
|
||||
点击下载<i class="el-icon-download el-icon--right"></i>
|
||||
@@ -95,9 +132,11 @@
|
||||
<script>
|
||||
import { add, getDetail, getList, remove, update } from '@/api/vehicle/mileage-record';
|
||||
import { getList as getVehicleList } from '@/api/transportCapacity/transport-vehicle';
|
||||
import { getList as getShipList } from '@/api/transportCapacity/transport-ship';
|
||||
import { getDeptTree } from '@/api/system/dept';
|
||||
import { exportBlob } from '@/api/common';
|
||||
import { downloadXls } from '@/utils/util';
|
||||
import { openImportDialog } from '@/utils/import-excel';
|
||||
import { getToken } from '@/utils/auth';
|
||||
import { mapGetters } from 'vuex';
|
||||
import { excelOption, option } from '@/option/vehicle/mileage-record';
|
||||
@@ -121,6 +160,7 @@ export default {
|
||||
total: 0,
|
||||
},
|
||||
selectionList: [],
|
||||
boxType: '',
|
||||
data: [],
|
||||
};
|
||||
},
|
||||
@@ -141,6 +181,9 @@ export default {
|
||||
editBtn: this.hasPermission('mileage_record_edit'),
|
||||
};
|
||||
},
|
||||
vehicleNoPlaceholder() {
|
||||
return this.form.vehicleType === '船舶' ? '输入船号模糊查询选择' : '输入车牌号模糊查询选择';
|
||||
},
|
||||
ids() {
|
||||
const ids = [];
|
||||
this.selectionList.forEach(ele => {
|
||||
@@ -149,10 +192,43 @@ export default {
|
||||
return ids.join(',');
|
||||
},
|
||||
},
|
||||
watch: {
|
||||
'form.vehicleType': {
|
||||
handler(value) {
|
||||
this.updateVehicleTypeDisplays(value || '车辆');
|
||||
},
|
||||
immediate: true,
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
hasPermission(code) {
|
||||
return this.isAdmin || this.validData(this.permission[code], false);
|
||||
},
|
||||
updateVehicleTypeDisplays(vehicleType) {
|
||||
const isShip = vehicleType === '船舶';
|
||||
const unit = isShip ? '海里' : '公里';
|
||||
const vehicleTypeColumn = this.findColumn(this.option.column, 'vehicleType');
|
||||
const labelMap = {
|
||||
previousMonthMileage: isShip ? '上月统计航程数' : '上月统计里程数',
|
||||
currentMonthMileage: isShip ? '本月统计航程数' : '本月统计里程数',
|
||||
monthlyMileage: isShip ? '本月航行航程数' : '本月行驶里程数',
|
||||
totalMileage: isShip ? '累计航程数' : '累计行驶里程数',
|
||||
totalMileageStart: isShip ? '累计航程' : '累计行驶里程',
|
||||
totalMileageEnd: isShip ? '累计航程数结束值' : '累计行驶里程数结束值',
|
||||
};
|
||||
Object.keys(labelMap).forEach(prop => {
|
||||
const column = this.findColumn(this.option.column, prop);
|
||||
column.label = labelMap[prop];
|
||||
column.append = unit;
|
||||
});
|
||||
vehicleTypeColumn.disabled = Boolean(this.form.id);
|
||||
const unitColumn = this.findColumn(this.option.column, 'mileageUnit');
|
||||
unitColumn.value = unit;
|
||||
this.form.mileageUnit = unit;
|
||||
if (!this.form.id && this.form.vehicleNo) {
|
||||
this.form.vehicleNo = '';
|
||||
}
|
||||
},
|
||||
initDeptTree() {
|
||||
getDeptTree(this.userInfo.tenantId).then(res => {
|
||||
const column = this.findColumn(this.option.column, 'createDept');
|
||||
@@ -160,13 +236,27 @@ export default {
|
||||
});
|
||||
},
|
||||
fetchVehicleOptions(queryString, callback) {
|
||||
getVehicleList(1, 20, { plateNo: queryString })
|
||||
const vehicleType = this.form.vehicleType || '车辆';
|
||||
const request = vehicleType === '船舶' ? getShipList : getVehicleList;
|
||||
const params =
|
||||
vehicleType === '船舶' ? { shipIdentifierNo: queryString } : { plateNo: queryString };
|
||||
request(1, 20, params)
|
||||
.then(res => {
|
||||
const records = res.data.data.records || [];
|
||||
callback(records.map(item => ({ value: item.plateNo })));
|
||||
callback(
|
||||
records.map(item => ({
|
||||
value: vehicleType === '船舶' ? item.shipIdentifierNo || item.shipName : item.plateNo,
|
||||
}))
|
||||
);
|
||||
})
|
||||
.catch(() => callback([]));
|
||||
},
|
||||
formatMileage(value, unit) {
|
||||
if (this.isEmpty(value)) {
|
||||
return '';
|
||||
}
|
||||
return `${value} ${unit || '公里'}`;
|
||||
},
|
||||
formatAttachments(value) {
|
||||
if (!value) return '';
|
||||
if (Array.isArray(value)) return `${value.length} 个`;
|
||||
@@ -211,12 +301,21 @@ export default {
|
||||
},
|
||||
normalizeRow(row) {
|
||||
const values = { ...row };
|
||||
values.vehicleType = values.vehicleType || '车辆';
|
||||
values.mileageUnit = values.vehicleType === '船舶' ? '海里' : '公里';
|
||||
if (values.vehicleNo) {
|
||||
values.vehicleNo = values.vehicleNo.trim().toUpperCase();
|
||||
values.vehicleNo =
|
||||
values.vehicleType === '船舶'
|
||||
? values.vehicleNo.trim()
|
||||
: values.vehicleNo.trim().toUpperCase();
|
||||
}
|
||||
const previousMonthMileage = this.toNumber(values.previousMonthMileage);
|
||||
const currentMonthMileage = this.toNumber(values.currentMonthMileage);
|
||||
if (this.isEmpty(values.monthlyMileage) && previousMonthMileage !== null && currentMonthMileage !== null) {
|
||||
if (
|
||||
this.isEmpty(values.monthlyMileage) &&
|
||||
previousMonthMileage !== null &&
|
||||
currentMonthMileage !== null
|
||||
) {
|
||||
values.monthlyMileage = this.toMoney(currentMonthMileage - previousMonthMileage);
|
||||
}
|
||||
values.attachments = this.stringifyAttachments(values.attachments);
|
||||
@@ -237,11 +336,12 @@ export default {
|
||||
return true;
|
||||
},
|
||||
validateRow(row) {
|
||||
const isShip = row.vehicleType === '船舶';
|
||||
const mileageFields = [
|
||||
['previousMonthMileage', '上月统计里程'],
|
||||
['currentMonthMileage', '本月统计里程'],
|
||||
['monthlyMileage', '本月行驶里程'],
|
||||
['totalMileage', '累计行驶里程'],
|
||||
['previousMonthMileage', isShip ? '上月统计航程数' : '上月统计里程数'],
|
||||
['currentMonthMileage', isShip ? '本月统计航程数' : '本月统计里程数'],
|
||||
['monthlyMileage', isShip ? '本月航行航程数' : '本月行驶里程数'],
|
||||
['totalMileage', isShip ? '累计航程数' : '累计行驶里程数'],
|
||||
];
|
||||
if (!mileageFields.every(([prop, label]) => this.validateMileage(row[prop], label))) {
|
||||
return false;
|
||||
@@ -256,11 +356,21 @@ export default {
|
||||
monthlyMileage !== null &&
|
||||
this.toMoney(currentMonthMileage - previousMonthMileage) !== this.toMoney(monthlyMileage)
|
||||
) {
|
||||
this.$message.warning('本月行驶里程应等于本月统计里程减去上月统计里程');
|
||||
this.$message.warning(
|
||||
isShip
|
||||
? '本月航行航程数应等于本月统计航程数减去上月统计航程数'
|
||||
: '本月行驶里程数应等于本月统计里程数减去上月统计里程数'
|
||||
);
|
||||
return false;
|
||||
}
|
||||
if (totalMileage !== null && currentMonthMileage !== null && totalMileage < currentMonthMileage) {
|
||||
this.$message.warning('累计行驶里程应大于等于本月统计里程');
|
||||
if (
|
||||
totalMileage !== null &&
|
||||
currentMonthMileage !== null &&
|
||||
totalMileage < currentMonthMileage
|
||||
) {
|
||||
this.$message.warning(
|
||||
isShip ? '累计航程数应大于等于本月统计航程数' : '累计行驶里程数应大于等于本月统计里程数'
|
||||
);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -331,19 +441,32 @@ export default {
|
||||
});
|
||||
},
|
||||
beforeOpen(done, type) {
|
||||
this.boxType = type;
|
||||
const vehicleNoColumn = this.findColumn(this.option.column, 'vehicleNo');
|
||||
vehicleNoColumn.disabled = type !== 'add';
|
||||
if (type === 'add') {
|
||||
this.form.vehicleType = '车辆';
|
||||
this.form.mileageUnit = '公里';
|
||||
this.updateVehicleTypeDisplays(this.form.vehicleType);
|
||||
}
|
||||
if (['edit', 'view'].includes(type)) {
|
||||
getDetail(this.form.id).then(res => {
|
||||
const detail = res.data.data;
|
||||
detail.attachments = this.parseAttachments(detail.attachments);
|
||||
detail.vehicleType = detail.vehicleType || this.form.vehicleType || '车辆';
|
||||
detail.mileageUnit = detail.vehicleType === '船舶' ? '海里' : '公里';
|
||||
this.form = detail;
|
||||
this.updateVehicleTypeDisplays(detail.vehicleType);
|
||||
});
|
||||
}
|
||||
done();
|
||||
},
|
||||
searchReset() {
|
||||
this.query = {};
|
||||
if (this.$refs.crud?.search) {
|
||||
this.$refs.crud.search.totalMileageStart = undefined;
|
||||
this.$refs.crud.search.totalMileageEnd = undefined;
|
||||
}
|
||||
this.onLoad(this.page);
|
||||
},
|
||||
searchChange(params, done) {
|
||||
@@ -382,12 +505,7 @@ export default {
|
||||
});
|
||||
},
|
||||
handleImport() {
|
||||
this.excelBox = true;
|
||||
},
|
||||
uploadAfter(res, done) {
|
||||
this.excelBox = false;
|
||||
this.onLoad(this.page);
|
||||
done();
|
||||
openImportDialog(this, '里程记录');
|
||||
},
|
||||
handleExport() {
|
||||
this.$confirm('是否导出里程记录数据?', '提示', {
|
||||
@@ -396,7 +514,10 @@ export default {
|
||||
type: 'warning',
|
||||
}).then(() => {
|
||||
NProgress.start();
|
||||
exportBlob('/blade-transport/mileage-record/export-mileage-record', this.buildExportParams())
|
||||
exportBlob(
|
||||
'/blade-transport/mileage-record/export-mileage-record',
|
||||
this.buildExportParams()
|
||||
)
|
||||
.then(res => {
|
||||
downloadXls(res.data, `里程记录${this.$dayjs().format('YYYY-MM-DD HH:mm:ss')}.xlsx`);
|
||||
})
|
||||
@@ -413,11 +534,11 @@ export default {
|
||||
};
|
||||
},
|
||||
handleTemplate() {
|
||||
exportBlob(`/blade-transport/mileage-record/export-template?${this.website.tokenHeader}=${getToken()}`).then(
|
||||
res => {
|
||||
downloadXls(res.data, '里程记录模板.xlsx');
|
||||
}
|
||||
);
|
||||
exportBlob(
|
||||
`/blade-transport/mileage-record/export-template?${this.website.tokenHeader}=${getToken()}`
|
||||
).then(res => {
|
||||
downloadXls(res.data, '里程记录模板.xlsx');
|
||||
});
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -433,5 +554,21 @@ export default {
|
||||
&__input {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
&__range {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
&__range-input {
|
||||
width: 150px;
|
||||
}
|
||||
|
||||
&__range-separator {
|
||||
color: #606266;
|
||||
line-height: 32px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user