提交
This commit is contained in:
1 parent
06956b742b
commit
e59b2aa6cb
104 files changed
+653227
-7621
No files matched your search
@@ -10,6 +10,22 @@
|
||||
modal-class="order-module-dialog-mask"
|
||||
:close-on-click-modal="false"
|
||||
>
|
||||
<el-alert
|
||||
v-if="isBatchMode && batchCount > 0"
|
||||
type="success"
|
||||
:closable="false"
|
||||
show-icon
|
||||
class="batch-action-alert batch-action-alert--success"
|
||||
:title="batchInfoTitle"
|
||||
/>
|
||||
<el-alert
|
||||
v-if="skippedCount > 0"
|
||||
type="error"
|
||||
:closable="false"
|
||||
show-icon
|
||||
class="batch-action-alert batch-action-alert--danger"
|
||||
:title="`已跳过 ${skippedCount} 条不可处理的合同`"
|
||||
/>
|
||||
<el-form
|
||||
ref="formRef"
|
||||
:model="form"
|
||||
@@ -35,14 +51,6 @@
|
||||
<template #label>
|
||||
选择审批人<span class="form-label-tip">支持搜索用户姓名</span>
|
||||
</template>
|
||||
<el-alert
|
||||
v-if="submitPrefillTip"
|
||||
type="success"
|
||||
:closable="false"
|
||||
show-icon
|
||||
title="已按「合同审批人设置」预填审批人,可修改后提交"
|
||||
style="margin-bottom: 12px"
|
||||
/>
|
||||
<el-select
|
||||
v-model="form.approverIds"
|
||||
multiple
|
||||
@@ -158,6 +166,7 @@ const dialogVisible = ref(false)
|
||||
const actionType = ref<'submit' | 'approve' | 'reject' | 'withdraw'>('submit')
|
||||
const contractId = ref<string | number>()
|
||||
const contractIds = ref<(string | number)[]>()
|
||||
const skippedCount = ref(0)
|
||||
|
||||
const form = ref({
|
||||
approvalType: 'sequential',
|
||||
@@ -170,9 +179,11 @@ const form = ref({
|
||||
const approverList = ref<ApproverUser[]>([])
|
||||
const submitLoading = ref(false)
|
||||
const userLoading = ref(false)
|
||||
const submitPrefillTip = ref(false)
|
||||
const formRef = ref<ElFormInstance>()
|
||||
|
||||
const isBatchMode = computed(() => !!(contractIds.value && contractIds.value.length > 0))
|
||||
const batchCount = computed(() => contractIds.value?.length || 0)
|
||||
|
||||
const rules = computed(() => {
|
||||
const baseRules: any = {}
|
||||
if (actionType.value === 'submit') {
|
||||
@@ -195,12 +206,25 @@ const dialogTitle = computed(() => {
|
||||
withdraw: '撤回审批'
|
||||
}
|
||||
let title = titleMap[actionType.value]
|
||||
if (contractIds.value && contractIds.value.length > 0) {
|
||||
title += `(${contractIds.value.length}条)`
|
||||
if (isBatchMode.value) {
|
||||
title += `(${batchCount.value}条)`
|
||||
}
|
||||
return title
|
||||
})
|
||||
|
||||
const batchInfoTitle = computed(() => {
|
||||
if (actionType.value === 'submit') {
|
||||
return `将提交 ${batchCount.value} 条草稿合同(使用同一组审批人与说明)`
|
||||
}
|
||||
if (actionType.value === 'approve') {
|
||||
return `将审批通过 ${batchCount.value} 条合同(使用同一审批意见)`
|
||||
}
|
||||
if (actionType.value === 'reject') {
|
||||
return `将审批驳回 ${batchCount.value} 条合同(使用同一审批意见)`
|
||||
}
|
||||
return `将处理 ${batchCount.value} 条合同`
|
||||
})
|
||||
|
||||
const confirmButtonText = computed(() => {
|
||||
const textMap = {
|
||||
submit: '提交',
|
||||
@@ -214,6 +238,7 @@ const confirmButtonText = computed(() => {
|
||||
const open = async (id: string | number, type: 'submit' | 'approve' | 'reject' | 'withdraw' = 'submit') => {
|
||||
contractId.value = id
|
||||
contractIds.value = undefined
|
||||
skippedCount.value = 0
|
||||
actionType.value = type
|
||||
dialogVisible.value = true
|
||||
resetForm()
|
||||
@@ -225,10 +250,12 @@ const open = async (id: string | number, type: 'submit' | 'approve' | 'reject' |
|
||||
|
||||
const openBatch = async (
|
||||
idList: (string | number)[],
|
||||
type: 'submit' | 'approve' | 'reject' | 'withdraw' = 'submit'
|
||||
type: 'submit' | 'approve' | 'reject' | 'withdraw' = 'submit',
|
||||
options?: { skippedCount?: number }
|
||||
) => {
|
||||
contractIds.value = idList
|
||||
contractId.value = undefined
|
||||
skippedCount.value = options?.skippedCount || 0
|
||||
actionType.value = type
|
||||
dialogVisible.value = true
|
||||
resetForm()
|
||||
@@ -238,6 +265,33 @@ const openBatch = async (
|
||||
}
|
||||
}
|
||||
|
||||
const showBatchResultMessage = (options: {
|
||||
actionLabel: string
|
||||
successCount: number
|
||||
failedCount: number
|
||||
skippedCount?: number
|
||||
}) => {
|
||||
const { actionLabel, successCount, failedCount, skippedCount: skip = 0 } = options
|
||||
const skipText = skip > 0 ? `,跳过 ${skip} 条` : ''
|
||||
if (successCount === 0 && failedCount === 0) {
|
||||
$modal.msgWarning(`没有可${actionLabel}的合同${skipText}`)
|
||||
return
|
||||
}
|
||||
if (successCount === 0) {
|
||||
$modal.msgError(`${actionLabel}失败${skipText}`)
|
||||
return
|
||||
}
|
||||
if (failedCount > 0) {
|
||||
$modal.msgWarning(`成功${actionLabel} ${successCount} 条,失败 ${failedCount} 条${skipText}`)
|
||||
return
|
||||
}
|
||||
if (successCount === 1 && skip === 0) {
|
||||
$modal.msgSuccess(`${actionLabel}成功`)
|
||||
return
|
||||
}
|
||||
$modal.msgSuccess(`成功${actionLabel} ${successCount} 条${skipText}`)
|
||||
}
|
||||
|
||||
const loadApproverList = async (nickName?: string) => {
|
||||
userLoading.value = true
|
||||
try {
|
||||
@@ -278,9 +332,7 @@ async function resolvePrefillApproverIds(userList: ApproverUser[]) {
|
||||
}
|
||||
|
||||
async function applyPrefillApprovers() {
|
||||
const prefillIds = await resolvePrefillApproverIds(approverList.value)
|
||||
form.value.approverIds = prefillIds
|
||||
submitPrefillTip.value = prefillIds.length > 0
|
||||
form.value.approverIds = await resolvePrefillApproverIds(approverList.value)
|
||||
}
|
||||
|
||||
const handleSearchUser = (query: string) => {
|
||||
@@ -298,34 +350,73 @@ const getApproverName = (approverId: string | number): string => {
|
||||
|
||||
const handleConfirm = async () => {
|
||||
await formRef.value?.validate()
|
||||
const isBatch = !!(contractIds.value && contractIds.value.length > 0)
|
||||
const isBatch = isBatchMode.value
|
||||
if (!isBatch && (contractId.value == null || contractId.value === '')) {
|
||||
$modal.msgError('合同 ID 缺失,请关闭后重新打开提交审批')
|
||||
$modal.msgError('合同 ID 缺失,请关闭后重新打开')
|
||||
return
|
||||
}
|
||||
submitLoading.value = true
|
||||
try {
|
||||
let shouldClose = true
|
||||
|
||||
if (actionType.value === 'submit') {
|
||||
if (isBatch) {
|
||||
const count = await batchSubmitContract(contractIds.value!, form.value.approverIds, form.value.remark)
|
||||
$modal.msgSuccess(`提交成功,成功 ${count ?? contractIds.value!.length} 条`)
|
||||
showBatchResultMessage({
|
||||
actionLabel: '提交',
|
||||
successCount: count ?? contractIds.value!.length,
|
||||
failedCount: 0,
|
||||
skippedCount: skippedCount.value
|
||||
})
|
||||
} else {
|
||||
await submitContract(contractId.value!, form.value.approverIds, form.value.remark)
|
||||
$modal.msgSuccess('提交成功')
|
||||
}
|
||||
} else if (actionType.value === 'approve') {
|
||||
await approveContract(contractId.value!, form.value.comment)
|
||||
$modal.msgSuccess('审批通过')
|
||||
if (isBatch) {
|
||||
const results = await Promise.allSettled(
|
||||
contractIds.value!.map((id) => approveContract(id, form.value.comment))
|
||||
)
|
||||
const successCount = results.filter((item) => item.status === 'fulfilled').length
|
||||
const failedCount = results.length - successCount
|
||||
showBatchResultMessage({
|
||||
actionLabel: '审批通过',
|
||||
successCount,
|
||||
failedCount,
|
||||
skippedCount: skippedCount.value
|
||||
})
|
||||
shouldClose = successCount > 0
|
||||
} else {
|
||||
await approveContract(contractId.value!, form.value.comment)
|
||||
$modal.msgSuccess('审批通过')
|
||||
}
|
||||
} else if (actionType.value === 'reject') {
|
||||
await rejectContract(contractId.value!, form.value.comment)
|
||||
$modal.msgSuccess('已驳回')
|
||||
if (isBatch) {
|
||||
const results = await Promise.allSettled(
|
||||
contractIds.value!.map((id) => rejectContract(id, form.value.comment))
|
||||
)
|
||||
const successCount = results.filter((item) => item.status === 'fulfilled').length
|
||||
const failedCount = results.length - successCount
|
||||
showBatchResultMessage({
|
||||
actionLabel: '审批驳回',
|
||||
successCount,
|
||||
failedCount,
|
||||
skippedCount: skippedCount.value
|
||||
})
|
||||
shouldClose = successCount > 0
|
||||
} else {
|
||||
await rejectContract(contractId.value!, form.value.comment)
|
||||
$modal.msgSuccess('已驳回')
|
||||
}
|
||||
} else if (actionType.value === 'withdraw') {
|
||||
await withdrawContract(contractId.value!, form.value.reason)
|
||||
$modal.msgSuccess('已撤回')
|
||||
}
|
||||
|
||||
dialogVisible.value = false
|
||||
emit('success')
|
||||
if (shouldClose) {
|
||||
dialogVisible.value = false
|
||||
emit('success')
|
||||
}
|
||||
} finally {
|
||||
submitLoading.value = false
|
||||
}
|
||||
@@ -350,7 +441,6 @@ const resetForm = () => {
|
||||
remark: '',
|
||||
reason: ''
|
||||
}
|
||||
submitPrefillTip.value = false
|
||||
formRef.value?.clearValidate()
|
||||
}
|
||||
|
||||
@@ -361,6 +451,24 @@ defineExpose({
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.batch-action-alert {
|
||||
margin-bottom: 12px;
|
||||
|
||||
&--success {
|
||||
:deep(.el-alert__title),
|
||||
:deep(.el-alert__icon) {
|
||||
color: var(--primary, #10b981);
|
||||
}
|
||||
}
|
||||
|
||||
&--danger {
|
||||
:deep(.el-alert__title),
|
||||
:deep(.el-alert__icon) {
|
||||
color: #ef4444;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.form-tip-block {
|
||||
display: block;
|
||||
margin-top: 6px;
|
||||
|
||||
Reference in new issue
Block a user