608 lines
19 KiB
Vue
608 lines
19 KiB
Vue
<!-- 司机管理 -->
|
|
<template>
|
|
<div class="page-container">
|
|
<section class="panel">
|
|
<div class="panel-top">
|
|
<h2 class="title-bar-heading">司机列表</h2>
|
|
</div>
|
|
|
|
<!-- 筛选区 -->
|
|
<div class="filter-block">
|
|
<el-form :model="searchForm" class="filter-form" @submit.prevent>
|
|
<div class="filter-grid">
|
|
<el-form-item label="司机姓名/手机">
|
|
<el-input
|
|
v-model="searchForm.q"
|
|
placeholder="搜索司机姓名或手机号"
|
|
clearable
|
|
@keyup.enter="handleSearch"
|
|
/>
|
|
</el-form-item>
|
|
</div>
|
|
<div class="filter-actions">
|
|
<div class="filter-actions-end">
|
|
<el-button class="btn-ghost" :loading="loading" @click="handleReset">
|
|
<el-icon><RefreshLeft /></el-icon>重置
|
|
</el-button>
|
|
<el-button class="btn-main" type="primary" :loading="loading" @click="handleSearch">
|
|
<el-icon><Search /></el-icon>搜索
|
|
</el-button>
|
|
</div>
|
|
</div>
|
|
</el-form>
|
|
</div>
|
|
|
|
<!-- 工具栏 -->
|
|
<div class="list-toolbar">
|
|
<div class="list-toolbar-row">
|
|
<ListQuickSearchInput
|
|
v-model="quickSearchKeyword"
|
|
placeholder="司机姓名/手机号"
|
|
@search="handleQuickSearch"
|
|
@clear="handleQuickSearchClear"
|
|
/>
|
|
<el-button class="btn-main" type="primary" @click="handleAdd">
|
|
<el-icon><Plus /></el-icon>新增司机
|
|
</el-button>
|
|
<el-button
|
|
class="btn-ghost"
|
|
:disabled="selectedRows.length !== 1"
|
|
@click="handleToolbarEdit"
|
|
>
|
|
<el-icon><Edit /></el-icon>编辑
|
|
</el-button>
|
|
<el-button
|
|
class="btn-ghost"
|
|
type="danger"
|
|
:disabled="selectedRows.length === 0 || !allRowsDeletableByCreator(selectedRows)"
|
|
:title="allRowsDeletableByCreator(selectedRows) ? '' : CREATOR_DELETE_TIP"
|
|
@click="handleToolbarDelete"
|
|
>
|
|
<el-icon><Delete /></el-icon>删除
|
|
</el-button>
|
|
|
|
<ListToolbarEndActions
|
|
:loading="loading"
|
|
:column-defs="listColumnDefs"
|
|
v-model:visible-columns="visibleColumns"
|
|
v-model:check-all="checkAll"
|
|
:is-indeterminate="isIndeterminate"
|
|
@refresh="fetchData"
|
|
@reset-columns="resetToDefault"
|
|
/>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 数据表格 -->
|
|
<div class="list-body list-wrap">
|
|
<ListTable table-key="pl-driver"
|
|
class="list-table"
|
|
:data="driverList"
|
|
v-loading="loading"
|
|
stripe
|
|
row-key="id"
|
|
@selection-change="handleSelectionChange"
|
|
@row-dblclick="handleView"
|
|
>
|
|
<el-table-column type="selection" min-width="55" align="center" header-align="center" />
|
|
<el-table-column
|
|
type="index"
|
|
label="序号"
|
|
min-width="68"
|
|
align="center"
|
|
header-align="center"
|
|
:index="(index) => (pagination.page - 1) * pagination.pageSize + index + 1"
|
|
/>
|
|
<el-table-column prop="driverName" label="姓名" min-width="100" align="center">
|
|
<template #default="{ row }">
|
|
<el-link type="primary" @click="handleView(row)">{{ row.driverName }}</el-link>
|
|
</template>
|
|
</el-table-column>
|
|
<el-table-column prop="phoneNo" label="手机号" min-width="130" align="center" />
|
|
<el-table-column
|
|
v-if="isColumnVisible('idCardNo')"
|
|
prop="idCardNo"
|
|
label="身份证号"
|
|
min-width="180"
|
|
align="center"
|
|
>
|
|
<template #default="{ row }">
|
|
{{ maskIdCard(row.idCardNo) }}
|
|
</template>
|
|
</el-table-column>
|
|
<el-table-column
|
|
v-if="isColumnVisible('drivingLicenseNo')"
|
|
prop="drivingLicenseNo"
|
|
label="驾驶证号"
|
|
min-width="160"
|
|
align="center"
|
|
/>
|
|
<el-table-column
|
|
v-if="isColumnVisible('drivingLicenseExpire')"
|
|
prop="drivingLicenseExpire"
|
|
label="驾驶证有效期"
|
|
min-width="120"
|
|
align="center"
|
|
>
|
|
<template #default="{ row }">
|
|
<el-tag :type="getExpireTagType(row.drivingLicenseExpire)" size="small">
|
|
{{ row.drivingLicenseExpire || '-' }}
|
|
</el-tag>
|
|
</template>
|
|
</el-table-column>
|
|
<el-table-column
|
|
v-if="isColumnVisible('vehicleLicenseNo')"
|
|
prop="vehicleLicenseNo"
|
|
label="行驶证号"
|
|
min-width="160"
|
|
align="center"
|
|
/>
|
|
<el-table-column
|
|
v-if="isColumnVisible('hazmatCertNo')"
|
|
prop="hazmatCertNo"
|
|
label="危化品证号"
|
|
min-width="160"
|
|
align="center"
|
|
>
|
|
<template #default="{ row }">
|
|
<el-tag v-if="row.hazmatCertNo" type="warning" size="small">有</el-tag>
|
|
<span v-else>-</span>
|
|
</template>
|
|
</el-table-column>
|
|
<el-table-column
|
|
v-if="isColumnVisible('remark')"
|
|
prop="remark"
|
|
label="备注"
|
|
min-width="160"
|
|
show-overflow-tooltip
|
|
/>
|
|
</ListTable>
|
|
|
|
<div class="pagination list-pager-bar">
|
|
<div class="list-pager-selected">
|
|
已选 <span class="sel-num">{{ selectedRows.length }}</span> 项
|
|
</div>
|
|
|
|
<el-pagination
|
|
v-model:current-page="pagination.page"
|
|
v-model:page-size="pagination.pageSize"
|
|
:total="pagination.total"
|
|
:page-sizes="[10, 20, 50, 100]"
|
|
layout="total, sizes, prev, pager, next"
|
|
@size-change="handleSizeChange"
|
|
@current-change="handlePageChange"
|
|
/>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
|
|
<!-- 新增/编辑弹窗 -->
|
|
<el-dialog
|
|
v-model="dialogVisible"
|
|
:title="dialogTitle"
|
|
width="640px"
|
|
align-center
|
|
class="dialog-form-layout"
|
|
@close="handleDialogClose"
|
|
>
|
|
<el-form ref="formRef" :model="formData" :rules="formRules" label-position="right" label-width="100px" class="pl-dialog-form">
|
|
<div class="form-grid-2">
|
|
<el-form-item label="姓名" prop="driverName">
|
|
<el-input v-model="formData.driverName" placeholder="请输入姓名" maxlength="100" />
|
|
</el-form-item>
|
|
<el-form-item label="手机号" prop="phoneNo">
|
|
<el-input v-model="formData.phoneNo" placeholder="请输入手机号" maxlength="32" />
|
|
</el-form-item>
|
|
<el-form-item label="身份证号" prop="idCardNo">
|
|
<el-input v-model="formData.idCardNo" placeholder="请输入身份证号" maxlength="32" />
|
|
</el-form-item>
|
|
<el-form-item label="驾驶证号" prop="drivingLicenseNo">
|
|
<el-input v-model="formData.drivingLicenseNo" placeholder="请输入驾驶证号" maxlength="32" />
|
|
</el-form-item>
|
|
<el-form-item label="驾驶证有效期" prop="drivingLicenseExpire">
|
|
<el-date-picker
|
|
v-model="formData.drivingLicenseExpire"
|
|
type="date"
|
|
placeholder="选择日期"
|
|
value-format="YYYY-MM-DD"
|
|
style="width: 100%"
|
|
/>
|
|
</el-form-item>
|
|
<el-form-item label="行驶证号" prop="vehicleLicenseNo">
|
|
<el-input v-model="formData.vehicleLicenseNo" placeholder="请输入行驶证号" maxlength="32" />
|
|
</el-form-item>
|
|
<el-form-item label="行驶证有效期" prop="vehicleLicenseExpire">
|
|
<el-date-picker
|
|
v-model="formData.vehicleLicenseExpire"
|
|
type="date"
|
|
placeholder="选择日期"
|
|
value-format="YYYY-MM-DD"
|
|
style="width: 100%"
|
|
/>
|
|
</el-form-item>
|
|
<el-form-item label="危化品证号" prop="hazmatCertNo">
|
|
<el-input v-model="formData.hazmatCertNo" placeholder="请输入危化品证号" maxlength="32" />
|
|
</el-form-item>
|
|
<el-form-item label="危化品证有效期" prop="hazmatCertExpire">
|
|
<el-date-picker
|
|
v-model="formData.hazmatCertExpire"
|
|
type="date"
|
|
placeholder="选择日期"
|
|
value-format="YYYY-MM-DD"
|
|
style="width: 100%"
|
|
/>
|
|
</el-form-item>
|
|
<el-form-item label="备注" class="form-col-span-2" prop="remark">
|
|
<el-input
|
|
v-model="formData.remark"
|
|
type="textarea"
|
|
:rows="3"
|
|
placeholder="请输入备注"
|
|
maxlength="512"
|
|
/>
|
|
</el-form-item>
|
|
</div>
|
|
</el-form>
|
|
<template #footer>
|
|
<div class="dialog-footer">
|
|
<el-button @click="dialogVisible = false">
|
|
<el-icon><Close /></el-icon>取消
|
|
</el-button>
|
|
<el-button type="primary" :loading="submitLoading" @click="handleSubmit">
|
|
<el-icon><Check /></el-icon>确定
|
|
</el-button>
|
|
</div>
|
|
</template>
|
|
</el-dialog>
|
|
|
|
<SystemViewDialog
|
|
v-model:visible="viewVisible"
|
|
:title="viewRow?.driverName || '司机详情'"
|
|
:sections="viewSections"
|
|
width="720px"
|
|
modal-class="order-module-dialog-mask"
|
|
append-to-body
|
|
>
|
|
<template v-if="viewRow" #hero-actions>
|
|
<div class="driver-view-hero-actions">
|
|
<el-button class="btn-main" type="primary" @click="handleViewEdit">
|
|
<el-icon><Edit /></el-icon>编辑
|
|
</el-button>
|
|
<el-button
|
|
class="btn-ghost"
|
|
type="danger"
|
|
:disabled="!canDeleteByCreator(viewRow)"
|
|
:title="canDeleteByCreator(viewRow) ? '' : CREATOR_DELETE_TIP"
|
|
@click="handleViewDelete"
|
|
>
|
|
<el-icon><Delete /></el-icon>删除
|
|
</el-button>
|
|
</div>
|
|
</template>
|
|
</SystemViewDialog>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import { Check, Close, Delete, Edit, Plus, RefreshLeft, Search } from '@element-plus/icons-vue'
|
|
import { driverApi, type Driver } from '@/api/pl'
|
|
import SystemViewDialog, { type ViewSection } from '@/components/business/system-view-dialog/index.vue'
|
|
import ListQuickSearchInput from '@/components/business/list-quick-search-input/index.vue'
|
|
import ListToolbarEndActions from '@/components/business/list-toolbar-end-actions/index.vue'
|
|
import { usePersistedListColumns } from '@/composables/usePersistedListColumns'
|
|
import { useDbInstantSearch } from '@/composables/useDbInstantSearch'
|
|
import { pickBxPageResult } from '@/utils/http/bx'
|
|
import { DEFAULT_LIST_PAGE_SIZE } from '@/utils/table/tableConfig'
|
|
import { canDeleteByCreator, filterDeletableByCreator, allRowsDeletableByCreator, CREATOR_DELETE_TIP } from '@/utils/creator-delete'
|
|
|
|
const loading = ref(false)
|
|
const submitLoading = ref(false)
|
|
const driverList = ref<Driver[]>([])
|
|
|
|
const listColumnDefs = [
|
|
{ prop: 'idCardNo', label: '身份证号' },
|
|
{ prop: 'drivingLicenseNo', label: '驾驶证号' },
|
|
{ prop: 'drivingLicenseExpire', label: '驾驶证有效期' },
|
|
{ prop: 'vehicleLicenseNo', label: '行驶证号' },
|
|
{ prop: 'hazmatCertNo', label: '危化品证号' },
|
|
{ prop: 'remark', label: '备注', defaultVisible: false }
|
|
]
|
|
|
|
const {
|
|
visibleColumns,
|
|
checkAll,
|
|
isIndeterminate,
|
|
isColumnVisible,
|
|
resetToDefault
|
|
} = usePersistedListColumns('pl-driver-list-columns', listColumnDefs, {
|
|
defaultVisibleProps: [
|
|
'idCardNo',
|
|
'drivingLicenseNo',
|
|
'drivingLicenseExpire',
|
|
'vehicleLicenseNo',
|
|
'hazmatCertNo'
|
|
]
|
|
})
|
|
|
|
const selectedRows = ref<Driver[]>([])
|
|
const dialogVisible = ref(false)
|
|
const dialogTitle = ref('')
|
|
const formRef = ref()
|
|
const isEdit = ref(false)
|
|
const viewVisible = ref(false)
|
|
const viewRow = ref<Driver | null>(null)
|
|
|
|
const quickSearchKeyword = ref('')
|
|
|
|
const searchForm = reactive({
|
|
q: ''
|
|
})
|
|
|
|
const pagination = reactive({
|
|
page: 1,
|
|
pageSize: DEFAULT_LIST_PAGE_SIZE,
|
|
total: 0
|
|
})
|
|
|
|
const formData = reactive({
|
|
id: '',
|
|
driverName: '',
|
|
phoneNo: '',
|
|
idCardNo: '',
|
|
drivingLicenseNo: '',
|
|
drivingLicenseExpire: '',
|
|
vehicleLicenseNo: '',
|
|
vehicleLicenseExpire: '',
|
|
hazmatCertNo: '',
|
|
hazmatCertExpire: '',
|
|
remark: ''
|
|
})
|
|
|
|
const formRules = {
|
|
driverName: [{ required: true, message: '请输入姓名', trigger: 'blur' }],
|
|
phoneNo: [{ required: true, message: '请输入手机号', trigger: 'blur' }]
|
|
}
|
|
|
|
const viewSections = computed<ViewSection[]>(() => {
|
|
const row = viewRow.value
|
|
if (!row) return []
|
|
return [
|
|
{
|
|
title: '基本信息',
|
|
fields: [
|
|
{ label: '姓名', value: row.driverName },
|
|
{ label: '手机号', value: row.phoneNo || '—' },
|
|
{ label: '身份证号', value: maskIdCard(row.idCardNo) },
|
|
{ label: '备注', value: row.remark || '—', span: 2 }
|
|
]
|
|
},
|
|
{
|
|
title: '证件信息',
|
|
fields: [
|
|
{ label: '驾驶证号', value: row.drivingLicenseNo || '—' },
|
|
{
|
|
label: '驾驶证有效期',
|
|
value: row.drivingLicenseExpire || '—',
|
|
tagType: getExpireTagType(row.drivingLicenseExpire)
|
|
},
|
|
{ label: '行驶证号', value: row.vehicleLicenseNo || '—' },
|
|
{
|
|
label: '行驶证有效期',
|
|
value: row.vehicleLicenseExpire || '—',
|
|
tagType: getExpireTagType(row.vehicleLicenseExpire)
|
|
},
|
|
{ label: '危化品证号', value: row.hazmatCertNo || '—' },
|
|
{
|
|
label: '危化品证有效期',
|
|
value: row.hazmatCertExpire || '—',
|
|
tagType: getExpireTagType(row.hazmatCertExpire)
|
|
}
|
|
]
|
|
}
|
|
]
|
|
})
|
|
|
|
function maskIdCard(idCard: string | undefined) {
|
|
if (!idCard || idCard.length < 8) return idCard || '-'
|
|
return idCard.slice(0, 4) + '**********' + idCard.slice(-4)
|
|
}
|
|
|
|
function getExpireTagType(dateStr: string | undefined) {
|
|
if (!dateStr) return 'info'
|
|
const expDate = new Date(dateStr)
|
|
const today = new Date()
|
|
const diffDays = Math.ceil((expDate.getTime() - today.getTime()) / (1000 * 60 * 60 * 24))
|
|
if (diffDays <= 0) return 'danger'
|
|
if (diffDays <= 30) return 'warning'
|
|
return 'success'
|
|
}
|
|
|
|
async function fetchData() {
|
|
loading.value = true
|
|
try {
|
|
const res = await driverApi.list({
|
|
q: quickSearchKeyword.value.trim() || searchForm.q || undefined,
|
|
page: pagination.page,
|
|
pageSize: pagination.pageSize
|
|
})
|
|
const { list, total } = pickBxPageResult<Driver>(res)
|
|
driverList.value = list
|
|
pagination.total = total
|
|
const idSet = new Set(driverList.value.map(item => item.id))
|
|
selectedRows.value = selectedRows.value.filter(item => idSet.has(item.id))
|
|
} finally {
|
|
loading.value = false
|
|
}
|
|
}
|
|
|
|
function handleSearch() {
|
|
quickSearchKeyword.value = ''
|
|
pagination.page = 1
|
|
fetchData()
|
|
}
|
|
|
|
function handleReset() {
|
|
searchForm.q = ''
|
|
quickSearchKeyword.value = ''
|
|
selectedRows.value = []
|
|
pagination.page = 1
|
|
fetchData()
|
|
}
|
|
|
|
function handleQuickSearch() {
|
|
pagination.page = 1
|
|
fetchData()
|
|
}
|
|
|
|
function handleQuickSearchClear() {
|
|
quickSearchKeyword.value = ''
|
|
pagination.page = 1
|
|
fetchData()
|
|
}
|
|
|
|
function handlePageChange() {
|
|
fetchData()
|
|
}
|
|
|
|
function handleSizeChange() {
|
|
pagination.page = 1
|
|
fetchData()
|
|
}
|
|
|
|
function handleSelectionChange(selection: Driver[]) {
|
|
selectedRows.value = selection
|
|
}
|
|
|
|
function handleAdd() {
|
|
dialogTitle.value = '新增司机'
|
|
isEdit.value = false
|
|
Object.assign(formData, {
|
|
id: '',
|
|
driverName: '',
|
|
phoneNo: '',
|
|
idCardNo: '',
|
|
drivingLicenseNo: '',
|
|
drivingLicenseExpire: '',
|
|
vehicleLicenseNo: '',
|
|
vehicleLicenseExpire: '',
|
|
hazmatCertNo: '',
|
|
hazmatCertExpire: '',
|
|
remark: ''
|
|
})
|
|
dialogVisible.value = true
|
|
}
|
|
|
|
function handleEdit(row: Driver) {
|
|
dialogTitle.value = '编辑司机'
|
|
isEdit.value = true
|
|
Object.assign(formData, {
|
|
id: row.id,
|
|
driverName: row.driverName,
|
|
phoneNo: row.phoneNo,
|
|
idCardNo: row.idCardNo,
|
|
drivingLicenseNo: row.drivingLicenseNo,
|
|
drivingLicenseExpire: row.drivingLicenseExpire,
|
|
vehicleLicenseNo: row.vehicleLicenseNo,
|
|
vehicleLicenseExpire: row.vehicleLicenseExpire,
|
|
hazmatCertNo: row.hazmatCertNo,
|
|
hazmatCertExpire: row.hazmatCertExpire,
|
|
remark: row.remark
|
|
})
|
|
dialogVisible.value = true
|
|
}
|
|
|
|
function handleView(row: Driver) {
|
|
viewRow.value = row
|
|
viewVisible.value = true
|
|
}
|
|
|
|
function handleToolbarEdit() {
|
|
if (selectedRows.value.length !== 1) return
|
|
handleEdit(selectedRows.value[0])
|
|
}
|
|
|
|
function handleViewEdit() {
|
|
if (!viewRow.value) return
|
|
viewVisible.value = false
|
|
handleEdit(viewRow.value)
|
|
}
|
|
|
|
function handleToolbarDelete() {
|
|
if (selectedRows.value.length === 0) return
|
|
if (selectedRows.value.length === 1) {
|
|
handleDelete(selectedRows.value[0])
|
|
return
|
|
}
|
|
const deletable = filterDeletableByCreator(selectedRows.value)
|
|
if (deletable.length !== selectedRows.value.length) {
|
|
ElMessage.warning(CREATOR_DELETE_TIP)
|
|
return
|
|
}
|
|
ElMessageBox.confirm(`确定删除选中的 ${selectedRows.value.length} 条司机吗?`, '提示', {
|
|
type: 'warning'
|
|
}).then(async () => {
|
|
await Promise.all(deletable.map((row) => driverApi.delete(row.id)))
|
|
ElMessage.success('删除成功')
|
|
fetchData()
|
|
})
|
|
}
|
|
|
|
function handleViewDelete() {
|
|
if (!viewRow.value) return
|
|
handleDelete(viewRow.value).then(() => {
|
|
viewVisible.value = false
|
|
})
|
|
}
|
|
|
|
async function handleSubmit() {
|
|
const valid = await formRef.value.validate().catch(() => false)
|
|
if (!valid) return
|
|
|
|
submitLoading.value = true
|
|
try {
|
|
const payload = { ...formData }
|
|
delete (payload as any).id
|
|
|
|
if (isEdit.value) {
|
|
await driverApi.update(formData.id, payload)
|
|
} else {
|
|
await driverApi.create(payload)
|
|
}
|
|
ElMessage.success(isEdit.value ? '编辑成功' : '新增成功')
|
|
dialogVisible.value = false
|
|
fetchData()
|
|
} finally {
|
|
submitLoading.value = false
|
|
}
|
|
}
|
|
|
|
function handleDialogClose() {
|
|
formRef.value?.resetFields()
|
|
}
|
|
|
|
async function handleDelete(row: Driver) {
|
|
if (!canDeleteByCreator(row)) {
|
|
ElMessage.warning(CREATOR_DELETE_TIP)
|
|
return
|
|
}
|
|
await ElMessageBox.confirm('确定删除该司机吗?', '提示', { type: 'warning' })
|
|
await driverApi.delete(row.id)
|
|
ElMessage.success('删除成功')
|
|
fetchData()
|
|
}
|
|
|
|
useDbInstantSearch(() => ({ q: searchForm.q }), handleSearch)
|
|
|
|
onMounted(() => {
|
|
fetchData()
|
|
})
|
|
</script>
|
|
|
|
<style scoped lang="scss">
|
|
.driver-view-hero-actions {
|
|
display: flex;
|
|
flex-wrap: wrap;
|
|
gap: 8px;
|
|
}
|
|
</style>
|