431 lines
13 KiB
Vue
431 lines
13 KiB
Vue
<template>
|
|
<basic-container class="vehicle-dispatch-page">
|
|
<avue-crud
|
|
ref="crud"
|
|
v-model="form"
|
|
v-model:page="page"
|
|
:data="data"
|
|
:option="option"
|
|
:permission="permissionList"
|
|
:table-loading="loading"
|
|
:before-open="beforeOpen"
|
|
@row-save="rowSave"
|
|
@row-update="rowUpdate"
|
|
@search-change="searchChange"
|
|
@search-reset="searchReset"
|
|
@selection-change="selectionChange"
|
|
@current-change="currentChange"
|
|
@size-change="sizeChange"
|
|
@refresh-change="refreshChange"
|
|
@on-load="onLoad"
|
|
>
|
|
<template #menu-left>
|
|
<el-button
|
|
v-if="hasPermission('vehicle_dispatch_add')"
|
|
type="primary"
|
|
@click="$refs.crud.rowAdd()"
|
|
>
|
|
新增
|
|
</el-button>
|
|
<el-button
|
|
v-if="hasPermission('vehicle_dispatch_export')"
|
|
type="primary"
|
|
plain
|
|
@click="handleExport"
|
|
>
|
|
导出
|
|
</el-button>
|
|
</template>
|
|
<template #applicationNo="{ row }">
|
|
<el-link type="primary" @click="$refs.crud.rowView(row)">{{ row.applicationNo }}</el-link>
|
|
</template>
|
|
<template #plateNo-form>
|
|
<el-autocomplete
|
|
class="vehicle-dispatch-form-control"
|
|
v-model="form.plateNo"
|
|
value-key="value"
|
|
clearable
|
|
:fetch-suggestions="fetchVehicleSuggestions"
|
|
:disabled="dialogType === 'view'"
|
|
placeholder="请选择车牌号"
|
|
@input="handleVehicleInput"
|
|
@select="handleVehicleSelect"
|
|
@blur="handleVehicleBlur"
|
|
/>
|
|
</template>
|
|
<template #useDepartment-form>
|
|
<el-cascader
|
|
class="vehicle-dispatch-form-control"
|
|
v-model="deptCascaderValue"
|
|
:options="deptOptions"
|
|
:props="deptCascaderProps"
|
|
:disabled="dialogType === 'view'"
|
|
clearable
|
|
filterable
|
|
placeholder="请选择使用部门"
|
|
@change="handleDepartmentChange"
|
|
/>
|
|
</template>
|
|
<template #attachments-form>
|
|
<vehicle-attachment-table v-model="form.attachments" :readonly="dialogType === 'view'" />
|
|
</template>
|
|
<template #approvalStatus="{ row }">
|
|
<el-tag :type="statusTagType(row.approvalStatus)" class="status-text">
|
|
{{ statusName(row.approvalStatus) }}
|
|
</el-tag>
|
|
</template>
|
|
<template #menu="{ row }">
|
|
<el-link
|
|
v-if="hasPermission('vehicle_dispatch_view')"
|
|
type="primary"
|
|
@click="$refs.crud.rowView(row)"
|
|
>
|
|
查看
|
|
</el-link>
|
|
<el-link
|
|
v-if="
|
|
hasPermission('vehicle_dispatch_edit') &&
|
|
['draft', 'rejected'].includes(row.approvalStatus)
|
|
"
|
|
type="primary"
|
|
@click="$refs.crud.rowEdit(row)"
|
|
>
|
|
编辑
|
|
</el-link>
|
|
<el-link
|
|
v-if="hasPermission('vehicle_dispatch_submit') && row.approvalStatus === 'draft'"
|
|
type="primary"
|
|
@click="handleSubmitApproval(row)"
|
|
>
|
|
提交
|
|
</el-link>
|
|
<el-link
|
|
v-if="hasPermission('vehicle_dispatch_approve') && row.approvalStatus === 'reviewing'"
|
|
type="success"
|
|
@click="handleApprove(row)"
|
|
>
|
|
审核通过
|
|
</el-link>
|
|
<el-link
|
|
v-if="
|
|
hasPermission('vehicle_dispatch_delete') &&
|
|
['draft', 'rejected'].includes(row.approvalStatus)
|
|
"
|
|
type="danger"
|
|
@click="handleDelete(row.id)"
|
|
>
|
|
删除
|
|
</el-link>
|
|
</template>
|
|
</avue-crud>
|
|
<empty-pagination
|
|
:page="page"
|
|
@size-change="sizeChange"
|
|
@current-change="currentChange"
|
|
@load="onLoad(page, query)"
|
|
/>
|
|
</basic-container>
|
|
</template>
|
|
|
|
<script>
|
|
import { mapGetters } from 'vuex';
|
|
import {
|
|
approve,
|
|
exportVehicleDispatch,
|
|
getDetail,
|
|
getList,
|
|
remove,
|
|
submit,
|
|
submitApproval,
|
|
} from '@/api/transportCapacity/vehicle-dispatch';
|
|
import { getList as getVehicleList } from '@/api/transportCapacity/transport-vehicle';
|
|
import { getDeptTree } from '@/api/system/dept';
|
|
import VehicleAttachmentTable from '@/components/vehicle-attachment-table/main.vue';
|
|
import { option, statusName } from '@/option/transportCapacity/vehicle-dispatch';
|
|
|
|
export default {
|
|
components: {
|
|
VehicleAttachmentTable,
|
|
},
|
|
data() {
|
|
return {
|
|
option,
|
|
form: {},
|
|
query: {},
|
|
dialogType: '',
|
|
deptOptions: [],
|
|
deptCascaderValue: [],
|
|
selectedVehicleValue: '',
|
|
data: [],
|
|
loading: false,
|
|
selectionList: [],
|
|
page: { pageSize: 10, pageSizes: [10, 20, 50, 100], currentPage: 1, total: 0 },
|
|
};
|
|
},
|
|
created() {
|
|
this.initDepartmentTree();
|
|
},
|
|
computed: {
|
|
...mapGetters(['permission', 'userInfo']),
|
|
permissionList() {
|
|
return { addBtn: this.hasPermission('vehicle_dispatch_add') };
|
|
},
|
|
deptCascaderProps() {
|
|
return { label: 'title', value: 'id', children: 'children', checkStrictly: true };
|
|
},
|
|
},
|
|
methods: {
|
|
statusName,
|
|
hasPermission(code) {
|
|
return (
|
|
String(this.userInfo?.authority || '').includes('admin') || this.permission?.[code] === true
|
|
);
|
|
},
|
|
statusTagType(status) {
|
|
return { approved: 'success', reviewing: 'warning', rejected: 'danger' }[status] || 'info';
|
|
},
|
|
formatAttachments(value) {
|
|
if (!value) return '';
|
|
if (Array.isArray(value)) return `${value.length} 个`;
|
|
if (typeof value !== 'string') return '1 个';
|
|
try {
|
|
const attachments = JSON.parse(value);
|
|
return Array.isArray(attachments) ? `${attachments.length} 个` : '1 个';
|
|
} catch (error) {
|
|
return `${value.split(',').filter(item => item.trim()).length} 个`;
|
|
}
|
|
},
|
|
parseAttachments(value) {
|
|
if (!value || Array.isArray(value)) return value || [];
|
|
if (typeof value !== 'string') return [];
|
|
try {
|
|
const attachments = JSON.parse(value);
|
|
return Array.isArray(attachments) ? attachments : [];
|
|
} catch (error) {
|
|
return value
|
|
.split(',')
|
|
.map(item => ({ name: item.trim(), url: item.trim() }))
|
|
.filter(item => item.url);
|
|
}
|
|
},
|
|
stringifyAttachments(value) {
|
|
if (!value || typeof value === 'string') return value;
|
|
return JSON.stringify(value);
|
|
},
|
|
normalizeRow(row) {
|
|
const values = { ...row };
|
|
values.attachments = this.stringifyAttachments(values.attachments);
|
|
return values;
|
|
},
|
|
rowSave(row, done, loading) {
|
|
if (!this.selectedVehicleValue || row.plateNo !== this.selectedVehicleValue) {
|
|
this.$message.warning('请选择车牌号');
|
|
loading();
|
|
return;
|
|
}
|
|
submit(this.normalizeRow(row))
|
|
.then(() => {
|
|
this.onLoad();
|
|
this.$message.success('操作成功');
|
|
done();
|
|
})
|
|
.catch(() => loading());
|
|
},
|
|
rowUpdate(row, index, done, loading) {
|
|
this.rowSave(row, done, loading);
|
|
},
|
|
beforeOpen(done, type) {
|
|
if (['edit', 'view'].includes(type)) {
|
|
this.dialogType = type;
|
|
getDetail(this.form.id)
|
|
.then(res => {
|
|
this.form = res.data.data || {};
|
|
this.form.attachments = this.parseAttachments(this.form.attachments);
|
|
this.form.applicantName = this.form.createUserName || '';
|
|
this.form.applyTime = this.form.createTime || '';
|
|
this.selectedVehicleValue = this.form.plateNo || '';
|
|
this.deptCascaderValue = this.findDepartmentPath(this.form.useDepartment);
|
|
done();
|
|
})
|
|
.catch(() => done());
|
|
} else {
|
|
this.dialogType = 'add';
|
|
this.deptCascaderValue = [];
|
|
this.selectedVehicleValue = '';
|
|
this.form.attachments = [];
|
|
this.form.approvalStatus = 'draft';
|
|
this.form.vehicleType = '';
|
|
this.form.applicantName =
|
|
this.userInfo?.realName || this.userInfo?.userName || this.userInfo?.account || '';
|
|
this.form.applyTime = this.$dayjs().format('YYYY-MM-DD HH:mm:ss');
|
|
done();
|
|
}
|
|
},
|
|
initDepartmentTree() {
|
|
getDeptTree(this.userInfo?.tenantId)
|
|
.then(res => {
|
|
this.deptOptions = this.filterExternalDepartments(res.data.data || []);
|
|
})
|
|
.catch(() => {
|
|
this.deptOptions = [];
|
|
});
|
|
},
|
|
filterExternalDepartments(tree) {
|
|
return (tree || [])
|
|
.filter(item => (item.title || item.deptName || item.name) !== '外部组织')
|
|
.map(item => ({
|
|
...item,
|
|
children: this.filterExternalDepartments(item.children),
|
|
}));
|
|
},
|
|
findDepartmentPath(departmentName, tree = this.deptOptions, parents = []) {
|
|
if (!departmentName) return [];
|
|
for (const item of tree || []) {
|
|
const path = [...parents, item.id];
|
|
const itemName = item.title || item.deptName || item.name;
|
|
if (itemName === departmentName) return path;
|
|
const matched = this.findDepartmentPath(departmentName, item.children, path);
|
|
if (matched.length) return matched;
|
|
}
|
|
return [];
|
|
},
|
|
findDepartmentNode(id, tree = this.deptOptions) {
|
|
for (const item of tree || []) {
|
|
if (String(item.id) === String(id)) return item;
|
|
const matched = this.findDepartmentNode(id, item.children);
|
|
if (matched) return matched;
|
|
}
|
|
return null;
|
|
},
|
|
handleDepartmentChange(value) {
|
|
const node = this.findDepartmentNode(value?.[value.length - 1]);
|
|
this.form.useDepartment = node ? node.title || node.deptName || node.name || '' : '';
|
|
},
|
|
fetchVehicleSuggestions(queryString, callback) {
|
|
getVehicleList(1, 9999, {
|
|
plateNo: queryString || '',
|
|
status: 1,
|
|
})
|
|
.then(res => {
|
|
const records = res.data.data?.records || [];
|
|
callback(
|
|
records.map(item => ({
|
|
value: item.plateNo,
|
|
organizationName: item.organizationName,
|
|
vehicleType: item.vehicleType,
|
|
}))
|
|
);
|
|
})
|
|
.catch(() => callback([]));
|
|
},
|
|
handleVehicleSelect(vehicle) {
|
|
this.form.plateNo = vehicle.value;
|
|
this.form.organizationName = vehicle.organizationName || '';
|
|
this.form.vehicleType = vehicle.vehicleType || '';
|
|
this.selectedVehicleValue = vehicle.value;
|
|
},
|
|
handleVehicleInput(value) {
|
|
if (value !== this.selectedVehicleValue) {
|
|
this.selectedVehicleValue = '';
|
|
this.form.organizationName = '';
|
|
this.form.vehicleType = '';
|
|
}
|
|
},
|
|
handleVehicleBlur() {
|
|
if (this.form.plateNo && this.form.plateNo !== this.selectedVehicleValue) {
|
|
this.form.plateNo = '';
|
|
this.form.organizationName = '';
|
|
this.form.vehicleType = '';
|
|
this.$message.warning('请从下拉列表中选择车牌号');
|
|
}
|
|
},
|
|
handleSubmitApproval(row) {
|
|
this.$confirm('确定提交该车辆调度申请吗?', '提示', { type: 'warning' })
|
|
.then(() => submitApproval(row.id))
|
|
.then(() => {
|
|
this.$message.success('提交成功');
|
|
this.onLoad();
|
|
});
|
|
},
|
|
handleApprove(row) {
|
|
this.$confirm('审核通过后将同步更新车辆使用部门,确认继续吗?', '提示', { type: 'warning' })
|
|
.then(() => approve(row.id))
|
|
.then(() => {
|
|
this.$message.success('审核通过');
|
|
this.onLoad();
|
|
});
|
|
},
|
|
handleDelete(ids) {
|
|
const targetIds = ids || this.selectionList.map(item => item.id).join(',');
|
|
if (!targetIds) return this.$message.warning('请选择至少一条数据');
|
|
this.$confirm('确定删除所选数据,删除后不可恢复?', '提示', { type: 'warning' })
|
|
.then(() => remove(targetIds))
|
|
.then(() => {
|
|
this.$message.success('操作成功');
|
|
this.onLoad();
|
|
});
|
|
},
|
|
handleExport() {
|
|
exportVehicleDispatch(this.query).then(res => {
|
|
const blob = new Blob([res.data]);
|
|
const link = document.createElement('a');
|
|
link.href = URL.createObjectURL(blob);
|
|
link.download = `车辆调度${this.$dayjs().format('YYYYMMDDHHmmss')}.xlsx`;
|
|
link.click();
|
|
URL.revokeObjectURL(link.href);
|
|
});
|
|
},
|
|
searchChange(params, done) {
|
|
this.query = { ...params };
|
|
this.page.currentPage = 1;
|
|
this.onLoad();
|
|
done();
|
|
},
|
|
searchReset() {
|
|
this.query = {};
|
|
this.page.currentPage = 1;
|
|
this.onLoad();
|
|
},
|
|
selectionChange(list) {
|
|
this.selectionList = list;
|
|
},
|
|
currentChange(currentPage) {
|
|
this.page.currentPage = currentPage;
|
|
this.onLoad();
|
|
},
|
|
sizeChange(pageSize) {
|
|
this.page.pageSize = pageSize;
|
|
this.page.currentPage = 1;
|
|
this.onLoad();
|
|
},
|
|
refreshChange() {
|
|
this.onLoad();
|
|
},
|
|
onLoad() {
|
|
this.loading = true;
|
|
return getList(this.page.currentPage, this.page.pageSize, this.query)
|
|
.then(res => {
|
|
const result = res.data.data || {};
|
|
this.data = result.records || [];
|
|
this.page.total = result.total || 0;
|
|
})
|
|
.finally(() => {
|
|
this.loading = false;
|
|
});
|
|
},
|
|
},
|
|
};
|
|
</script>
|
|
|
|
<style lang="scss" scoped>
|
|
.vehicle-dispatch-page :deep(.avue-crud__header) {
|
|
margin-top: 12px;
|
|
}
|
|
.vehicle-dispatch-page :deep(.el-link + .el-link) {
|
|
margin-left: 8px;
|
|
}
|
|
.vehicle-dispatch-page :deep(.vehicle-dispatch-form-control) {
|
|
width: 100%;
|
|
}
|
|
</style>
|