<template>
|
<div class="bas-station-page art-full-height">
|
<ArtSearchBar
|
v-model="searchForm"
|
:items="searchItems"
|
:showExpand="true"
|
@search="handleSearch"
|
@reset="handleReset"
|
/>
|
|
<ElCard class="art-table-card">
|
<ArtTableHeader v-model:columns="columnChecks" :loading="loading" @refresh="refreshData">
|
<template #left>
|
<ElSpace wrap>
|
<ElButton v-auth="'add'" @click="showDialog('add')" v-ripple>新增站点</ElButton>
|
<ElButton
|
v-auth="'delete'"
|
type="danger"
|
:disabled="selectedRows.length === 0"
|
@click="handleBatchDelete"
|
v-ripple
|
>
|
批量删除
|
</ElButton>
|
<ListExportPrint
|
class="inline-flex"
|
:preview-visible="previewVisible"
|
@update:previewVisible="handlePreviewVisibleChange"
|
:report-title="reportTitle"
|
:selected-rows="selectedRows"
|
:query-params="reportQueryParams"
|
:columns="columns"
|
:preview-rows="previewRows"
|
:preview-meta="resolvedPreviewMeta"
|
:total="pagination.total"
|
:disabled="loading"
|
@export="handleExport"
|
@print="handlePrint"
|
/>
|
</ElSpace>
|
</template>
|
</ArtTableHeader>
|
|
<ArtTable
|
:loading="loading"
|
:data="data"
|
:columns="columns"
|
:pagination="pagination"
|
@selection-change="handleSelectionChange"
|
@pagination:size-change="handleSizeChange"
|
@pagination:current-change="handleCurrentChange"
|
/>
|
|
<BasStationDialog
|
v-model:visible="dialogVisible"
|
:dialog-type="dialogType"
|
:station-data="currentStationData"
|
:area-options="areaOptions"
|
:container-type-options="containerTypeOptions"
|
:use-status-options="useStatusOptions"
|
@submit="handleDialogSubmit"
|
/>
|
|
<BasStationDetailDrawer
|
v-model:visible="detailDrawerVisible"
|
:loading="detailLoading"
|
:detail="detailData"
|
:resolve-area-label="resolveAreaLabel"
|
:resolve-container-type-label="resolveContainerTypeLabel"
|
/>
|
</ElCard>
|
</div>
|
</template>
|
|
<script setup>
|
import { computed, onMounted, ref } from 'vue'
|
import { ElMessage } from 'element-plus'
|
import { useUserStore } from '@/store/modules/user'
|
import { useAuth } from '@/hooks/core/useAuth'
|
import { useTable } from '@/hooks/core/useTable'
|
import { useCrudPage } from '@/views/system/common/useCrudPage'
|
import { usePrintExportPage } from '@/views/system/common/usePrintExportPage'
|
import ListExportPrint from '@/components/biz/list-export-print/index.vue'
|
import { defaultResponseAdapter } from '@/utils/table/tableUtils'
|
import { guardRequestWithMessage } from '@/utils/sys/requestGuard'
|
import { fetchDictDataPage } from '@/api/system-manage'
|
import { fetchWarehouseAreasList } from '@/api/warehouse-areas'
|
import {
|
fetchBasStationPage,
|
fetchDeleteBasStation,
|
fetchExportBasStationReport,
|
fetchGetBasStationDetail,
|
fetchGetBasStationMany,
|
fetchSaveBasStation,
|
fetchUpdateBasStation
|
} from '@/api/bas-station'
|
import BasStationDialog from './modules/bas-station-dialog.vue'
|
import BasStationDetailDrawer from './modules/bas-station-detail-drawer.vue'
|
import { createBasStationTableColumns } from './basStationTable.columns'
|
import {
|
BAS_STATION_REPORT_STYLE,
|
BAS_STATION_REPORT_TITLE,
|
buildBasStationDialogModel,
|
buildBasStationPageQueryParams,
|
buildBasStationPrintRows,
|
buildBasStationReportMeta,
|
buildBasStationSavePayload,
|
buildBasStationSearchParams,
|
buildBasStationContainerTypeOptions,
|
buildBasStationUseStatusOptions,
|
createBasStationSearchState,
|
getBasStationPaginationKey,
|
normalizeBasStationDetailRecord,
|
normalizeBasStationListRow,
|
getBasStationTypeOptions,
|
getBasStationBooleanOptions,
|
resolveBasStationAreaOptions
|
} from './basStationPage.helpers'
|
|
defineOptions({ name: 'BasStation' })
|
|
const { hasAuth } = useAuth()
|
const userStore = useUserStore()
|
|
const searchForm = ref(createBasStationSearchState())
|
const areaOptions = ref([])
|
const containerTypeOptions = ref([])
|
const useStatusOptions = ref([])
|
const detailDrawerVisible = ref(false)
|
const detailLoading = ref(false)
|
const detailData = ref({})
|
let handleDeleteAction = null
|
|
const reportTitle = BAS_STATION_REPORT_TITLE
|
const reportQueryParams = computed(() => buildBasStationSearchParams(searchForm.value))
|
|
const areaLabelMap = computed(
|
() =>
|
new Map(
|
areaOptions.value
|
.map((item) => [String(item.value), item.label])
|
.filter(([value, label]) => value && label)
|
)
|
)
|
|
const containerTypeLabelMap = computed(
|
() =>
|
new Map(
|
containerTypeOptions.value
|
.map((item) => [String(item.value), item.label])
|
.filter(([value, label]) => value && label)
|
)
|
)
|
|
function resolveAreaLabel(id) {
|
return areaLabelMap.value.get(String(id)) || ''
|
}
|
|
function resolveContainerTypeLabel(value) {
|
return containerTypeLabelMap.value.get(String(value)) || ''
|
}
|
|
const searchItems = computed(() => [
|
{
|
label: '关键字',
|
key: 'condition',
|
type: 'input',
|
props: {
|
clearable: true,
|
placeholder: '请输入站点编码/站点名称/备注'
|
}
|
},
|
{
|
label: '站点编码',
|
key: 'stationName',
|
type: 'input',
|
props: {
|
clearable: true,
|
placeholder: '请输入站点编码'
|
}
|
},
|
{
|
label: '站点名称',
|
key: 'stationId',
|
type: 'input',
|
props: {
|
clearable: true,
|
placeholder: '请输入站点名称'
|
}
|
},
|
{
|
label: '站点类型',
|
key: 'type',
|
type: 'select',
|
props: {
|
clearable: true,
|
options: getBasStationTypeOptions()
|
}
|
},
|
{
|
label: '使用状态',
|
key: 'useStatus',
|
type: 'select',
|
props: {
|
clearable: true,
|
options: useStatusOptions.value
|
}
|
},
|
{
|
label: '所属库区',
|
key: 'area',
|
type: 'select',
|
props: {
|
clearable: true,
|
filterable: true,
|
options: areaOptions.value
|
}
|
},
|
{
|
label: '是否跨区',
|
key: 'isCrossZone',
|
type: 'select',
|
props: {
|
clearable: true,
|
options: getBasStationBooleanOptions()
|
}
|
},
|
{
|
label: '是否WCS',
|
key: 'isWcs',
|
type: 'select',
|
props: {
|
clearable: true,
|
options: getBasStationBooleanOptions()
|
}
|
},
|
{
|
label: '条码',
|
key: 'barcode',
|
type: 'input',
|
props: {
|
clearable: true,
|
placeholder: '请输入条码'
|
}
|
},
|
{
|
label: '自动调拨',
|
key: 'autoTransfer',
|
type: 'select',
|
props: {
|
clearable: true,
|
options: getBasStationBooleanOptions()
|
}
|
},
|
{
|
label: '状态',
|
key: 'status',
|
type: 'select',
|
props: {
|
clearable: true,
|
options: [
|
{ label: '正常', value: 1 },
|
{ label: '冻结', value: 0 }
|
]
|
}
|
},
|
{
|
label: '备注',
|
key: 'memo',
|
type: 'input',
|
props: {
|
clearable: true,
|
placeholder: '请输入备注'
|
}
|
},
|
{
|
label: '开始时间',
|
key: 'timeStart',
|
type: 'date',
|
props: {
|
clearable: true,
|
type: 'date',
|
valueFormat: 'YYYY-MM-DD',
|
placeholder: '请选择开始时间'
|
}
|
},
|
{
|
label: '结束时间',
|
key: 'timeEnd',
|
type: 'date',
|
props: {
|
clearable: true,
|
type: 'date',
|
valueFormat: 'YYYY-MM-DD',
|
placeholder: '请选择结束时间'
|
}
|
}
|
])
|
|
async function openDetail(row) {
|
detailDrawerVisible.value = true
|
detailLoading.value = true
|
try {
|
const detail = await guardRequestWithMessage(fetchGetBasStationDetail(row.id), {}, {
|
timeoutMessage: '站点详情加载超时,已停止等待'
|
})
|
detailData.value = normalizeBasStationDetailRecord(detail, resolveAreaLabel, resolveContainerTypeLabel)
|
} catch (error) {
|
detailDrawerVisible.value = false
|
detailData.value = {}
|
ElMessage.error(error?.message || '获取站点详情失败')
|
} finally {
|
detailLoading.value = false
|
}
|
}
|
|
async function openEditDialog(row) {
|
try {
|
const detail = await guardRequestWithMessage(fetchGetBasStationDetail(row.id), {}, {
|
timeoutMessage: '站点详情加载超时,已停止等待'
|
})
|
showDialog('edit', detail)
|
} catch (error) {
|
ElMessage.error(error?.message || '获取站点详情失败')
|
}
|
}
|
|
const { columns, columnChecks, data, loading, pagination, getData, replaceSearchParams, resetSearchParams, handleSizeChange, handleCurrentChange, refreshData, refreshCreate, refreshUpdate, refreshRemove } =
|
useTable({
|
core: {
|
apiFn: fetchBasStationPage,
|
apiParams: buildBasStationPageQueryParams(searchForm.value),
|
paginationKey: getBasStationPaginationKey(),
|
columnsFactory: () =>
|
createBasStationTableColumns({
|
handleView: openDetail,
|
handleEdit: hasAuth('update') ? openEditDialog : null,
|
handleDelete: hasAuth('delete') ? (row) => handleDeleteAction?.(row) : null,
|
canEdit: hasAuth('update'),
|
canDelete: hasAuth('delete')
|
})
|
},
|
transform: {
|
dataTransformer: (records) => {
|
if (!Array.isArray(records)) {
|
return []
|
}
|
return records.map((item) => normalizeBasStationListRow(item, resolveAreaLabel, resolveContainerTypeLabel))
|
}
|
}
|
})
|
|
const {
|
dialogVisible,
|
dialogType,
|
currentRecord: currentStationData,
|
selectedRows,
|
handleSelectionChange,
|
showDialog,
|
handleDialogSubmit,
|
handleDelete,
|
handleBatchDelete
|
} = useCrudPage({
|
createEmptyModel: () => buildBasStationDialogModel(),
|
buildEditModel: (record) => buildBasStationDialogModel(record),
|
buildSavePayload: (formData) => buildBasStationSavePayload(formData),
|
saveRequest: fetchSaveBasStation,
|
updateRequest: fetchUpdateBasStation,
|
deleteRequest: fetchDeleteBasStation,
|
entityName: '站点',
|
resolveRecordLabel: (record) => record?.stationName || record?.stationId || record?.id,
|
refreshCreate,
|
refreshUpdate,
|
refreshRemove
|
})
|
handleDeleteAction = handleDelete
|
|
const buildPreviewMeta = (rows) => {
|
const now = new Date()
|
return {
|
reportDate: now.toLocaleDateString('zh-CN'),
|
printedAt: now.toLocaleString('zh-CN', { hour12: false }),
|
operator: userStore.getUserInfo?.name || userStore.getUserInfo?.username || '',
|
count: rows.length,
|
reportStyle: { ...BAS_STATION_REPORT_STYLE }
|
}
|
}
|
|
const resolvePrintRecords = async (payload) => {
|
if (Array.isArray(payload?.ids) && payload.ids.length > 0) {
|
return defaultResponseAdapter(await fetchGetBasStationMany(payload.ids)).records
|
}
|
return defaultResponseAdapter(
|
await fetchBasStationPage({
|
...reportQueryParams.value,
|
current: 1,
|
pageSize: Number(pagination.total) > 0 ? Number(pagination.total) : Number(payload?.pageSize) || 20
|
})
|
).records
|
}
|
|
const { previewVisible, previewRows, previewMeta, handlePreviewVisibleChange, handleExport, handlePrint } =
|
usePrintExportPage({
|
downloadFileName: 'bas-station.xlsx',
|
requestExport: (payload) =>
|
fetchExportBasStationReport(payload, {
|
headers: {
|
Authorization: userStore.accessToken || ''
|
}
|
}),
|
resolvePrintRecords,
|
buildPreviewRows: (records) => buildBasStationPrintRows(records, resolveAreaLabel, resolveContainerTypeLabel),
|
buildPreviewMeta
|
})
|
|
const resolvedPreviewMeta = computed(() =>
|
buildBasStationReportMeta({
|
previewMeta: previewMeta.value,
|
count: previewRows.value.length,
|
orientation: previewMeta.value?.reportStyle?.orientation || BAS_STATION_REPORT_STYLE.orientation
|
})
|
)
|
|
function handleSearch(params) {
|
replaceSearchParams(buildBasStationSearchParams(params))
|
getData()
|
}
|
|
function handleReset() {
|
Object.assign(searchForm.value, createBasStationSearchState())
|
resetSearchParams()
|
}
|
|
async function loadAreaOptions() {
|
const records = await guardRequestWithMessage(fetchWarehouseAreasList(), [], {
|
timeoutMessage: '库区加载超时,已停止等待'
|
})
|
areaOptions.value = resolveBasStationAreaOptions(defaultResponseAdapter(records).records)
|
}
|
|
async function loadContainerTypeOptions() {
|
const response = await guardRequestWithMessage(
|
fetchDictDataPage({
|
current: 1,
|
pageSize: 200,
|
dictTypeCode: 'sys_container_type',
|
status: 1
|
}),
|
{ records: [] },
|
{ timeoutMessage: '容器类型加载超时,已停止等待' }
|
)
|
containerTypeOptions.value = buildBasStationContainerTypeOptions(defaultResponseAdapter(response).records)
|
}
|
|
async function loadUseStatusOptions() {
|
const response = await guardRequestWithMessage(
|
fetchDictDataPage({
|
current: 1,
|
pageSize: 100,
|
dictTypeCode: 'sys_sta_use_stas',
|
status: 1
|
}),
|
{ records: [] },
|
{ timeoutMessage: '使用状态加载超时,已停止等待' }
|
)
|
useStatusOptions.value = buildBasStationUseStatusOptions(defaultResponseAdapter(response).records)
|
}
|
|
onMounted(async () => {
|
await Promise.all([loadAreaOptions(), loadContainerTypeOptions(), loadUseStatusOptions()])
|
})
|
</script>
|