<template>
|
<div class="purchase-item-page art-full-height">
|
<ElCard v-if="activeSourceSummary" class="mb-3">
|
<div class="flex items-center justify-between gap-3">
|
<div class="flex items-center gap-2 text-sm text-[var(--art-text-gray-600)]">
|
<span class="font-medium text-[var(--art-text-gray-900)]">当前来源</span>
|
<span>PO单ID:{{ activeSourceSummary.purchaseId }}</span>
|
</div>
|
<ElButton link type="primary" @click="handleClearSourceFilter">查看全部</ElButton>
|
</div>
|
</ElCard>
|
|
<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>
|
<ListExportPrint
|
: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"
|
/>
|
</template>
|
</ArtTableHeader>
|
|
<ArtTable
|
:loading="loading"
|
:data="data"
|
:columns="columns"
|
:pagination="pagination"
|
@selection-change="handleSelectionChange"
|
@pagination:size-change="handleSizeChange"
|
@pagination:current-change="handleCurrentChange"
|
/>
|
</ElCard>
|
|
<PurchaseItemDetailDrawer
|
v-model:visible="detailDrawerVisible"
|
:loading="detailLoading"
|
:detail-data="detailData"
|
/>
|
</div>
|
</template>
|
|
<script setup>
|
import { computed, onMounted, ref, watch } from 'vue'
|
import { ElButton, ElMessage } from 'element-plus'
|
import { useRoute, useRouter } from 'vue-router'
|
import { useUserStore } from '@/store/modules/user'
|
import { useTable } from '@/hooks/core/useTable'
|
import { defaultResponseAdapter } from '@/utils/table/tableUtils'
|
import { guardRequestWithMessage } from '@/utils/sys/requestGuard'
|
import { usePrintExportPage } from '@/views/system/common/usePrintExportPage'
|
import ListExportPrint from '@/components/biz/list-export-print/index.vue'
|
import {
|
fetchExportPurchaseItemReport,
|
fetchPurchaseItemDetail,
|
fetchPurchaseItemMany,
|
fetchPurchaseItemPage
|
} from '@/api/purchase-item'
|
import PurchaseItemDetailDrawer from './modules/purchase-item-detail-drawer.vue'
|
import { createPurchaseItemTableColumns } from './purchaseItemTable.columns.js'
|
import {
|
PURCHASE_ITEM_REPORT_STYLE,
|
PURCHASE_ITEM_REPORT_TITLE,
|
buildPurchaseItemPageQueryParams,
|
buildPurchaseItemPrintRows,
|
buildPurchaseItemReportMeta,
|
buildPurchaseItemSearchParams,
|
createPurchaseItemSearchState,
|
getPurchaseItemPaginationKey,
|
normalizePurchaseItemRow
|
} from './purchaseItemPage.helpers.js'
|
|
defineOptions({ name: 'PurchaseItem' })
|
|
const userStore = useUserStore()
|
const route = useRoute()
|
const router = useRouter()
|
const reportTitle = PURCHASE_ITEM_REPORT_TITLE
|
const searchForm = ref(createPurchaseItemSearchState())
|
const selectedRows = ref([])
|
const detailDrawerVisible = ref(false)
|
const detailLoading = ref(false)
|
const detailData = ref({})
|
|
const activeSourceSummary = computed(() => {
|
if (searchForm.value.purchaseId === '' || searchForm.value.purchaseId === undefined || searchForm.value.purchaseId === null) {
|
return null
|
}
|
return {
|
purchaseId: searchForm.value.purchaseId
|
}
|
})
|
|
const searchItems = computed(() => [
|
{
|
label: '关键字',
|
key: 'condition',
|
type: 'input',
|
props: {
|
clearable: true,
|
placeholder: '请输入主单标识/物料编码/供应商信息'
|
}
|
},
|
{
|
label: '主单标识',
|
key: 'purchaseId',
|
type: 'inputNumber',
|
props: {
|
clearable: true,
|
min: 0,
|
controlsPosition: 'right',
|
placeholder: '请输入主单标识'
|
}
|
},
|
{
|
label: 'ERP行号',
|
key: 'platItemId',
|
type: 'input',
|
props: {
|
clearable: true,
|
placeholder: '请输入ERP行号'
|
}
|
},
|
{
|
label: '物料编码',
|
key: 'matnrCode',
|
type: 'input',
|
props: {
|
clearable: true,
|
placeholder: '请输入物料编码'
|
}
|
},
|
{
|
label: '物料名称',
|
key: 'matnrName',
|
type: 'input',
|
props: {
|
clearable: true,
|
placeholder: '请输入物料名称'
|
}
|
},
|
{
|
label: '单位',
|
key: 'unit',
|
type: 'input',
|
props: {
|
clearable: true,
|
placeholder: '请输入单位'
|
}
|
},
|
{
|
label: '数量',
|
key: 'anfme',
|
type: 'inputNumber',
|
props: {
|
clearable: true,
|
min: 0,
|
controlsPosition: 'right',
|
placeholder: '请输入数量'
|
}
|
},
|
{
|
label: '已收数量',
|
key: 'qty',
|
type: 'inputNumber',
|
props: {
|
clearable: true,
|
min: 0,
|
controlsPosition: 'right',
|
placeholder: '请输入已收数量'
|
}
|
},
|
{
|
label: '标准包装',
|
key: 'nromQty',
|
type: 'inputNumber',
|
props: {
|
clearable: true,
|
min: 0,
|
controlsPosition: 'right',
|
placeholder: '请输入标准包装'
|
}
|
},
|
{
|
label: 'ASN单据数量',
|
key: 'asnQty',
|
type: 'inputNumber',
|
props: {
|
clearable: true,
|
min: 0,
|
controlsPosition: 'right',
|
placeholder: '请输入ASN单据数量'
|
}
|
},
|
{
|
label: '条码打印数量',
|
key: 'printQty',
|
type: 'inputNumber',
|
props: {
|
clearable: true,
|
min: 0,
|
controlsPosition: 'right',
|
placeholder: '请输入条码打印数量'
|
}
|
},
|
{
|
label: '供应商名称',
|
key: 'splrName',
|
type: 'input',
|
props: {
|
clearable: true,
|
placeholder: '请输入供应商名称'
|
}
|
},
|
{
|
label: '供应商编码',
|
key: 'splrCode',
|
type: 'input',
|
props: {
|
clearable: true,
|
placeholder: '请输入供应商编码'
|
}
|
},
|
{
|
label: '供应商批次',
|
key: 'splrBatch',
|
type: 'input',
|
props: {
|
clearable: true,
|
placeholder: '请输入供应商批次'
|
}
|
},
|
{
|
label: '备注',
|
key: 'memo',
|
type: 'input',
|
props: {
|
clearable: true,
|
placeholder: '请输入备注'
|
}
|
},
|
{
|
label: '状态',
|
key: 'status',
|
type: 'select',
|
props: {
|
clearable: true,
|
options: [
|
{ label: '正常', value: 1 },
|
{ label: '冻结', value: 0 }
|
],
|
placeholder: '请选择状态'
|
}
|
}
|
])
|
|
const reportQueryParams = computed(() => buildPurchaseItemSearchParams(searchForm.value))
|
|
const { columns, columnChecks, data, loading, pagination, getData, replaceSearchParams, resetSearchParams, handleSizeChange, handleCurrentChange, refreshData } =
|
useTable({
|
core: {
|
apiFn: fetchPurchaseItemPage,
|
apiParams: buildPurchaseItemPageQueryParams(searchForm.value),
|
paginationKey: getPurchaseItemPaginationKey(),
|
columnsFactory: () =>
|
createPurchaseItemTableColumns({
|
handleView: openDetail
|
})
|
},
|
transform: {
|
dataTransformer: (records) =>
|
Array.isArray(records) ? records.map((item) => normalizePurchaseItemRow(item)) : []
|
}
|
})
|
|
function handleSelectionChange(rows) {
|
selectedRows.value = Array.isArray(rows) ? rows : []
|
}
|
|
async function openDetail(row) {
|
detailDrawerVisible.value = true
|
detailLoading.value = true
|
try {
|
const detail = await guardRequestWithMessage(fetchPurchaseItemDetail(row.id), {}, {
|
timeoutMessage: 'PO单明细详情加载超时,已停止等待'
|
})
|
detailData.value = normalizePurchaseItemRow({
|
...row,
|
...(detail || {})
|
})
|
} catch (error) {
|
detailDrawerVisible.value = false
|
detailData.value = {}
|
ElMessage.error(error?.message || '获取PO单明细详情失败')
|
} finally {
|
detailLoading.value = false
|
}
|
}
|
|
function handleSearch(params) {
|
searchForm.value = {
|
...searchForm.value,
|
...params
|
}
|
replaceSearchParams(buildPurchaseItemPageQueryParams(searchForm.value))
|
getData()
|
}
|
|
function handleReset() {
|
Object.assign(searchForm.value, createPurchaseItemSearchState())
|
resetSearchParams()
|
}
|
|
function applyRouteSearch() {
|
const purchaseId = route.query.purchaseId
|
if (purchaseId === undefined || purchaseId === null || purchaseId === '') {
|
return
|
}
|
searchForm.value.purchaseId = Number.isFinite(Number(purchaseId))
|
? Number(purchaseId)
|
: searchForm.value.purchaseId
|
}
|
|
function handleClearSourceFilter() {
|
searchForm.value.purchaseId = ''
|
router.replace({
|
path: route.path,
|
query: {
|
...route.query,
|
purchaseId: undefined
|
}
|
})
|
replaceSearchParams(buildPurchaseItemPageQueryParams(searchForm.value))
|
getData()
|
}
|
|
const buildPreviewMeta = (rows) => {
|
const now = new Date()
|
return {
|
reportTitle,
|
reportDate: now.toLocaleDateString('zh-CN'),
|
printedAt: now.toLocaleString('zh-CN', { hour12: false }),
|
operator: userStore.getUserInfo?.name || userStore.getUserInfo?.username || '',
|
count: rows.length,
|
reportStyle: {
|
...PURCHASE_ITEM_REPORT_STYLE
|
}
|
}
|
}
|
|
const resolvePrintRecords = async (payload) => {
|
if (Array.isArray(payload?.ids) && payload.ids.length > 0) {
|
return defaultResponseAdapter(await fetchPurchaseItemMany(payload.ids)).records
|
}
|
|
return defaultResponseAdapter(
|
await fetchPurchaseItemPage({
|
...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: 'purchase-item.xlsx',
|
requestExport: (payload) =>
|
fetchExportPurchaseItemReport(payload, {
|
headers: {
|
Authorization: userStore.accessToken || ''
|
}
|
}),
|
resolvePrintRecords,
|
buildPreviewRows: (records) => buildPurchaseItemPrintRows(records),
|
buildPreviewMeta
|
})
|
|
const resolvedPreviewMeta = computed(() =>
|
buildPurchaseItemReportMeta({
|
previewMeta: previewMeta.value,
|
count: previewRows.value.length,
|
orientation:
|
previewMeta.value?.reportStyle?.orientation || PURCHASE_ITEM_REPORT_STYLE.orientation
|
})
|
)
|
|
watch(
|
() => route.query.purchaseId,
|
(value) => {
|
if (value === undefined || value === null || value === '') {
|
return
|
}
|
applyRouteSearch()
|
replaceSearchParams(buildPurchaseItemPageQueryParams(searchForm.value))
|
getData()
|
}
|
)
|
|
onMounted(() => {
|
applyRouteSearch()
|
replaceSearchParams(buildPurchaseItemPageQueryParams(searchForm.value))
|
getData()
|
})
|
</script>
|