248 lines
8.0 KiB
Vue
248 lines
8.0 KiB
Vue
<template>
|
||
<el-dialog v-model="visible" title="合同续签" width="800px" :close-on-click-modal="false" @close="handleClose">
|
||
<el-alert title="提示" type="info" :closable="false" class="mb-4"> 系统将自动复制原合同信息,您可以修改金额、期限等字段 </el-alert>
|
||
|
||
<el-form ref="formRef" :model="form" :rules="rules" label-position="right" label-width="120px" class="crm-dialog-form">
|
||
<el-row :gutter="20">
|
||
<el-col :span="12">
|
||
<el-form-item label="原合同" prop="parentContractId">
|
||
<el-input v-model="parentContractInfo" disabled />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-form-item label="续签次数">
|
||
<el-tag type="success">第 {{ renewalCount }} 次续签</el-tag>
|
||
</el-form-item>
|
||
</el-col>
|
||
</el-row>
|
||
|
||
<el-row :gutter="20">
|
||
<el-col :span="24">
|
||
<el-form-item label="合同名称" prop="contractName">
|
||
<el-input v-model="form.contractName" placeholder="请输入合同名称" />
|
||
</el-form-item>
|
||
</el-col>
|
||
</el-row>
|
||
|
||
<el-row :gutter="20">
|
||
<el-col :span="12">
|
||
<el-form-item label="合同金额" prop="amount">
|
||
<el-input-number
|
||
v-model="form.amount"
|
||
:precision="2"
|
||
:min="0"
|
||
:max="99999999.99"
|
||
style="width: 100%"
|
||
placeholder="请输入合同金额"
|
||
@change="calculateAmountWithTax"
|
||
/>
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-form-item label="币种" prop="currency">
|
||
<el-select v-model="form.currency" placeholder="请选择币种" style="width: 100%">
|
||
<el-option
|
||
v-for="dict in dictStore.getOptions('crm_currency')"
|
||
:key="dict.value"
|
||
:label="dict.label"
|
||
:value="dict.value"
|
||
/>
|
||
</el-select>
|
||
</el-form-item>
|
||
</el-col>
|
||
</el-row>
|
||
|
||
<el-row :gutter="20">
|
||
<el-col :span="12">
|
||
<el-form-item label="税率" prop="taxRate">
|
||
<el-select v-model="form.taxRate" placeholder="请选择税率" style="width: 100%" @change="calculateAmountWithTax">
|
||
<el-option label="0%" :value="0" />
|
||
<el-option label="6%" :value="6" />
|
||
<el-option label="9%" :value="9" />
|
||
<el-option label="13%" :value="13" />
|
||
</el-select>
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-form-item label="含税金额">
|
||
<el-input-number v-model="form.amountWithTax" :precision="2" disabled style="width: 100%" placeholder="自动计算" />
|
||
</el-form-item>
|
||
</el-col>
|
||
</el-row>
|
||
|
||
<el-row :gutter="20">
|
||
<el-col :span="12">
|
||
<el-form-item label="开始日期" prop="startDate">
|
||
<el-date-picker v-model="form.startDate" type="date" placeholder="请选择开始日期" value-format="YYYY-MM-DD" style="width: 100%" />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-form-item label="结束日期" prop="endDate">
|
||
<el-date-picker v-model="form.endDate" type="date" placeholder="请选择结束日期" value-format="YYYY-MM-DD" style="width: 100%" />
|
||
</el-form-item>
|
||
</el-col>
|
||
</el-row>
|
||
|
||
<el-row :gutter="20">
|
||
<el-col :span="12">
|
||
<el-form-item label="合同期限(月)" prop="contractPeriod">
|
||
<el-input-number v-model="form.contractPeriod" :min="1" :max="120" style="width: 100%" placeholder="请输入合同期限" />
|
||
</el-form-item>
|
||
</el-col>
|
||
</el-row>
|
||
|
||
<el-form-item label="备注" prop="remark">
|
||
<el-input v-model="form.remark" type="textarea" :rows="3" placeholder="请输入续签说明" />
|
||
</el-form-item>
|
||
</el-form>
|
||
|
||
<template #footer>
|
||
<el-button @click="handleClose">取消</el-button>
|
||
<el-button type="primary" @click="handleSubmit" :loading="submitLoading">确定续签</el-button>
|
||
</template>
|
||
</el-dialog>
|
||
</template>
|
||
|
||
<script setup lang="ts" name="RenewDialog">
|
||
import { ref } from 'vue'
|
||
import { renewContract, getContract, type ContractForm } from '@/api/crm/contract/index'
|
||
import { useDictStore } from '@/store/modules/dict'
|
||
import { $modal } from '@/utils/modal'
|
||
import type { FormInstance, FormRules } from 'element-plus'
|
||
|
||
const dictStore = useDictStore()
|
||
|
||
const visible = ref(false)
|
||
const submitLoading = ref(false)
|
||
|
||
const formRef = ref<FormInstance>()
|
||
const form = ref<ContractForm>({
|
||
contractName: '',
|
||
customerId: 0,
|
||
contractType: 'sale',
|
||
amount: 0,
|
||
currency: 'CNY',
|
||
taxRate: 6,
|
||
amountWithTax: 0,
|
||
startDate: '',
|
||
endDate: '',
|
||
contractPeriod: 12,
|
||
products: [],
|
||
remark: ''
|
||
})
|
||
|
||
const parentContractId = ref<number>(0)
|
||
const parentContractInfo = ref('')
|
||
const renewalCount = ref(1)
|
||
|
||
const rules = ref<FormRules>({
|
||
contractName: [{ required: true, message: '请输入合同名称', trigger: 'blur' }],
|
||
amount: [{ required: true, message: '请输入合同金额', trigger: 'blur' }],
|
||
startDate: [{ required: true, message: '请选择开始日期', trigger: 'change' }],
|
||
endDate: [{ required: true, message: '请选择结束日期', trigger: 'change' }]
|
||
})
|
||
|
||
const emit = defineEmits(['success'])
|
||
|
||
const open = async (contractId: number) => {
|
||
reset()
|
||
parentContractId.value = contractId
|
||
|
||
try {
|
||
const res = await getContract(contractId)
|
||
const contract = res.data
|
||
|
||
parentContractInfo.value = `${contract.contractNo} - ${contract.contractName}`
|
||
renewalCount.value = (contract.renewalCount || 0) + 1
|
||
|
||
form.value.contractName = contract.contractName + `-续签${renewalCount.value}`
|
||
form.value.customerId = contract.customerId
|
||
form.value.contractType = contract.contractType
|
||
form.value.amount = contract.amount
|
||
form.value.currency = contract.currency || 'CNY'
|
||
form.value.taxRate = contract.taxRate || 6
|
||
form.value.amountWithTax = contract.amountWithTax
|
||
form.value.contractPeriod = contract.contractPeriod || 12
|
||
|
||
if (contract.endDate) {
|
||
const endDate = new Date(contract.endDate)
|
||
endDate.setDate(endDate.getDate() + 1)
|
||
form.value.startDate = formatDate(endDate)
|
||
|
||
const newEndDate = new Date(endDate)
|
||
newEndDate.setMonth(newEndDate.getMonth() + (form.value.contractPeriod || 12))
|
||
form.value.endDate = formatDate(newEndDate)
|
||
}
|
||
|
||
visible.value = true
|
||
} catch (error) {
|
||
console.error('加载原合同信息失败:', error)
|
||
$modal.msgError('加载原合同信息失败')
|
||
}
|
||
}
|
||
|
||
const handleSubmit = () => {
|
||
formRef.value?.validate(async (valid) => {
|
||
if (valid) {
|
||
submitLoading.value = true
|
||
try {
|
||
const res = await renewContract(parentContractId.value, form.value)
|
||
$modal.msgSuccess('续签成功')
|
||
visible.value = false
|
||
emit('success', res)
|
||
} catch (error) {
|
||
console.error('续签失败:', error)
|
||
} finally {
|
||
submitLoading.value = false
|
||
}
|
||
}
|
||
})
|
||
}
|
||
|
||
const handleClose = () => {
|
||
visible.value = false
|
||
reset()
|
||
}
|
||
|
||
const reset = () => {
|
||
form.value = {
|
||
contractName: '',
|
||
customerId: 0,
|
||
contractType: 'sale',
|
||
amount: 0,
|
||
currency: 'CNY',
|
||
taxRate: 6,
|
||
amountWithTax: 0,
|
||
startDate: '',
|
||
endDate: '',
|
||
contractPeriod: 12,
|
||
products: [],
|
||
remark: ''
|
||
}
|
||
formRef.value?.resetFields()
|
||
}
|
||
|
||
const calculateAmountWithTax = () => {
|
||
if (form.value.amount && form.value.taxRate !== undefined) {
|
||
form.value.amountWithTax = form.value.amount * (1 + form.value.taxRate / 100)
|
||
} else if (form.value.amount) {
|
||
form.value.amountWithTax = form.value.amount
|
||
}
|
||
}
|
||
|
||
const formatDate = (date: Date): string => {
|
||
const year = date.getFullYear()
|
||
const month = String(date.getMonth() + 1).padStart(2, '0')
|
||
const day = String(date.getDate()).padStart(2, '0')
|
||
return `${year}-${month}-${day}`
|
||
}
|
||
|
||
defineExpose({ open })
|
||
</script>
|
||
|
||
<style scoped lang="scss">
|
||
.mb-4 {
|
||
margin-bottom: 16px;
|
||
}
|
||
</style>
|