feat: 采购申请支持整批修改重提——批次主行对有被驳回明细的批次一键载入全部被驳明细重提

This commit is contained in:
yueli
2026-09-07 17:08:37 +08:00
parent d163a36117
commit d182af7d2a

View File

@ -109,9 +109,11 @@
</span>
</template>
</el-table-column>
<el-table-column label="操作" width="220" fixed="right" align="center">
<el-table-column label="操作" width="250" fixed="right" align="center">
<template #default="{ row }">
<el-button type="info" link size="small" @click="openBatchDialog(row.batchKey)">查看整批</el-button>
<!-- 整批修改重提批次内有被驳回明细时提供 -->
<el-button v-if="batchHasRejected(row)" type="warning" link size="small" @click="handleReapplyBatch(row)">整批重提</el-button>
<!-- 一键审批本批 -->
<template v-if="row.pendingCount > 0 && canApprove">
<el-button type="success" link size="small" :loading="batchLoading" @click="handleApproveBatch(row.batchKey)">审批本批</el-button>
@ -861,35 +863,50 @@ const openCreateDialog = (prefill?: { materialId?: number; name?: string; spec?:
}
// 获取当前用户上一次采购申请的审批人作为默认值
// ★ 被驳回单"修改重提"预填原单内容到新建弹窗改后重新提交生成新单原驳回单保留
const handleReapply = (row: any) => {
dialogTitle.value = `重新申请(驳回单 ${row.request_no}`
form.value = {
approver_id: row.approver_id ?? undefined,
remark: ''
}
// ★ 被驳回单 → 构建预填行(保留物料/数量/日期/单价/税率/链接/备注/图片)
const buildFormItemFromRequest = (row: any) => {
let imgList: string[] = []
if (Array.isArray(row.images)) imgList = row.images
else if (row.images) { try { imgList = JSON.parse(row.images) } catch (e) { imgList = [] } }
const firstRow = createEmptyFormItem()
firstRow.materialBaseId = row.base_id ?? null
firstRow.name = row.name || ''
firstRow.spec_model = row.spec_model || ''
firstRow.quantity = Number(row.quantity || 1)
firstRow.purchase_date = row.purchase_date || new Date().toISOString().split('T')[0]
firstRow.unit_price = row.unit_price != null ? row.unit_price : undefined
firstRow.total_price = row.total_price != null ? row.total_price : undefined
firstRow.tax_rate = row.tax_rate ?? 0
firstRow.supplier_link = row.supplier_link || ''
firstRow.remark = row.remark || ''
firstRow.images = imgList
firstRow.fileList = imgList.map((u: string) => ({ name: (u.split('/').pop() || '图片'), url: u }))
const it = createEmptyFormItem()
it.materialBaseId = row.base_id ?? null
it.name = row.name || ''
it.spec_model = row.spec_model || ''
it.quantity = Number(row.quantity || 1)
it.purchase_date = row.purchase_date || new Date().toISOString().split('T')[0]
it.unit_price = row.unit_price != null ? row.unit_price : undefined
it.total_price = row.total_price != null ? row.total_price : undefined
it.tax_rate = row.tax_rate ?? 0
it.supplier_link = row.supplier_link || ''
it.remark = row.remark || ''
it.images = imgList
it.fileList = imgList.map((u: string) => ({ name: (u.split('/').pop() || '图片'), url: u }))
return it
}
// ★ 单条"修改重提":预填一条被驳回申请到新建弹窗
const handleReapply = (row: any) => {
dialogTitle.value = `重新申请(驳回单 ${row.request_no}`
form.value = { approver_id: row.approver_id ?? undefined, remark: '' }
materialOptions.value = row.base_id
? [{ id: row.base_id, name: row.name || '', spec_model: row.spec_model || '' }]
: []
formItems.value = [firstRow]
formItems.value = [buildFormItemFromRequest(row)]
formDialogVisible.value = true
}
// 批次内是否有被驳回的明细(主行显示"整批重提"
const batchHasRejected = (row: any) => (row.items || []).some((it: any) => it.status === 2)
// ★ 整批"修改重提"把批次内所有被驳回的明细一起载入多行弹窗改后重新提交
const handleReapplyBatch = (row: any) => {
const rejected = (row.items || []).filter((it: any) => it.status === 2)
if (!rejected.length) { ElMessage.warning('该批没有被驳回的申请'); return }
dialogTitle.value = `整批重新申请(批次 ${row.batchKey}${rejected.length} 项被驳回)`
form.value = { approver_id: rejected[0].approver_id ?? undefined, remark: '' }
materialOptions.value = []
formItems.value = rejected.map((it: any) => buildFormItemFromRequest(it))
formDialogVisible.value = true
}