189 lines
5.2 KiB
Vue
189 lines
5.2 KiB
Vue
<template>
|
||
<el-dialog
|
||
v-model="dialogVisible"
|
||
title="作废合同"
|
||
width="640px"
|
||
align-center
|
||
append-to-body
|
||
destroy-on-close
|
||
class="dialog-form-layout"
|
||
modal-class="order-module-dialog-mask"
|
||
:close-on-click-modal="false"
|
||
>
|
||
<el-alert type="warning" :closable="false" class="invalid-alert">
|
||
<template #default>
|
||
<div><strong>注意:</strong>合同作废后将无法恢复,请谨慎操作!</div>
|
||
<div>作废的合同不会统计到业绩中,但历史记录仍会保留。</div>
|
||
</template>
|
||
</el-alert>
|
||
|
||
<el-form
|
||
ref="formRef"
|
||
:model="form"
|
||
:rules="rules"
|
||
label-position="top"
|
||
scroll-to-error
|
||
:scroll-into-view-options="{ behavior: 'smooth', block: 'center' }"
|
||
>
|
||
<div class="form-grid-2">
|
||
<el-form-item label="作废原因" prop="invalidReason" class="form-col-span-2">
|
||
<el-select
|
||
v-model="form.invalidReason"
|
||
placeholder="请选择作废原因"
|
||
style="width: 100%"
|
||
@change="handleReasonChange"
|
||
>
|
||
<el-option
|
||
v-for="dict in dictStore.getOptions('crm_invalid_reason')"
|
||
:key="dict.value"
|
||
:label="dict.label"
|
||
:value="dict.value"
|
||
/>
|
||
</el-select>
|
||
</el-form-item>
|
||
|
||
<el-form-item label="详细说明" prop="invalidRemark" class="form-col-span-2">
|
||
<el-input
|
||
v-model="form.invalidRemark"
|
||
type="textarea"
|
||
:rows="6"
|
||
placeholder="请详细说明作废原因,此信息将记录在合同历史中"
|
||
maxlength="1000"
|
||
show-word-limit
|
||
/>
|
||
</el-form-item>
|
||
</div>
|
||
</el-form>
|
||
|
||
<el-alert v-if="hasPaymentOrInvoice" type="error" :closable="false" class="invalid-alert">
|
||
<template #default>
|
||
<div><strong>风险提示:</strong></div>
|
||
<div v-if="paymentAmount > 0">该合同已有回款记录,金额:¥{{ formatAmount(paymentAmount) }}</div>
|
||
<div v-if="invoiceAmount > 0">该合同已有开票记录,金额:¥{{ formatAmount(invoiceAmount) }}</div>
|
||
<div>作废后请及时处理相关财务数据。</div>
|
||
</template>
|
||
</el-alert>
|
||
|
||
<template #footer>
|
||
<div class="invalid-dialog-actions">
|
||
<el-button @click="handleClose">
|
||
<el-icon><Close /></el-icon>取消
|
||
</el-button>
|
||
<el-button type="danger" :loading="submitLoading" @click="handleConfirm">
|
||
<el-icon><Delete /></el-icon>确认作废
|
||
</el-button>
|
||
</div>
|
||
</template>
|
||
</el-dialog>
|
||
</template>
|
||
|
||
<script setup lang="ts" name="InvalidDialog">
|
||
import { ref, computed } from 'vue'
|
||
import { Close, Delete } from '@element-plus/icons-vue'
|
||
import { invalidContract, getContract } from '@/api/crm/contract'
|
||
import { useDictStore } from '@/store/modules/dict'
|
||
import { $modal } from '@/utils/modal'
|
||
|
||
const dictStore = useDictStore()
|
||
const emit = defineEmits(['success'])
|
||
|
||
const dialogVisible = ref(false)
|
||
const contractId = ref<number>()
|
||
|
||
const form = ref({
|
||
invalidReason: '',
|
||
invalidRemark: ''
|
||
})
|
||
|
||
const paymentAmount = ref(0)
|
||
const invoiceAmount = ref(0)
|
||
const submitLoading = ref(false)
|
||
const formRef = ref<ElFormInstance>()
|
||
|
||
const rules = ref({
|
||
invalidReason: [{ required: true, message: '请选择作废原因', trigger: 'change' }],
|
||
invalidRemark: [{ required: true, message: '请输入详细说明', trigger: 'blur' }]
|
||
})
|
||
|
||
const hasPaymentOrInvoice = computed(() => paymentAmount.value > 0 || invoiceAmount.value > 0)
|
||
|
||
const open = async (id: number) => {
|
||
contractId.value = id
|
||
dialogVisible.value = true
|
||
resetForm()
|
||
await loadContractInfo()
|
||
}
|
||
|
||
const loadContractInfo = async () => {
|
||
try {
|
||
const res = await getContract(contractId.value!)
|
||
paymentAmount.value = res.data.receivedAmount || 0
|
||
invoiceAmount.value = res.data.invoiceAmount || 0
|
||
} catch (error) {
|
||
console.error('获取合同信息失败:', error)
|
||
}
|
||
}
|
||
|
||
const handleReasonChange = (value: string) => {
|
||
if (value === 'other') {
|
||
form.value.invalidRemark = ''
|
||
}
|
||
}
|
||
|
||
const handleConfirm = async () => {
|
||
await formRef.value?.validate()
|
||
await $modal.confirm('确认要作废此合同吗?此操作不可恢复!')
|
||
|
||
submitLoading.value = true
|
||
try {
|
||
await invalidContract({
|
||
id: contractId.value!,
|
||
invalidReason: form.value.invalidReason,
|
||
remark: form.value.invalidRemark
|
||
})
|
||
$modal.msgSuccess('合同已作废')
|
||
dialogVisible.value = false
|
||
emit('success')
|
||
} finally {
|
||
submitLoading.value = false
|
||
}
|
||
}
|
||
|
||
const handleClose = () => {
|
||
dialogVisible.value = false
|
||
resetForm()
|
||
}
|
||
|
||
const resetForm = () => {
|
||
form.value = {
|
||
invalidReason: '',
|
||
invalidRemark: ''
|
||
}
|
||
paymentAmount.value = 0
|
||
invoiceAmount.value = 0
|
||
formRef.value?.clearValidate()
|
||
}
|
||
|
||
const formatAmount = (amount: number): string => {
|
||
return (amount || 0).toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 })
|
||
}
|
||
|
||
defineExpose({
|
||
open
|
||
})
|
||
</script>
|
||
|
||
<style scoped lang="scss">
|
||
.invalid-alert {
|
||
margin-bottom: 16px;
|
||
}
|
||
|
||
.invalid-dialog-actions {
|
||
display: flex;
|
||
flex-wrap: wrap;
|
||
gap: 4px 16px;
|
||
justify-content: flex-end;
|
||
width: 100%;
|
||
}
|
||
</style>
|