<template>
|
<div class="out-bound-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>
|
<span class="text-sm text-[var(--art-text-secondary)]">已选库存 {{ selectedBrowseRows.length }} 条</span>
|
<ElButton type="primary" :disabled="selectedBrowseRows.length === 0" @click="handleCollectSelectedRows">
|
加入任务篮
|
</ElButton>
|
</ElSpace>
|
</template>
|
</ArtTableHeader>
|
|
<ArtTable
|
:loading="loading"
|
:data="data"
|
:columns="columns"
|
:pagination="pagination"
|
@selection-change="handleSelectionChange"
|
@pagination:size-change="handleSizeChange"
|
@pagination:current-change="handleCurrentChange"
|
/>
|
</ElCard>
|
|
<ElCard class="art-table-card">
|
<template #header>
|
<div class="flex flex-wrap items-center justify-between gap-4">
|
<div>
|
<div class="text-base font-medium text-[var(--art-text-primary)]">任务篮</div>
|
<div class="text-xs text-[var(--art-text-secondary)]">
|
{{ basketSummaryText }}
|
</div>
|
</div>
|
|
<ElSpace wrap>
|
<ElSelect
|
v-model="taskForm.siteNo"
|
filterable
|
clearable
|
placeholder="请选择出库站点"
|
style="min-width: 220px"
|
>
|
<ElOption v-for="option in siteOptions" :key="option.value" :label="option.label" :value="option.value" />
|
</ElSelect>
|
<ElInput v-model="taskForm.memo" clearable placeholder="请输入任务备注" style="min-width: 220px" />
|
<ElButton type="primary" :disabled="basketRows.length === 0" :loading="generating" @click="handleGenerateTask">
|
生成任务
|
</ElButton>
|
<ElButton :disabled="basketRows.length === 0" @click="handleClearBasket">清空任务篮</ElButton>
|
</ElSpace>
|
</div>
|
</template>
|
|
<ArtTable :loading="false" :data="basketRows" :columns="basketColumns" :pagination="basketPagination" />
|
</ElCard>
|
|
<OutBoundDetailDrawer v-model:visible="detailDrawerVisible" :detail="detailData" />
|
</div>
|
</template>
|
|
<script setup>
|
import { computed, onMounted, ref } from 'vue'
|
import { ElMessage, ElMessageBox } from 'element-plus'
|
import { useTable } from '@/hooks/core/useTable'
|
import { useTableColumns } from '@/hooks/core/useTableColumns'
|
import { guardRequestWithMessage } from '@/utils/sys/requestGuard'
|
import {
|
fetchGenerateOutboundTask,
|
fetchGetOutboundInventoryDetail,
|
fetchOutboundInventoryPage,
|
fetchOutboundSiteList,
|
normalizeOutboundTaskPayload
|
} from '@/api/out-bound'
|
import OutBoundDetailDrawer from './modules/out-bound-detail-drawer.vue'
|
import { createOutBoundInventoryTableColumns, createOutBoundBasketTableColumns } from './outBoundTable.columns'
|
import {
|
buildOutBoundGenerateTaskPayload,
|
buildOutBoundPageQueryParams,
|
createOutBoundSearchState,
|
createOutBoundTaskState,
|
getOutBoundValidationMessage,
|
mergeOutBoundBasketRows,
|
normalizeOutBoundBasketRows,
|
normalizeOutBoundRow,
|
normalizeOutBoundSiteOptions
|
} from './outBoundPage.helpers'
|
|
defineOptions({ name: 'OutBound' })
|
|
const searchForm = ref(createOutBoundSearchState())
|
const taskForm = ref(createOutBoundTaskState())
|
const selectedBrowseRows = ref([])
|
const basketRows = ref([])
|
const siteOptions = ref([])
|
const detailDrawerVisible = ref(false)
|
const detailData = ref({})
|
const generating = ref(false)
|
|
const searchItems = computed(() => [
|
{
|
label: '关键字',
|
key: 'condition',
|
type: 'input',
|
props: {
|
clearable: true,
|
placeholder: '请输入库位/物料/批次关键字'
|
}
|
},
|
{
|
label: '库位编码',
|
key: 'locCode',
|
type: 'input',
|
props: {
|
clearable: true,
|
placeholder: '请输入库位编码'
|
}
|
},
|
{
|
label: '物料编码',
|
key: 'matnrCode',
|
type: 'input',
|
props: {
|
clearable: true,
|
placeholder: '请输入物料编码'
|
}
|
},
|
{
|
label: '物料名称',
|
key: 'maktx',
|
type: 'input',
|
props: {
|
clearable: true,
|
placeholder: '请输入物料名称'
|
}
|
},
|
{
|
label: '批次',
|
key: 'batch',
|
type: 'input',
|
props: {
|
clearable: true,
|
placeholder: '请输入批次'
|
}
|
},
|
{
|
label: '供应商批次',
|
key: 'splrBatch',
|
type: 'input',
|
props: {
|
clearable: true,
|
placeholder: '请输入供应商批次'
|
}
|
},
|
{
|
label: '追踪码',
|
key: 'trackCode',
|
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: '请输入备注'
|
}
|
}
|
])
|
|
const basketPagination = computed(() => ({
|
current: 1,
|
size: Math.max(basketRows.value.length, 1),
|
total: basketRows.value.length
|
}))
|
|
const basketSummaryText = computed(() => {
|
const totalQty = basketRows.value.reduce((sum, row) => sum + Number(row.outQty || 0), 0)
|
return `已选 ${basketRows.value.length} 条,合计出库数量 ${totalQty}`
|
})
|
|
function buildBasketRowKey(row = {}) {
|
return row.id ?? `${row.locId || ''}-${row.matnrCode || ''}-${row.batch || ''}-${row.trackCode || ''}`
|
}
|
|
async function openDetailDrawer(row) {
|
detailDrawerVisible.value = true
|
try {
|
const detail = await guardRequestWithMessage(fetchGetOutboundInventoryDetail(row.id), {}, {
|
timeoutMessage: '库存明细详情加载超时,已停止等待'
|
})
|
detailData.value = normalizeOutBoundRow(detail)
|
} catch (error) {
|
detailDrawerVisible.value = false
|
detailData.value = {}
|
ElMessage.error(error?.message || '获取库存明细详情失败')
|
}
|
}
|
|
function handleSelectionChange(rows) {
|
selectedBrowseRows.value = Array.isArray(rows) ? rows : []
|
}
|
|
function handleCollectSelectedRows(rows = selectedBrowseRows.value) {
|
if (!Array.isArray(rows) || rows.length === 0) {
|
ElMessage.warning('请先选择库存明细')
|
return
|
}
|
basketRows.value = mergeOutBoundBasketRows(basketRows.value, rows)
|
selectedBrowseRows.value = []
|
ElMessage.success(`已加入 ${rows.length} 条库存明细`)
|
}
|
|
function handleAddToBasket(rows) {
|
basketRows.value = mergeOutBoundBasketRows(basketRows.value, rows)
|
}
|
|
function handleRemoveBasketRow(row) {
|
const key = buildBasketRowKey(row)
|
basketRows.value = basketRows.value.filter((item) => buildBasketRowKey(item) !== key)
|
}
|
|
function handleOutQtyChange(row, value) {
|
const key = buildBasketRowKey(row)
|
basketRows.value = basketRows.value.map((item) => {
|
if (buildBasketRowKey(item) !== key) {
|
return item
|
}
|
const numericValue = Number(value ?? 0)
|
return {
|
...item,
|
outQty: Number.isFinite(numericValue) ? numericValue : 0
|
}
|
})
|
}
|
|
function handleClearBasket() {
|
basketRows.value = []
|
taskForm.value = createOutBoundTaskState()
|
}
|
|
async function handleGenerateTask() {
|
const message = getOutBoundValidationMessage({
|
siteNo: taskForm.value.siteNo,
|
items: basketRows.value
|
})
|
if (message) {
|
ElMessage.warning(message)
|
return
|
}
|
|
try {
|
generating.value = true
|
await ElMessageBox.confirm('确定根据当前任务篮生成出库任务吗?', '生成确认', {
|
confirmButtonText: '确定',
|
cancelButtonText: '取消',
|
type: 'warning'
|
})
|
await fetchGenerateOutboundTask(
|
normalizeOutboundTaskPayload(
|
buildOutBoundGenerateTaskPayload({
|
siteNo: taskForm.value.siteNo,
|
memo: taskForm.value.memo,
|
items: normalizeOutBoundBasketRows(basketRows.value)
|
})
|
)
|
)
|
ElMessage.success('任务生成成功')
|
basketRows.value = []
|
taskForm.value = createOutBoundTaskState()
|
await refreshData()
|
} catch (error) {
|
if (error === 'cancel' || error?.message === 'cancel') {
|
return
|
}
|
ElMessage.error(error?.message || '生成任务失败')
|
} finally {
|
generating.value = false
|
}
|
}
|
|
const { columns, columnChecks } = useTableColumns(() =>
|
createOutBoundInventoryTableColumns({
|
handleViewDetail: openDetailDrawer,
|
handleAddToBasket
|
})
|
)
|
|
const basketColumns = computed(() =>
|
createOutBoundBasketTableColumns({
|
handleRemoveBasketRow,
|
handleOutQtyChange
|
})
|
)
|
|
const {
|
data,
|
loading,
|
pagination,
|
replaceSearchParams,
|
resetSearchParams,
|
handleSizeChange,
|
handleCurrentChange,
|
refreshData,
|
getData
|
} = useTable({
|
core: {
|
apiFn: fetchOutboundInventoryPage,
|
apiParams: buildOutBoundPageQueryParams(searchForm.value),
|
columnsFactory: () => createOutBoundInventoryTableColumns({
|
handleViewDetail: openDetailDrawer,
|
handleAddToBasket
|
})
|
},
|
transform: {
|
dataTransformer: (records) => (Array.isArray(records) ? records.map((record) => normalizeOutBoundRow(record)) : [])
|
}
|
})
|
|
async function loadSiteOptions() {
|
const records = await guardRequestWithMessage(fetchOutboundSiteList(), [], {
|
timeoutMessage: '出库站点加载超时,已停止等待'
|
})
|
siteOptions.value = normalizeOutBoundSiteOptions(records)
|
}
|
|
function handleSearch(params) {
|
searchForm.value = {
|
...searchForm.value,
|
...params
|
}
|
replaceSearchParams(buildOutBoundPageQueryParams(searchForm.value))
|
getData()
|
}
|
|
function handleReset() {
|
searchForm.value = createOutBoundSearchState()
|
resetSearchParams()
|
}
|
|
onMounted(async () => {
|
await loadSiteOptions()
|
})
|
</script>
|