<template>
|
<div class="loc-area-mat-rela-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"
|
/>
|
|
<LocAreaMatRelaDialog
|
v-model:visible="dialogVisible"
|
:dialog-type="dialogType"
|
:rela-data="currentRelaData"
|
:area-mat-options="areaMatOptions"
|
:area-options="areaOptions"
|
:group-options="groupOptions"
|
:matnr-options="matnrOptions"
|
:loc-type-options="locTypeOptions"
|
:loc-options="locOptions"
|
@submit="handleDialogSubmit"
|
/>
|
|
<LocAreaMatRelaDetailDrawer
|
v-model:visible="detailDrawerVisible"
|
:loading="detailLoading"
|
:detail="detailData"
|
/>
|
</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 { fetchWarehouseAreasList } from '@/api/loc'
|
import { fetchLocAreaMatList } from '@/api/loc-area-mat'
|
import { fetchLocPage, fetchLocTypeList } from '@/api/loc'
|
import { fetchMatnrGroupTree, fetchMatnrPage } from '@/api/wh-mat'
|
import {
|
fetchDeleteLocAreaMatRela,
|
fetchExportLocAreaMatRelaReport,
|
fetchGetLocAreaMatRelaDetail,
|
fetchGetLocAreaMatRelaMany,
|
fetchLocAreaMatRelaPage,
|
fetchSaveLocAreaMatRela,
|
fetchUpdateLocAreaMatRela
|
} from '@/api/loc-area-mat-rela'
|
import LocAreaMatRelaDialog from './modules/loc-area-mat-rela-dialog.vue'
|
import LocAreaMatRelaDetailDrawer from './modules/loc-area-mat-rela-detail-drawer.vue'
|
import { createLocAreaMatRelaTableColumns } from './locAreaMatRelaTable.columns'
|
import {
|
LOC_AREA_MAT_RELA_REPORT_STYLE,
|
LOC_AREA_MAT_RELA_REPORT_TITLE,
|
buildLocAreaMatRelaDialogModel,
|
buildLocAreaMatRelaPageQueryParams,
|
buildLocAreaMatRelaPrintRows,
|
buildLocAreaMatRelaReportMeta,
|
buildLocAreaMatRelaSavePayload,
|
buildLocAreaMatRelaSearchParams,
|
createLocAreaMatRelaLookupMaps,
|
createLocAreaMatRelaSearchState,
|
getLocAreaMatRelaPaginationKey,
|
getLocAreaMatRelaStatusOptions,
|
normalizeLocAreaMatRelaDetailRecord,
|
normalizeLocAreaMatRelaListRow,
|
resolveLocAreaMatRelaAreaMatOptions,
|
resolveLocAreaMatRelaAreaOptions,
|
resolveLocAreaMatRelaGroupOptions,
|
resolveLocAreaMatRelaLocOptions,
|
resolveLocAreaMatRelaLocTypeOptions,
|
resolveLocAreaMatRelaMatnrOptions
|
} from './locAreaMatRelaPage.helpers'
|
|
defineOptions({ name: 'LocAreaMatRela' })
|
|
const { hasAuth } = useAuth()
|
const userStore = useUserStore()
|
|
const searchForm = ref(createLocAreaMatRelaSearchState())
|
const areaMatOptions = ref([])
|
const areaOptions = ref([])
|
const groupOptions = ref([])
|
const matnrOptions = ref([])
|
const locTypeOptions = ref([])
|
const locOptions = ref([])
|
const detailDrawerVisible = ref(false)
|
const detailLoading = ref(false)
|
const detailData = ref({})
|
let handleDeleteAction = null
|
|
const reportTitle = LOC_AREA_MAT_RELA_REPORT_TITLE
|
const reportQueryParams = computed(() => buildLocAreaMatRelaSearchParams(searchForm.value))
|
const lookupMaps = computed(() =>
|
createLocAreaMatRelaLookupMaps({
|
areaMatOptions: areaMatOptions.value,
|
areaOptions: areaOptions.value,
|
matnrOptions: matnrOptions.value,
|
groupOptions: groupOptions.value,
|
locTypeOptions: locTypeOptions.value,
|
locOptions: locOptions.value
|
})
|
)
|
|
const searchItems = computed(() => [
|
{
|
label: '关键字',
|
key: 'condition',
|
type: 'input',
|
props: {
|
clearable: true,
|
placeholder: '请输入编号/备注/关系信息'
|
}
|
},
|
{
|
label: '主单',
|
key: 'areaMatId',
|
type: 'select',
|
props: {
|
clearable: true,
|
filterable: true,
|
options: areaMatOptions.value
|
}
|
},
|
{
|
label: '库区',
|
key: 'areaId',
|
type: 'select',
|
props: {
|
clearable: true,
|
filterable: true,
|
options: areaOptions.value
|
}
|
},
|
{
|
label: '编号',
|
key: 'code',
|
type: 'input',
|
props: {
|
clearable: true,
|
placeholder: '请输入编号'
|
}
|
},
|
{
|
label: '物料',
|
key: 'matnrId',
|
type: 'select',
|
props: {
|
clearable: true,
|
filterable: true,
|
options: matnrOptions.value
|
}
|
},
|
{
|
label: '物料分组',
|
key: 'groupId',
|
type: 'treeselect',
|
props: {
|
data: groupOptions.value,
|
props: {
|
label: 'displayLabel',
|
value: 'id',
|
children: 'children'
|
},
|
clearable: true,
|
checkStrictly: true,
|
defaultExpandAll: true,
|
placeholder: '请选择物料分组'
|
}
|
},
|
{
|
label: '库位类型',
|
key: 'locTypeId',
|
type: 'select',
|
props: {
|
clearable: true,
|
filterable: true,
|
options: locTypeOptions.value
|
}
|
},
|
{
|
label: '库位',
|
key: 'locId',
|
type: 'select',
|
props: {
|
clearable: true,
|
filterable: true,
|
options: locOptions.value
|
}
|
},
|
{
|
label: '状态',
|
key: 'status',
|
type: 'select',
|
props: {
|
clearable: true,
|
options: getLocAreaMatRelaStatusOptions()
|
}
|
},
|
{
|
label: '备注',
|
key: 'memo',
|
type: 'input',
|
props: {
|
clearable: true,
|
placeholder: '请输入备注'
|
}
|
}
|
])
|
|
async function openDetail(row) {
|
detailDrawerVisible.value = true
|
detailLoading.value = true
|
try {
|
const detail = await guardRequestWithMessage(fetchGetLocAreaMatRelaDetail(row.id), {}, {
|
timeoutMessage: '库区物料关系详情加载超时,已停止等待'
|
})
|
detailData.value = normalizeLocAreaMatRelaDetailRecord(detail, lookupMaps.value)
|
} catch (error) {
|
detailDrawerVisible.value = false
|
detailData.value = {}
|
ElMessage.error(error?.message || '获取库区物料关系详情失败')
|
} finally {
|
detailLoading.value = false
|
}
|
}
|
|
async function openEditDialog(row) {
|
try {
|
const detail = await guardRequestWithMessage(fetchGetLocAreaMatRelaDetail(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: fetchLocAreaMatRelaPage,
|
apiParams: buildLocAreaMatRelaPageQueryParams(searchForm.value),
|
paginationKey: getLocAreaMatRelaPaginationKey(),
|
columnsFactory: () =>
|
createLocAreaMatRelaTableColumns({
|
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) => normalizeLocAreaMatRelaListRow(item, lookupMaps.value))
|
}
|
}
|
})
|
|
const {
|
dialogVisible,
|
dialogType,
|
currentRecord: currentRelaData,
|
selectedRows,
|
handleSelectionChange,
|
showDialog,
|
handleDialogSubmit,
|
handleDelete,
|
handleBatchDelete
|
} = useCrudPage({
|
createEmptyModel: () => buildLocAreaMatRelaDialogModel(),
|
buildEditModel: (record) => buildLocAreaMatRelaDialogModel(record),
|
buildSavePayload: (formData) => buildLocAreaMatRelaSavePayload(formData),
|
saveRequest: fetchSaveLocAreaMatRela,
|
updateRequest: fetchUpdateLocAreaMatRela,
|
deleteRequest: fetchDeleteLocAreaMatRela,
|
entityName: '库区物料关系',
|
resolveRecordLabel: (record) => record?.areaMatIdText || record?.code || record?.relationTypeText || record?.id,
|
refreshCreate,
|
refreshUpdate,
|
refreshRemove
|
})
|
handleDeleteAction = handleDelete
|
|
const buildPreviewDialogMeta = (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
|
}
|
}
|
|
const resolvePrintRecords = async (payload) => {
|
const response =
|
Array.isArray(payload?.ids) && payload.ids.length > 0
|
? await fetchGetLocAreaMatRelaMany(payload.ids)
|
: await fetchLocAreaMatRelaPage({
|
...reportQueryParams.value,
|
current: 1,
|
pageSize: Number(pagination.total) > 0 ? Number(pagination.total) : Number(payload?.pageSize) || 20
|
})
|
return defaultResponseAdapter(response).records
|
}
|
|
const {
|
previewVisible,
|
previewRows,
|
previewMeta,
|
handlePreviewVisibleChange,
|
handleExport,
|
handlePrint
|
} = usePrintExportPage({
|
downloadFileName: 'loc-area-mat-rela.xlsx',
|
requestExport: (payload) =>
|
fetchExportLocAreaMatRelaReport(payload, {
|
headers: {
|
Authorization: userStore.accessToken || ''
|
}
|
}),
|
resolvePrintRecords,
|
buildPreviewRows: (records) => buildLocAreaMatRelaPrintRows(records, lookupMaps.value),
|
buildPreviewMeta: buildPreviewDialogMeta
|
})
|
|
const resolvedPreviewMeta = computed(() =>
|
buildLocAreaMatRelaReportMeta({
|
previewMeta: previewMeta.value,
|
count: previewRows.value.length,
|
orientation: previewMeta.value?.reportStyle?.orientation || LOC_AREA_MAT_RELA_REPORT_STYLE.orientation
|
})
|
)
|
|
function handleSearch(params) {
|
replaceSearchParams(buildLocAreaMatRelaSearchParams(params))
|
getData()
|
}
|
|
function handleReset() {
|
Object.assign(searchForm.value, createLocAreaMatRelaSearchState())
|
resetSearchParams()
|
}
|
|
async function loadAreaMatOptions() {
|
const records = await guardRequestWithMessage(fetchLocAreaMatList(), [], {
|
timeoutMessage: '主单选项加载超时,已停止等待'
|
})
|
areaMatOptions.value = resolveLocAreaMatRelaAreaMatOptions(defaultResponseAdapter(records).records)
|
}
|
|
async function loadAreaOptions() {
|
const records = await guardRequestWithMessage(fetchWarehouseAreasList(), [], {
|
timeoutMessage: '库区选项加载超时,已停止等待'
|
})
|
areaOptions.value = resolveLocAreaMatRelaAreaOptions(defaultResponseAdapter(records).records)
|
}
|
|
async function loadGroupOptions() {
|
const records = await guardRequestWithMessage(fetchMatnrGroupTree({}), [], {
|
timeoutMessage: '物料分组选项加载超时,已停止等待'
|
})
|
groupOptions.value = resolveLocAreaMatRelaGroupOptions(defaultResponseAdapter(records).records)
|
}
|
|
async function loadMatnrOptions() {
|
const response = await guardRequestWithMessage(
|
fetchMatnrPage({ current: 1, pageSize: 200 }),
|
{ records: [] },
|
{ timeoutMessage: '物料选项加载超时,已停止等待' }
|
)
|
matnrOptions.value = resolveLocAreaMatRelaMatnrOptions(defaultResponseAdapter(response).records)
|
}
|
|
async function loadLocTypeOptions() {
|
const records = await guardRequestWithMessage(fetchLocTypeList(), [], {
|
timeoutMessage: '库位类型选项加载超时,已停止等待'
|
})
|
locTypeOptions.value = resolveLocAreaMatRelaLocTypeOptions(defaultResponseAdapter(records).records)
|
}
|
|
async function loadLocOptions() {
|
const response = await guardRequestWithMessage(
|
fetchLocPage({ current: 1, pageSize: 200 }),
|
{ records: [] },
|
{ timeoutMessage: '库位选项加载超时,已停止等待' }
|
)
|
locOptions.value = resolveLocAreaMatRelaLocOptions(defaultResponseAdapter(response).records)
|
}
|
|
onMounted(async () => {
|
await Promise.all([
|
loadAreaMatOptions(),
|
loadAreaOptions(),
|
loadGroupOptions(),
|
loadMatnrOptions(),
|
loadLocTypeOptions(),
|
loadLocOptions(),
|
getData()
|
])
|
})
|
</script>
|