159 lines
7.1 KiB
Vue
159 lines
7.1 KiB
Vue
<script setup lang="ts">
|
|
import { computed, onMounted, reactive, ref, watch } from 'vue'
|
|
import { useRouter } from 'vue-router'
|
|
import { Plus } from '@lucide/vue'
|
|
import dayjs from 'dayjs'
|
|
import { useAuthStore } from '@/modules/auth/public'
|
|
import { listDeliveryOrders, type DeliveryQuery, type DeliveryRow } from '../api/deliveryOrders'
|
|
import QueryToolbar, { type QueryField, type QueryModel } from '@/components/common/QueryToolbar.vue'
|
|
import DataTable, { type DataTableColumn } from '@/components/common/DataTable.vue'
|
|
import type { TableAction } from '@/components/common/tableActions'
|
|
|
|
const router = useRouter()
|
|
const auth = useAuthStore()
|
|
const loading = ref(false)
|
|
const errorMessage = ref('')
|
|
const records = ref<DeliveryRow[]>([])
|
|
const total = ref(0)
|
|
const page = ref(1)
|
|
const pageSize = ref(20)
|
|
const filters = reactive({ documentNo: '', dispatchNo: '', waybillNo: '', status: '', deliveryMethod: '', plannedRange: [] as string[] })
|
|
const canCreate = computed(() => auth.hasPermission('merchant:warehouse:delivery:create'))
|
|
|
|
const statusOptions = [
|
|
{ value: 'PENDING', label: '待派送' },
|
|
{ value: 'IN_TRANSIT', label: '派送中' },
|
|
{ value: 'DELIVERED', label: '已送达' },
|
|
{ value: 'SIGNED', label: '已签收' },
|
|
{ value: 'CANCELLED', label: '已取消' },
|
|
]
|
|
|
|
const statusLabels: Record<string, string> = Object.fromEntries(statusOptions.map((item) => [item.value, item.label]))
|
|
const queryModel = computed<QueryModel>({ get: () => ({ ...filters }), set: (value) => Object.assign(filters, value) })
|
|
const queryFields: QueryField[] = [
|
|
{ key: 'documentNo', label: '派送单 / 出库单', type: 'input', placeholder: '请输入派送单号或出库单号' },
|
|
{ key: 'dispatchNo', label: '排车单号', type: 'input', placeholder: '请输入排车单号' },
|
|
{ key: 'waybillNo', label: '运单号', type: 'input', placeholder: '请输入运单号' },
|
|
{ key: 'status', label: '派送状态', type: 'select', options: statusOptions },
|
|
{ key: 'deliveryMethod', label: '派送方式', type: 'select', options: [{ label: '卡车派送', value: 'TRUCK' }, { label: '快递派送', value: 'COURIER' }, { label: '客户自提', value: 'SELF_PICKUP' }] },
|
|
{ key: 'plannedRange', label: '计划时间', type: 'daterange' },
|
|
]
|
|
const tableColumns: DataTableColumn[] = [
|
|
{ key: 'actions', label: '操作', slotName: 'actions', width: 90, fixed: 'left' }, { prop: 'deliveryNo', label: '派送单号', minWidth: 180 },
|
|
{ prop: 'dispatchNo', label: '排车单号', minWidth: 170 }, { prop: 'outboundNo', label: '出库单号', minWidth: 170 },
|
|
{ key: 'status', label: '状态', slotName: 'status', width: 110 }, { prop: 'overseasWarehouseName', label: '海外仓', minWidth: 160 },
|
|
{ prop: 'deliveryMethod', label: '派送方式', width: 120 }, { prop: 'waybillNo', label: '运单号', minWidth: 150 },
|
|
{ prop: 'carrierName', label: '承运商', minWidth: 140 }, { key: 'planned', label: '计划派送', slotName: 'planned', width: 160 },
|
|
{ key: 'arrival', label: '预计到达', slotName: 'arrival', width: 160 }, { key: 'createdAt', label: '创建时间', slotName: 'createdAt', width: 160 },
|
|
]
|
|
|
|
function display(value: string | number | null | undefined) {
|
|
return value === null || value === undefined || value === '' ? '—' : String(value)
|
|
}
|
|
|
|
function formatDateTime(value: string | null | undefined) {
|
|
return value ? dayjs(value).format('YYYY-MM-DD HH:mm') : '—'
|
|
}
|
|
|
|
function statusLabel(status: string) {
|
|
return statusLabels[status] ?? status
|
|
}
|
|
|
|
function statusType(status: string) {
|
|
if (status === 'DELIVERED' || status === 'SIGNED') return 'success'
|
|
if (status === 'CANCELLED') return 'info'
|
|
if (status === 'IN_TRANSIT') return 'warning'
|
|
return 'primary'
|
|
}
|
|
|
|
function buildQuery(): DeliveryQuery {
|
|
return {
|
|
page: page.value,
|
|
size: pageSize.value,
|
|
documentNo: filters.documentNo.trim() || undefined,
|
|
dispatchNo: filters.dispatchNo.trim() || undefined,
|
|
waybillNo: filters.waybillNo.trim() || undefined,
|
|
status: filters.status || undefined,
|
|
deliveryMethod: filters.deliveryMethod || undefined,
|
|
plannedFrom: filters.plannedRange[0] || undefined,
|
|
plannedTo: filters.plannedRange[1] || undefined,
|
|
}
|
|
}
|
|
|
|
async function loadOrders() {
|
|
loading.value = true
|
|
errorMessage.value = ''
|
|
try {
|
|
const result = await listDeliveryOrders(buildQuery())
|
|
records.value = result.records
|
|
total.value = result.total
|
|
} catch (error) {
|
|
records.value = []
|
|
total.value = 0
|
|
errorMessage.value = error instanceof Error ? error.message : '派送单加载失败,请重试'
|
|
} finally {
|
|
loading.value = false
|
|
}
|
|
}
|
|
|
|
function search() {
|
|
if (page.value === 1) void loadOrders()
|
|
else page.value = 1
|
|
}
|
|
|
|
function reset() {
|
|
Object.assign(filters, { documentNo: '', dispatchNo: '', waybillNo: '', status: '', deliveryMethod: '', plannedRange: [] })
|
|
search()
|
|
}
|
|
|
|
function changePage(nextPage: number) {
|
|
page.value = nextPage
|
|
void loadOrders()
|
|
}
|
|
|
|
function changePageSize(nextSize: number) {
|
|
pageSize.value = nextSize
|
|
page.value = 1
|
|
void loadOrders()
|
|
}
|
|
|
|
function openDetail(row: DeliveryRow) {
|
|
if (!row.deliveryNo) return
|
|
void router.push({ name: 'orders-delivery-detail', params: { deliveryNo: row.deliveryNo } })
|
|
}
|
|
|
|
function openCreate() {
|
|
void router.push({ name: 'orders-delivery-create' })
|
|
}
|
|
function rowActions(candidate: object): TableAction[] {
|
|
const row = candidate as DeliveryRow
|
|
return [{ key: 'detail', label: '详情', disabled: !row.deliveryNo, run: () => openDetail(row) }]
|
|
}
|
|
|
|
onMounted(loadOrders)
|
|
watch([page, pageSize], ([nextPage, nextSize], [previousPage, previousSize]) => {
|
|
if (nextSize !== previousSize && nextPage !== 1) { page.value = 1; return }
|
|
void loadOrders()
|
|
})
|
|
</script>
|
|
|
|
<template>
|
|
<section class="delivery-page" aria-labelledby="delivery-list-title">
|
|
<QueryToolbar v-model="queryModel" layout="grid" ariaLabel="派送订单筛选" :fields="queryFields" :search-on-reset="false" @search="search" @reset="reset" />
|
|
|
|
<div class="delivery-card delivery-table-card">
|
|
<DataTable v-model:page="page" v-model:page-size="pageSize" :data="records" :columns="tableColumns" :loading="loading" :total="total" :page-sizes="[10, 20, 50, 100]" :row-actions="rowActions" row-key="deliveryNo" empty-text="暂无派送单">
|
|
<template #toolbar><strong id="delivery-list-title">派送订单</strong><span>共 {{ total }} 条</span></template>
|
|
<template #toolbar-actions><el-button v-if="canCreate" type="primary" @click="openCreate"><Plus :size="16" />创建派送单</el-button></template>
|
|
<template v-if="errorMessage" #error><div class="delivery-state delivery-state--error" role="alert"><p>{{ errorMessage }}</p><el-button @click="loadOrders">重试</el-button></div></template>
|
|
<template #status="{ row }"><el-tag :type="statusType(row.status)" effect="light">{{ statusLabel(row.status) }}</el-tag></template>
|
|
<template #planned="{ row }">{{ formatDateTime(row.plannedDeliveryAt) }}</template>
|
|
<template #arrival="{ row }">{{ formatDateTime(row.expectedArrivalAt) }}</template>
|
|
<template #createdAt="{ row }">{{ formatDateTime(row.createdAt) }}</template>
|
|
</DataTable>
|
|
</div>
|
|
</section>
|
|
</template>
|
|
|
|
<style scoped src="./deliveryOrders.css"></style>
|