495 lines
16 KiB
Vue
495 lines
16 KiB
Vue
<template>
|
||
<ContentWrap class="mt-10px">
|
||
<el-form
|
||
ref="formRef"
|
||
v-loading="formLoading"
|
||
:model="formData"
|
||
:rules="formRules"
|
||
label-width="120px"
|
||
>
|
||
<el-row>
|
||
<!-- <el-col :span="8">
|
||
<el-form-item label="合同查询" prop="quotationId">
|
||
<el-select
|
||
@change="handleQuotationChange"
|
||
v-model="formData.quotationId"
|
||
class="w-1/1"
|
||
>
|
||
<el-option
|
||
v-for="item in quotationList"
|
||
:key="item.id"
|
||
:label="item.no"
|
||
:value="item.id"
|
||
/>
|
||
</el-select>
|
||
</el-form-item>
|
||
</el-col> -->
|
||
<el-col :span="8">
|
||
<el-form-item label="客户名称" prop="customerId">
|
||
<el-select
|
||
v-model="formData.customerId"
|
||
placeholder="请选择客户"
|
||
disabled
|
||
class="w-1/1"
|
||
>
|
||
<el-option
|
||
v-for="item in contactList"
|
||
:key="item.id"
|
||
:label="item.name"
|
||
:value="item.id"
|
||
/>
|
||
</el-select>
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="8">
|
||
<el-form-item label="协议编码" prop="name">
|
||
<el-input v-model="formData.processInstanceId" disabled placeholder="协议编码" />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="8">
|
||
<el-form-item label="合同状态" prop="quotationId">
|
||
<el-select v-model="formData.auditStatus" disabled clearable placeholder="请选择合同状态">
|
||
<el-option
|
||
v-for="dict in getIntDictOptions(DICT_TYPE.CRM_AUDIT_STATUS)"
|
||
:key="dict.value"
|
||
:label="dict.label"
|
||
:value="dict.value"
|
||
/>
|
||
</el-select>
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="8">
|
||
<el-form-item label="协议截止日期" prop="endTime">
|
||
<el-date-picker
|
||
v-model="formData.endTime"
|
||
disabled
|
||
type="date"
|
||
value-format="x"
|
||
placeholder="请选择协议截止日期"
|
||
style="width: 100%"
|
||
/>
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="24">
|
||
<el-form-item label="变更项目" prop="endTime">
|
||
<el-radio-group v-model="formData.changeItem" disabled >
|
||
<el-radio :value="1">额度</el-radio>
|
||
<el-radio :value="2">授权人</el-radio>
|
||
<el-radio :value="3">延期</el-radio>
|
||
<el-radio :value="4">终止</el-radio>
|
||
<el-radio :value="5">关联</el-radio>
|
||
<el-radio :value="6">重签</el-radio>
|
||
</el-radio-group>
|
||
</el-form-item>
|
||
</el-col>
|
||
</el-row>
|
||
|
||
<!-- 子表的表单 -->
|
||
<ContentWrap>
|
||
<ContractChangeLimit
|
||
v-if="formData.changeItem == 1"
|
||
ref="limitFormRef"
|
||
:data="formData"
|
||
:disabled="true"
|
||
/>
|
||
<div v-if="formData.changeItem == 2">
|
||
<ContentWrap style="border: none">
|
||
甲方现授权人信息
|
||
</ContentWrap>
|
||
<ContractAuthPersonInfo
|
||
:disabled="true"
|
||
|
||
ref="personDataRef"
|
||
:products="formData.contractAAuthorizedPersons"
|
||
/>
|
||
|
||
</div>
|
||
<ContracExtension ref="contractExtensionFormRef" v-if="formData.changeItem == 3" :disabled="true" :data="formData" />
|
||
<ContractStop ref="contractStopFormRef" :formData="formData" :disabled="true" v-if="formData.changeItem == 4" />
|
||
<ContractAAuthorizedCompanyForm ref="contractAAuthorizedCompanyFormRef1" :type="true" v-if="formData.changeItem == 5" :data="formData.contractAAuthorizedCompanys" />
|
||
<ContractForm ref="contractFormRef" :type="1" :id="formData.id" v-if="formData.changeItem == 6" />
|
||
</ContentWrap>
|
||
</el-form>
|
||
|
||
</ContentWrap>
|
||
</template>
|
||
<script lang="ts" setup>
|
||
import { getIntDictOptions, DICT_TYPE } from '@/utils/dict'
|
||
import * as CustomerApi from '@/api/crm/customer'
|
||
import * as ContractApi from '@/api/crm/contract'
|
||
import * as ContactApi from '@/api/crm/contact'
|
||
import * as UserApi from '@/api/system/user'
|
||
import { QuotationApi,QuotationVO } from '@/api/crm/quotation'
|
||
import { erpPriceMultiply, erpPriceInputFormatter, jsonParse } from '@/utils'
|
||
import { useUserStore } from '@/store/modules/user'
|
||
import ContractChangeLimit from '@/views/crm/contract/components/ContractChangeLimit.vue'
|
||
import ContractAuthPersonInfo from '@/views/crm/contract/components/ContractAuthPersonInfo.vue'
|
||
import ContracExtension from '@/views/crm/contract/components/ContractExtension.vue'
|
||
import ContractStop from '@/views/crm/contract/components/ContracStop.vue'
|
||
import ContractProductForm from '@/views/crm/contract/components/ContractProductForm.vue'
|
||
import ContractAAuthorizedCompanyForm from '../components/ContractAAuthorizedCompanyForm.vue'
|
||
import ContractBAuthorizedPersonForm from '../components/ContractAAuthorizedPersonForm.vue'
|
||
import ContractForm from './ContractDetail.vue'
|
||
import { propTypes } from '@/utils/propTypes'
|
||
|
||
const { t } = useI18n() // 国际化
|
||
const message = useMessage() // 消息弹窗
|
||
const { proxy }: any = getCurrentInstance();
|
||
const props = defineProps({
|
||
id: propTypes.number.def(undefined),
|
||
})
|
||
const dialogVisible = ref(false) // 弹窗的是否展示
|
||
const dialogTitle = ref('') // 弹窗的标题
|
||
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
|
||
const formType = ref('') // 表单的类型:create - 新增;update - 修改
|
||
const formData = ref({
|
||
authPerson: [],
|
||
id: undefined,
|
||
name: undefined,
|
||
no: undefined,
|
||
customerId: undefined,
|
||
quotationId: undefined,
|
||
invoiceTemplateId: undefined,
|
||
processInstanceId: undefined,
|
||
auditStatus: undefined,
|
||
startTime: undefined,
|
||
endTime: undefined,
|
||
penaltyRate: undefined,
|
||
latePaymentRate: undefined,
|
||
settleMethod: undefined,
|
||
lastPayDate: undefined,
|
||
contractTerm: undefined,
|
||
signUserId: undefined,
|
||
signPhoneNumber: undefined,
|
||
signEmail: undefined,
|
||
signWechat: undefined,
|
||
offlinePrice: undefined,
|
||
onlinePrice: undefined,
|
||
ownerUserId: undefined,
|
||
expanderUserId: undefined,
|
||
pricingUserId: undefined,
|
||
afterSaleUserId: undefined,
|
||
collUserId: undefined,
|
||
totalPrice: undefined,
|
||
contractBody: undefined,
|
||
contractAgreement: undefined,
|
||
creditMethod: undefined,
|
||
creditCalcCycle: undefined,
|
||
creditLimit: undefined,
|
||
partnerCompanyId: undefined,
|
||
deptId: undefined,
|
||
quotationTimes: undefined,
|
||
changeItem: 1,
|
||
products: []
|
||
})
|
||
const formRules = reactive({
|
||
name: [{ required: true, message: '合同名称不能为空', trigger: 'blur' }],
|
||
customerId: [{ required: true, message: '客户不能为空', trigger: 'blur' }],
|
||
orderDate: [{ required: true, message: '下单日期不能为空', trigger: 'blur' }],
|
||
ownerUserId: [{ required: true, message: '负责人不能为空', trigger: 'blur' }]
|
||
})
|
||
const formRef = ref() // 表单 Ref
|
||
const userOptions = ref<UserApi.UserVO[]>([]) // 用户列表
|
||
const customerList = ref([]) // 客户列表的数据
|
||
const quotationList = ref<QuotationVO[]>([])
|
||
const contactList = ref<ContactApi.ContactVO[]>([])
|
||
|
||
/** 子表的表单 */
|
||
const subTabsName = ref('limit')
|
||
const ContractBAuthorizedPersonFormRef = ref()
|
||
const contractAAuthorizedCompanyFormRef1 = ref()
|
||
const limitFormRef = ref()
|
||
const contractExtensionFormRef = ref()
|
||
const contractStopFormRef = ref()
|
||
const contractFormRef = ref()
|
||
|
||
/** 计算 discountPrice、totalPrice 价格 */
|
||
watch(
|
||
() => formData.value,
|
||
(val) => {
|
||
if (!val) {
|
||
return
|
||
}
|
||
// const totalPrice = val.products.reduce((prev, curr) => prev + curr.totalPrice, 0)
|
||
// 赋值
|
||
// formData.value.totalPrice = totalPrice
|
||
},
|
||
{ deep: true }
|
||
)
|
||
|
||
/** 打开弹窗 */
|
||
const open = async (type: string) => {
|
||
if (type) {
|
||
formLoading.value = true
|
||
try {
|
||
// formData.value = Object.assign(formData.value, data)
|
||
let data = await ContractApi.getChangeContract(type)
|
||
formData.value = data.contractDetail
|
||
formData.value.changeItem = data.changeItem
|
||
formData.value.changeAmount = data.changeAmount
|
||
formData.value.afterAmount = data.afterAmount
|
||
formData.value.changeAmountDeadline = data.changeAmountDeadline
|
||
formData.value.note = data.note
|
||
} finally {
|
||
formLoading.value = false
|
||
}
|
||
}
|
||
|
||
}
|
||
defineExpose({ open }) // 提供 open 方法,用于打开弹窗
|
||
|
||
/** 提交表单 */
|
||
const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
|
||
const submitForm = async () => {
|
||
// 校验表单
|
||
if (!formRef) return
|
||
const valid = await formRef.value.validate()
|
||
if (!valid) return
|
||
|
||
// const Authalid = await contractAAuthorizedCompanyFormRef.value.validate()
|
||
// if (!Authalid) return
|
||
|
||
// const Authalid1 = await contractAAuthorizedCompanyFormRef1.value.validate()
|
||
// if (!Authalid1) return
|
||
|
||
if(ContractBAuthorizedPersonFormRef.value) {
|
||
const Authalid = await ContractBAuthorizedPersonFormRef.value.validate()
|
||
if (!Authalid) return
|
||
}
|
||
|
||
if(contractAAuthorizedCompanyFormRef1.value) {
|
||
const Authalid1 = await contractAAuthorizedCompanyFormRef1.value.validate()
|
||
if (!Authalid1) return
|
||
}
|
||
|
||
if(limitFormRef.value) {
|
||
const limitValid = await limitFormRef.value.validate()
|
||
if (!limitValid) return
|
||
}
|
||
|
||
if(contractExtensionFormRef.value) {
|
||
const extensionValid = await contractExtensionFormRef.value.validate()
|
||
if (!extensionValid) return
|
||
|
||
}
|
||
|
||
if(contractStopFormRef.value) {
|
||
const stopValid = await contractStopFormRef.value.validate()
|
||
if (!stopValid) return
|
||
|
||
}
|
||
|
||
if(contractFormRef.value) {
|
||
const contractValid = await contractFormRef.value.validate()
|
||
if (!contractValid) return
|
||
|
||
}
|
||
|
||
|
||
// const stopValid = await contractStopFormRef.value.validate()
|
||
// if (!stopValid) return
|
||
|
||
// const contractValid = await contractFormRef.value.validate()
|
||
// if (!contractValid) return
|
||
|
||
|
||
|
||
// 提交请求
|
||
formLoading.value = true
|
||
try {
|
||
const data = unref(JSON.parse(JSON.stringify(formData.value))) as unknown as ContractApi.ContractVO
|
||
// 拼接子表的数据
|
||
let proChangeObj = {
|
||
1: limitFormRef,
|
||
2: ContractBAuthorizedPersonFormRef,
|
||
3: contractExtensionFormRef,
|
||
4: contractStopFormRef,
|
||
5: contractAAuthorizedCompanyFormRef1,
|
||
6: contractFormRef
|
||
}
|
||
let dataFormList = proChangeObj[formData.value.changeItem].value.getData()
|
||
data[proChangeObj[formData.value.changeItem]] = dataFormList
|
||
if(formData.value.changeItem == 1) {
|
||
data.changeAmount = dataFormList.changeAmount
|
||
data.changeAmountDeadline = dataFormList.changeAmountDeadline
|
||
} else if(formData.value.changeItem == 2) {
|
||
let ids = []
|
||
dataFormList.map(item => {
|
||
ids.push(item.id)
|
||
})
|
||
data.afterAuthorizerId = ids.join(',')
|
||
} else if(formData.value.changeItem == 3) {
|
||
data.agreementDeadline = dataFormList.agreementDeadline
|
||
data.extensionYears = dataFormList.extensionYears
|
||
data.extensionDate = dataFormList.extensionDate
|
||
data.note = dataFormList.note
|
||
} else if(formData.value.changeItem == 4) {
|
||
data.terminationDate = dataFormList.terminationDate
|
||
data.terminationReason = dataFormList.terminationReason
|
||
data.note = dataFormList.note
|
||
} else if(formData.value.changeItem == 5) {
|
||
let ids = []
|
||
dataFormList.map(item => {
|
||
ids.push(item.id)
|
||
})
|
||
data.afterAffiliateCompanyId = ids.join(',')
|
||
} else if(formData.value.changeItem == 6) {
|
||
data.newContract = data
|
||
}
|
||
data.contractId = data.id
|
||
delete data.id
|
||
await ContractApi.changeContract(data)
|
||
message.success(t('common.createSuccess'))
|
||
|
||
dialogVisible.value = false
|
||
// 发送操作成功的事件
|
||
emit('success')
|
||
goBack()
|
||
} finally {
|
||
formLoading.value = false
|
||
}
|
||
}
|
||
|
||
const goBack = ()=> {
|
||
proxy.$router.go(-1)
|
||
}
|
||
|
||
/** 重置表单 */
|
||
const resetForm = () => {
|
||
formData.value = {
|
||
id: undefined,
|
||
name: undefined,
|
||
no: undefined,
|
||
customerId: undefined,
|
||
quotationId: undefined,
|
||
invoiceTemplateId: undefined,
|
||
processInstanceId: undefined,
|
||
auditStatus: undefined,
|
||
startTime: undefined,
|
||
endTime: undefined,
|
||
penaltyRate: undefined,
|
||
latePaymentRate: undefined,
|
||
settleMethod: undefined,
|
||
lastPayDate: undefined,
|
||
contractTerm: undefined,
|
||
signUserId: undefined,
|
||
signPhoneNumber: undefined,
|
||
signEmail: undefined,
|
||
signWechat: undefined,
|
||
offlinePrice: undefined,
|
||
onlinePrice: undefined,
|
||
ownerUserId: undefined,
|
||
expanderUserId: undefined,
|
||
pricingUserId: undefined,
|
||
afterSaleUserId: undefined,
|
||
collUserId: undefined,
|
||
totalPrice: undefined,
|
||
contractBody: undefined,
|
||
contractAgreement: undefined,
|
||
creditMethod: undefined,
|
||
creditCalcCycle: undefined,
|
||
creditLimit: undefined,
|
||
partnerCompanyId: undefined,
|
||
deptId: undefined,
|
||
quotationTimes: undefined,
|
||
changeItem: 1,
|
||
products: []
|
||
}
|
||
formRef.value?.resetFields()
|
||
}
|
||
|
||
|
||
/** 处理商机变化 */
|
||
const handleQuotationChange = async (quotationId: number) => {
|
||
if (!quotationId) return
|
||
try {
|
||
const quotation = await QuotationApi.getQuotation(quotationId)
|
||
formData.value.products = quotation.products;
|
||
formData.value.customerId = quotation.customerId;
|
||
|
||
formData.value.invoiceTemplateId = quotation.invoiceTemplateId;
|
||
|
||
formData.value.ownerUserId = quotation.ownerUserId;
|
||
formData.value.expanderUserId = quotation.expanderUserId;
|
||
formData.value.pricingUserId = quotation.pricingUserId;
|
||
formData.value.signUserId = quotation.signUserId;
|
||
formData.value.signPhoneNumber = quotation.signPhoneNumber;
|
||
formData.value.signEmail = quotation.signEmail;
|
||
formData.value.signWechat = quotation.signWechat;
|
||
|
||
formData.value.partnerCompanyId = quotation.partnerCompanyId;
|
||
|
||
formData.value.creditLimit = quotation.creditLimit;
|
||
formData.value.creditMethod = quotation.creditMethod;
|
||
formData.value.creditCalcCycle = quotation.creditCalcCycle;
|
||
|
||
formData.value.deptId = quotation.deptId;
|
||
formData.value.offlinePrice = quotation.offlinePrice;
|
||
formData.value.onlinePrice = quotation.onlinePrice;
|
||
formData.value.totalPrice = quotation.totalPrice;
|
||
|
||
// 🔁 自动加载客户详情
|
||
await onCustomerChange(quotation.customerId);
|
||
} catch (err) {
|
||
} finally {
|
||
|
||
}
|
||
|
||
}
|
||
|
||
const onCustomerChange = async (customerId: string) => {
|
||
if (!customerId) return;
|
||
|
||
try {
|
||
formLoading.value = true;
|
||
const customerRes = await CustomerApi.getCustomer(customerId);
|
||
formData.value.cooperationType = customerRes.cooperationType;
|
||
formData.value.companyType = customerRes.companyType;
|
||
formData.value.listingStatus = customerRes.listingStatus;
|
||
formData.value.financingInfo = customerRes.financingInfo;
|
||
formData.value.paidInCapital = customerRes.paidInCapital;
|
||
formData.value.insuredCount = customerRes.insuredCount;
|
||
formData.value.establishmentDate = customerRes.establishmentDate;
|
||
formData.value.enterpriseType = customerRes.enterpriseType;
|
||
formData.value.businessStatus = customerRes.businessStatus;
|
||
formData.value.defendantRecord = customerRes.defendantRecord;
|
||
formData.value.businessAbnormal = customerRes.businessAbnormal;
|
||
formData.value.equityPledge = customerRes.equityPledge;
|
||
formData.value.dishonestRecord = customerRes.dishonestRecord;
|
||
formData.value.financingRecord = customerRes.financingRecord;
|
||
formData.value.enforcementRecord = customerRes.enforcementRecord;
|
||
} catch (err) {
|
||
console.error('获取客户详情失败:', err);
|
||
} finally {
|
||
formLoading.value = false;
|
||
}
|
||
}
|
||
|
||
|
||
/** 动态获取客户联系人 */
|
||
const getContactOptions = computed(() =>
|
||
contactList.value.filter((item) => item.customerId == formData.value.customerId)
|
||
)
|
||
|
||
const route = useRoute();
|
||
onMounted(async () => {
|
||
formType.value = props.id || route.query.id;
|
||
|
||
if (formType.value) open(formType.value)
|
||
|
||
// 获得客户列表
|
||
customerList.value = await CustomerApi.getCustomerSimpleList()
|
||
// 获得用户列表
|
||
userOptions.value = await UserApi.getSimpleUserList()
|
||
// 获得报价列表
|
||
quotationList.value = await QuotationApi.getSimpleQuotationList()
|
||
|
||
// 默认新建时选中自己
|
||
// if (formType.value === 'create') {
|
||
// formData.value.ownerUserId = useUserStore().getUser.id
|
||
// }
|
||
// 获取联系人
|
||
contactList.value = await CustomerApi.getCustomerSimpleList()
|
||
});
|
||
</script>
|