WEB/src/views/storage/entry/component/entrydetail.vue
2026-06-18 18:35:20 +08:00

258 lines
6.5 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<div class="entry-details">
<div class="header-actions">
<div class="left-actions">
<el-button size="small" @click="loadEntryDetail">刷新</el-button>
<el-button size="small" disabled>EXCEL导出</el-button>
<el-button size="small" disabled>导出</el-button>
</div>
<div class="right-actions">
<el-tag v-if="canBindReceiving" size="small" type="warning">待入库,可绑定收货明细</el-tag>
</div>
</div>
<div class="table-content">
<UpperTable
:data="tableData"
:columns="detailColumns"
:show-selection="true"
:pagination="pagination"
:loading="loading"
@selection-change="handleSelectionChange"
@page-size-change="handlePageSizeChange"
@page-change="handlePageChange"
>
<template v-if="canBindReceiving" #column-operation="{ row }">
<el-button
link
type="primary"
size="small"
:disabled="!row.stock_id"
@click="openBindDialog(row)"
>
绑定
</el-button>
</template>
<template #column-pending_total="{ row }">
<el-button
v-if="canBindReceiving && hasPendingBindings(row)"
link
type="primary"
size="small"
@click="openUnbindDialog(row)"
>
{{ row.pending_total ?? 0 }}
</el-button>
<span v-else>{{ row.pending_total ?? 0 }}</span>
</template>
</UpperTable>
</div>
<BindReceivingDetailsDialog
v-model="bindDialogVisible"
:entry-item="bindTargetItem"
@success="handleBindSuccess"
/>
<UnbindReceivingDetailsDialog
v-model="unbindDialogVisible"
:entry-item="unbindTargetItem"
:entry-order-id="props.id"
@success="handleUnbindSuccess"
/>
</div>
</template>
<script setup lang="ts">
import { computed, reactive, ref, watch, onMounted } from 'vue'
import { ElMessage } from 'element-plus'
import UpperTable from '@/components/UpperTable/index.vue'
import * as entryApi from '@/api/storage.entry/entry'
import BindReceivingDetailsDialog, {
type EntryDetailBindRow,
} from './BindReceivingDetailsDialog.vue'
import UnbindReceivingDetailsDialog from './UnbindReceivingDetailsDialog.vue'
import { entrydetail, isPendingEntryOrderStatus } from '../entry-config'
const props = defineProps<{
id?: string | number
row?: any
}>()
const tableData = ref<any[]>([])
const loading = ref(false)
const multipleSelection = ref<any[]>([])
const entryOrderStatus = ref('')
const pagination = reactive({
currentPage: 1,
pageSize: 20,
total: 0,
})
const canBindReceiving = computed(() => {
const status = props.row?.order_status ?? entryOrderStatus.value
return isPendingEntryOrderStatus(status)
})
const detailColumns = computed(() => {
const columns = [...entrydetail]
if (canBindReceiving.value) {
columns.push({
prop: 'operation',
label: '操作',
width: '90',
fixed: 'right',
align: 'center',
} as unknown as (typeof entrydetail)[number])
}
return columns
})
const emit = defineEmits(['refresh'])
const bindDialogVisible = ref(false)
const bindTargetItem = ref<EntryDetailBindRow | null>(null)
const unbindDialogVisible = ref(false)
const unbindTargetItem = ref<EntryDetailBindRow | null>(null)
watch(
() => props.id,
(newVal) => {
if (newVal) {
loadEntryDetail()
}
},
{ immediate: true }
)
async function loadEntryDetail() {
if (!props.id) return
loading.value = true
try {
const res = await entryApi.getEntryDetail({
id: Number(props.id),
})
if (res && res.code === 200 && res.data?.entryOrder) {
const entryOrder = res.data.entryOrder
entryOrderStatus.value = entryOrder.order_status || ''
const items = entryOrder.items || []
tableData.value = items.map((item: any) => ({
...item,
entry_order_code: entryOrder.entry_order_code || '',
purchase_order_code: entryOrder.purchase_order_code || '',
store_name: entryOrder.store_name || '',
}))
pagination.total = tableData.value.length
} else {
throw new Error(res?.message || '接口返回数据异常')
}
} catch (error) {
console.error('获取明细失败:', error)
ElMessage.error('获取明细失败')
tableData.value = []
pagination.total = 0
entryOrderStatus.value = ''
} finally {
loading.value = false
}
}
function openBindDialog(row: EntryDetailBindRow) {
if (!canBindReceiving.value) {
ElMessage.warning('仅待入库状态的入库单支持绑定收货明细')
return
}
if (!row?.id) {
ElMessage.warning('入库明细 ID 无效')
return
}
if (!row?.stock_id) {
ElMessage.warning('当前明细缺少 stock_id,无法查询收货单')
return
}
bindTargetItem.value = row
bindDialogVisible.value = true
}
function openUnbindDialog(row: EntryDetailBindRow) {
if (!canBindReceiving.value) {
ElMessage.warning('仅待入库状态的入库单支持解绑收货明细')
return
}
if (!row?.id) {
ElMessage.warning('入库明细 ID 无效')
return
}
if (!hasPendingBindings(row)) {
ElMessage.warning('当前明细没有可解绑的收货绑定')
return
}
unbindTargetItem.value = row
unbindDialogVisible.value = true
}
async function handleBindSuccess() {
await loadEntryDetail()
emit('refresh')
}
async function handleUnbindSuccess() {
await loadEntryDetail()
emit('refresh')
}
function hasPendingBindings(row: EntryDetailBindRow): boolean {
const pendingTotal = Number(row.pending_total)
if (Number.isFinite(pendingTotal) && pendingTotal > 0) return true
const bindings = row.bindings
return Array.isArray(bindings) && bindings.length > 0
}
const handleSelectionChange = (val: any[]) => {
multipleSelection.value = val
}
const handlePageSizeChange = (val: number) => {
pagination.pageSize = val
loadEntryDetail()
}
const handlePageChange = (val: number) => {
pagination.currentPage = val
loadEntryDetail()
}
onMounted(() => {
if (props.id) {
loadEntryDetail()
}
})
</script>
<style scoped lang="scss">
.entry-details {
display: flex;
flex-direction: column;
height: 100%;
background: #fff;
.header-actions {
display: flex;
justify-content: space-between;
align-items: center;
padding-bottom: 10px;
border-bottom: 1px solid #ebeef5;
margin-bottom: 10px;
}
.table-content {
flex: 1;
overflow: hidden;
}
}
</style>