<template>
|
<div class="bas-container-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"
|
/>
|
|
<BasContainerDialog
|
v-model:visible="dialogVisible"
|
:dialog-type="dialogType"
|
:container-data="currentContainerData"
|
:area-options="areaOptions"
|
:container-type-options="containerTypeOptions"
|
@submit="handleDialogSubmit"
|
/>
|
|
<BasContainerDetailDrawer
|
v-model:visible="detailDrawerVisible"
|
:loading="detailLoading"
|
:detail="detailData"
|
:resolve-area-label="resolveAreaLabel"
|
/>
|
</ElCard>
|
</div>
|
</template>
|
|
<script setup>
|
import { ElMessage } from 'element-plus'
|
import { computed, onMounted, reactive, ref } from 'vue'
|
import { useUserStore } from '@/store/modules/user'
|
import { useAuth } from '@/hooks/core/useAuth'
|
import { useTable } from '@/hooks/core/useTable'
|
import { useTableColumns } from '@/hooks/core/useTableColumns'
|
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 {
|
fetchBasContainerPage,
|
fetchDeleteBasContainer,
|
fetchExportBasContainerReport,
|
fetchGetBasContainerDetail,
|
fetchGetBasContainerMany,
|
fetchSaveBasContainer,
|
fetchUpdateBasContainer,
|
fetchWarehouseAreasList
|
} from '@/api/bas-container'
|
import { fetchDictDataPage } from '@/api/system-manage'
|
import BasContainerDialog from './modules/bas-container-dialog.vue'
|
import BasContainerDetailDrawer from './modules/bas-container-detail-drawer.vue'
|
import { createBasContainerTableColumns } from './basContainerTable.columns'
|
import {
|
BAS_CONTAINER_REPORT_STYLE,
|
BAS_CONTAINER_REPORT_TITLE,
|
buildBasContainerDialogModel,
|
buildBasContainerPageQueryParams,
|
buildBasContainerPrintRows,
|
buildBasContainerReportMeta,
|
buildBasContainerSavePayload,
|
buildBasContainerSearchParams,
|
buildBasContainerContainerTypeOptions,
|
createBasContainerSearchState,
|
getBasContainerPaginationKey,
|
normalizeBasContainerDetailRecord,
|
normalizeBasContainerListRow,
|
resolveBasContainerAreaOptions
|
} from './basContainerPage.helpers'
|
|
defineOptions({ name: 'BasContainer' })
|
|
const { hasAuth } = useAuth()
|
const userStore = useUserStore()
|
|
const searchForm = ref(createBasContainerSearchState())
|
const areaOptions = ref([])
|
const containerTypeOptions = ref([])
|
const detailDrawerVisible = ref(false)
|
const detailLoading = ref(false)
|
const detailData = ref({})
|
let handleDeleteAction = null
|
|
const reportTitle = BAS_CONTAINER_REPORT_TITLE
|
const reportQueryParams = computed(() => buildBasContainerSearchParams(searchForm.value))
|
const areaLabelMap = computed(
|
() =>
|
new Map(
|
areaOptions.value
|
.map((item) => [String(item.value), item.label])
|
.filter(([value, label]) => value && label)
|
)
|
)
|
|
function resolveAreaLabel(id) {
|
return areaLabelMap.value.get(String(id)) || ''
|
}
|
|
const searchItems = computed(() => [
|
{
|
label: '关键字',
|
key: 'condition',
|
type: 'input',
|
props: {
|
clearable: true,
|
placeholder: '请输入唯一编码/条码类型/备注'
|
}
|
},
|
{
|
label: '唯一编码',
|
key: 'code',
|
type: 'input',
|
props: {
|
clearable: true,
|
placeholder: '请输入唯一编码'
|
}
|
},
|
{
|
label: '容器类型',
|
key: 'containerType',
|
type: 'select',
|
props: {
|
clearable: true,
|
options: containerTypeOptions.value
|
}
|
},
|
{
|
label: '条码类型',
|
key: 'codeType',
|
type: 'input',
|
props: {
|
clearable: true,
|
placeholder: '请输入条码类型'
|
}
|
},
|
{
|
label: '可入库区',
|
key: 'areas',
|
type: 'input',
|
props: {
|
clearable: true,
|
placeholder: '请输入可入库区'
|
}
|
},
|
{
|
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(fetchGetBasContainerDetail(row.id), {}, {
|
timeoutMessage: '容器规则详情加载超时,已停止等待'
|
})
|
detailData.value = normalizeBasContainerDetailRecord(detail, resolveAreaLabel)
|
} catch (error) {
|
detailDrawerVisible.value = false
|
detailData.value = {}
|
ElMessage.error(error?.message || '获取容器规则详情失败')
|
} finally {
|
detailLoading.value = false
|
}
|
}
|
|
async function openEditDialog(row) {
|
try {
|
const detail = await guardRequestWithMessage(fetchGetBasContainerDetail(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: fetchBasContainerPage,
|
apiParams: buildBasContainerPageQueryParams(searchForm.value),
|
paginationKey: getBasContainerPaginationKey(),
|
columnsFactory: () =>
|
createBasContainerTableColumns({
|
handleView: openDetail,
|
handleEdit: hasAuth('update') ? openEditDialog : null,
|
handleDelete: hasAuth('delete') ? (row) => handleDeleteAction?.(row) : null,
|
resolveAreaLabel,
|
canEdit: hasAuth('update'),
|
canDelete: hasAuth('delete')
|
})
|
},
|
transform: {
|
dataTransformer: (records) => {
|
if (!Array.isArray(records)) {
|
return []
|
}
|
return records.map((item) => normalizeBasContainerListRow(item, resolveAreaLabel))
|
}
|
}
|
})
|
|
const {
|
dialogVisible,
|
dialogType,
|
currentRecord: currentContainerData,
|
selectedRows,
|
handleSelectionChange,
|
showDialog,
|
handleDialogSubmit,
|
handleDelete,
|
handleBatchDelete
|
} = useCrudPage({
|
createEmptyModel: () => buildBasContainerDialogModel(),
|
buildEditModel: (record) => buildBasContainerDialogModel(record),
|
buildSavePayload: (formData) => buildBasContainerSavePayload(formData),
|
saveRequest: fetchSaveBasContainer,
|
updateRequest: fetchUpdateBasContainer,
|
deleteRequest: fetchDeleteBasContainer,
|
entityName: '容器规则',
|
resolveRecordLabel: (record) => record?.code || 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_CONTAINER_REPORT_STYLE }
|
}
|
}
|
|
const resolvePrintRecords = async (payload) => {
|
if (Array.isArray(payload?.ids) && payload.ids.length > 0) {
|
return defaultResponseAdapter(await fetchGetBasContainerMany(payload.ids)).records
|
}
|
return defaultResponseAdapter(
|
await fetchBasContainerPage({
|
...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-container.xlsx',
|
requestExport: (payload) =>
|
fetchExportBasContainerReport(payload, {
|
headers: {
|
Authorization: userStore.accessToken || ''
|
}
|
}),
|
resolvePrintRecords,
|
buildPreviewRows: (records) => buildBasContainerPrintRows(records, resolveAreaLabel),
|
buildPreviewMeta
|
})
|
|
const resolvedPreviewMeta = computed(() =>
|
buildBasContainerReportMeta({
|
previewMeta: previewMeta.value,
|
count: previewRows.value.length,
|
orientation: previewMeta.value?.reportStyle?.orientation || BAS_CONTAINER_REPORT_STYLE.orientation
|
})
|
)
|
|
function handleSearch(params) {
|
replaceSearchParams(buildBasContainerSearchParams(params))
|
getData()
|
}
|
|
function handleReset() {
|
Object.assign(searchForm.value, createBasContainerSearchState())
|
resetSearchParams()
|
}
|
|
async function loadAreaOptions() {
|
const records = await guardRequestWithMessage(fetchWarehouseAreasList(), [], {
|
timeoutMessage: '可入库区加载超时,已停止等待'
|
})
|
areaOptions.value = resolveBasContainerAreaOptions(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 = buildBasContainerContainerTypeOptions(defaultResponseAdapter(response).records)
|
}
|
|
onMounted(async () => {
|
await Promise.all([loadAreaOptions(), loadContainerTypeOptions()])
|
})
|
</script>
|