<template>
|
<div class="loc-item-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" />
|
|
<ArtTable
|
:loading="loading"
|
:data="data"
|
:columns="columns"
|
:pagination="pagination"
|
@pagination:size-change="handleSizeChange"
|
@pagination:current-change="handleCurrentChange"
|
>
|
<template #action="{ row }">
|
<ArtButtonTable icon="ri:eye-line" @click="openDetail(row)" />
|
</template>
|
</ArtTable>
|
</ElCard>
|
|
<LocItemDetailDrawer
|
v-model:visible="detailDrawerVisible"
|
:detail="detailData"
|
:enabled-fields="detailFieldConfigs"
|
/>
|
</div>
|
</template>
|
|
<script setup>
|
import { computed, onMounted, ref } from 'vue'
|
import { useRoute } from 'vue-router'
|
import { useI18n } from 'vue-i18n'
|
import { ElMessage } from 'element-plus'
|
import { useTable } from '@/hooks/core/useTable'
|
import { guardRequestWithMessage } from '@/utils/sys/requestGuard'
|
import { useTableColumns } from '@/hooks/core/useTableColumns'
|
import { fetchEnabledFields, fetchLocItemDetail, fetchLocItemPage } from '@/api/loc-item'
|
import LocItemDetailDrawer from './modules/loc-item-detail-drawer.vue'
|
import { createLocItemTableColumns } from './locItemTable.columns'
|
import {
|
buildLocItemPageQueryParams,
|
buildLocItemSearchParams,
|
createLocItemSearchState,
|
getLocItemDynamicFieldKey,
|
getLocItemPaginationKey,
|
getLocItemStatusOptions,
|
normalizeLocItemEnabledFields,
|
normalizeLocItemRow
|
} from './locItemPage.helpers'
|
|
defineOptions({ name: 'LocItem' })
|
const { t } = useI18n()
|
|
const route = useRoute()
|
const searchForm = ref(createLocItemSearchState())
|
const detailDrawerVisible = ref(false)
|
const detailData = ref({})
|
const enabledFields = ref([])
|
|
const searchItems = computed(() => [
|
{
|
label: t('pages.manager.locItem.search.condition'),
|
key: 'condition',
|
type: 'input',
|
props: { clearable: true, placeholder: t('pages.manager.locItem.search.conditionPlaceholder') }
|
},
|
{
|
label: t('pages.manager.locItem.search.timeStart'),
|
key: 'timeStart',
|
type: 'date',
|
props: { clearable: true, valueFormat: 'YYYY-MM-DD', type: 'date' }
|
},
|
{
|
label: t('pages.manager.locItem.search.timeEnd'),
|
key: 'timeEnd',
|
type: 'date',
|
props: { clearable: true, valueFormat: 'YYYY-MM-DD', type: 'date' }
|
},
|
{
|
label: t('pages.manager.locItem.search.locId'),
|
key: 'locId',
|
type: 'inputNumber',
|
props: { min: 0, controlsPosition: 'right', placeholder: t('pages.manager.locItem.search.locIdPlaceholder') }
|
},
|
{
|
label: t('pages.manager.locItem.search.orderId'),
|
key: 'orderId',
|
type: 'inputNumber',
|
props: { min: 0, controlsPosition: 'right', placeholder: t('pages.manager.locItem.search.orderIdPlaceholder') }
|
},
|
{
|
label: t('pages.manager.locItem.search.type'),
|
key: 'type',
|
type: 'input',
|
props: { clearable: true, placeholder: t('pages.manager.locItem.search.typePlaceholder') }
|
},
|
{
|
label: t('pages.manager.locItem.search.wkType'),
|
key: 'wkType',
|
type: 'inputNumber',
|
props: { min: 0, controlsPosition: 'right', placeholder: t('pages.manager.locItem.search.wkTypePlaceholder') }
|
},
|
{
|
label: t('pages.manager.locItem.search.matnrCode'),
|
key: 'matnrCode',
|
type: 'input',
|
props: { clearable: true, placeholder: t('pages.manager.locItem.search.matnrCodePlaceholder') }
|
},
|
{
|
label: t('pages.manager.locItem.search.maktx'),
|
key: 'maktx',
|
type: 'input',
|
props: { clearable: true, placeholder: t('pages.manager.locItem.search.maktxPlaceholder') }
|
},
|
{
|
label: t('pages.manager.locItem.search.trackCode'),
|
key: 'trackCode',
|
type: 'input',
|
props: { clearable: true, placeholder: t('pages.manager.locItem.search.trackCodePlaceholder') }
|
},
|
{
|
label: t('pages.manager.locItem.search.batch'),
|
key: 'batch',
|
type: 'input',
|
props: { clearable: true, placeholder: t('pages.manager.locItem.search.batchPlaceholder') }
|
},
|
{
|
label: t('pages.manager.locItem.search.splrBatch'),
|
key: 'splrBatch',
|
type: 'input',
|
props: { clearable: true, placeholder: t('pages.manager.locItem.search.splrBatchPlaceholder') }
|
},
|
{
|
label: t('table.status'),
|
key: 'status',
|
type: 'select',
|
props: { clearable: true, options: getLocItemStatusOptions() }
|
}
|
])
|
|
const buildFieldConfigs = () =>
|
enabledFields.value.map((field) => ({
|
prop: getLocItemDynamicFieldKey(field.fields),
|
label: field.fieldsAlise
|
}))
|
|
const detailFieldConfigs = computed(() => buildFieldConfigs())
|
|
const { columns, columnChecks, resetColumns } = useTableColumns(() =>
|
createLocItemTableColumns({
|
enabledFields: buildFieldConfigs(),
|
handleView: openDetail
|
})
|
)
|
|
const {
|
data,
|
loading,
|
pagination,
|
getData,
|
replaceSearchParams,
|
resetSearchParams,
|
handleSizeChange,
|
handleCurrentChange,
|
refreshData
|
} = useTable({
|
core: {
|
apiFn: (params) =>
|
guardRequestWithMessage(
|
fetchLocItemPage(params),
|
{
|
records: [],
|
total: 0,
|
current: params.current || 1,
|
pageSize: params.pageSize || params.size || 20
|
},
|
{ timeoutMessage: t('pages.manager.locItem.messages.pageTimeout') }
|
),
|
apiParams: buildLocItemPageQueryParams(searchForm.value),
|
paginationKey: getLocItemPaginationKey()
|
},
|
transform: {
|
dataTransformer: (records) =>
|
Array.isArray(records) ? records.map((item) => normalizeLocItemRow(item, enabledFields.value)) : []
|
}
|
})
|
|
async function openDetail(row) {
|
detailDrawerVisible.value = true
|
try {
|
detailData.value = normalizeLocItemRow(await fetchLocItemDetail(row.id), enabledFields.value)
|
} catch (error) {
|
detailDrawerVisible.value = false
|
detailData.value = {}
|
ElMessage.error(error?.message || t('pages.manager.locItem.messages.detailFailed'))
|
}
|
}
|
|
async function loadEnabledFieldDefinitions() {
|
const fields = await guardRequestWithMessage(fetchEnabledFields(), [], {
|
timeoutMessage: t('pages.manager.locItem.messages.fieldsTimeout')
|
})
|
enabledFields.value = normalizeLocItemEnabledFields(fields)
|
resetColumns()
|
}
|
|
function handleSearch(params) {
|
replaceSearchParams(buildLocItemSearchParams(params))
|
getData()
|
}
|
|
function handleReset() {
|
const nextState = createLocItemSearchState()
|
if (route.query.locId) {
|
nextState.locId = route.query.locId
|
}
|
Object.assign(searchForm.value, nextState)
|
resetSearchParams()
|
}
|
|
onMounted(async () => {
|
if (route.query.locId) {
|
searchForm.value.locId = route.query.locId
|
replaceSearchParams(buildLocItemSearchParams(searchForm.value))
|
}
|
await loadEnabledFieldDefinitions()
|
await getData()
|
})
|
</script>
|