CRM:完善回款的新增/修改

This commit is contained in:
YunaiV 2024-02-25 18:44:19 +08:00
parent 70bf234133
commit 5369328b37
5 changed files with 123 additions and 109 deletions

View File

@ -4,7 +4,6 @@ export interface ReceivablePlanVO {
id: number id: number
period: number period: number
receivableId: number receivableId: number
finishStatus: number
price: number price: number
returnTime: Date returnTime: Date
remindDays: number remindDays: number
@ -43,10 +42,9 @@ export const getReceivablePlan = async (id: number) => {
} }
// 查询回款计划下拉数据 // 查询回款计划下拉数据
// TODO @芋艿:再看看这里 export const getReceivablePlanSimpleList = async (customerId: number, contractId: number) => {
export const getReceivablePlanListByContractId = async (customerId: number, contractId: number) => {
return await request.get({ return await request.get({
url: `/crm/receivable-plan/list-all-simple-by-customer?customerId=${customerId}&contractId=${contractId}` url: `/crm/receivable-plan/simple-list?customerId=${customerId}&contractId=${contractId}`
}) })
} }

View File

@ -10,12 +10,37 @@
<el-row> <el-row>
<el-col :span="12"> <el-col :span="12">
<el-form-item label="回款编号" prop="no"> <el-form-item label="回款编号" prop="no">
<el-input v-model="formData.no" placeholder="请输入回款编号" /> <el-input disabled v-model="formData.no" placeholder="保存时自动生成" />
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :span="12">
<el-form-item label="负责人" prop="ownerUserId">
<el-select
v-model="formData.ownerUserId"
:disabled="formType !== 'create'"
class="w-1/1"
>
<el-option
v-for="item in userOptions"
:key="item.id"
:label="item.nickname"
:value="item.id"
/>
</el-select>
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="12"> <el-col :span="12">
<el-form-item label="客户名称" prop="customerId"> <el-form-item label="客户名称" prop="customerId">
<el-select v-model="formData.customerId" class="w-1/1" placeholder="请选择客户"> <el-select
v-model="formData.customerId"
:disabled="formType !== 'create'"
class="w-1/1"
filterable
@change="handleCustomerChange"
placeholder="请选择客户"
>
<el-option <el-option
v-for="item in customerList" v-for="item in customerList"
:key="item.id" :key="item.id"
@ -29,8 +54,10 @@
<el-form-item label="合同名称" prop="contractId"> <el-form-item label="合同名称" prop="contractId">
<el-select <el-select
v-model="formData.contractId" v-model="formData.contractId"
:disabled="!formData.customerId" :disabled="formType !== 'create' || !formData.customerId"
class="!w-100%" class="w-1/1"
filterable
@change="handleContractChange"
placeholder="请选择合同" placeholder="请选择合同"
> >
<el-option <el-option
@ -38,42 +65,35 @@
:key="data.id" :key="data.id"
:label="data.name" :label="data.name"
:value="data.id!" :value="data.id!"
:disabled="data.auditStatus !== 20"
/> />
</el-select> </el-select>
</el-form-item> </el-form-item>
</el-col> </el-col>
</el-row>
<el-row>
<el-col :span="12"> <el-col :span="12">
<el-form-item label="回款期数" prop="planId"> <el-form-item label="回款期数" prop="planId">
<el-select <el-select
v-model="formData.planId" v-model="formData.planId"
:disabled="!formData.contractId" :disabled="formType !== 'create' || !formData.contractId"
class="!w-100%" class="!w-1/1"
@change="handleReceivablePlanChange"
placeholder="请选择回款期数" placeholder="请选择回款期数"
> >
<el-option <el-option
v-for="data in receivablePlanList" v-for="data in receivablePlanList"
:key="data.id" :key="data.id"
:label="data.period + '期'" :label="'第 ' + data.period + ' 期'"
:value="data.id!" :value="data.id!"
/> :disabled="data.receivableId"
</el-select>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="负责人" prop="ownerUserId">
<el-select v-model="formData.ownerUserId" clearable placeholder="请输入负责人">
<el-option
v-for="item in userList"
:key="item.id"
:label="item.nickname"
:value="item.id"
/> />
</el-select> </el-select>
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :span="12"> <el-col :span="12">
<el-form-item label="回款方式" prop="returnType"> <el-form-item label="回款方式" prop="returnType">
<el-select v-model="formData.returnType" placeholder="请选择回款方式"> <el-select v-model="formData.returnType" class="w-1/1" placeholder="请选择回款方式">
<el-option <el-option
v-for="dict in getIntDictOptions(DICT_TYPE.CRM_RECEIVABLE_RETURN_TYPE)" v-for="dict in getIntDictOptions(DICT_TYPE.CRM_RECEIVABLE_RETURN_TYPE)"
:key="dict.value" :key="dict.value"
@ -83,6 +103,8 @@
</el-select> </el-select>
</el-form-item> </el-form-item>
</el-col> </el-col>
</el-row>
<el-row>
<el-col :span="12"> <el-col :span="12">
<el-form-item label="回款金额" prop="price"> <el-form-item label="回款金额" prop="price">
<el-input-number <el-input-number
@ -90,6 +112,8 @@
class="!w-100%" class="!w-100%"
controls-position="right" controls-position="right"
placeholder="请输入回款金额" placeholder="请输入回款金额"
:min="0.01"
:precision="2"
/> />
</el-form-item> </el-form-item>
</el-col> </el-col>
@ -103,14 +127,11 @@
/> />
</el-form-item> </el-form-item>
</el-col> </el-col>
</el-row>
<el-row>
<el-col :span="24"> <el-col :span="24">
<el-form-item label="备注" prop="remark"> <el-form-item label="备注" prop="remark">
<el-input <el-input v-model="formData.remark" placeholder="请输入备注" type="textarea" />
v-model="formData.remark"
:rows="3"
placeholder="请输入备注"
type="textarea"
/>
</el-form-item> </el-form-item>
</el-col> </el-col>
</el-row> </el-row>
@ -129,20 +150,19 @@ import * as CustomerApi from '@/api/crm/customer'
import * as ContractApi from '@/api/crm/contract' import * as ContractApi from '@/api/crm/contract'
import { useUserStore } from '@/store/modules/user' import { useUserStore } from '@/store/modules/user'
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict' import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import form from '@/components/Form/src/Form.vue'
const { t } = useI18n() // const { t } = useI18n() //
const message = useMessage() // const message = useMessage() //
const userList = ref<UserApi.UserVO[]>([]) // const userOptions = ref<UserApi.UserVO[]>([]) //
const dialogVisible = ref(false) // const dialogVisible = ref(false) //
const dialogTitle = ref('') // const dialogTitle = ref('') //
const formLoading = ref(false) // 12 const formLoading = ref(false) // 12
const formType = ref('') // create - update - const formType = ref('') // create - update -
const formData = ref<ReceivableApi.ReceivableVO>({} as ReceivableApi.ReceivableVO) const formData = ref<ReceivableApi.ReceivableVO>({} as ReceivableApi.ReceivableVO)
const formRules = reactive({ const formRules = reactive({
no: [{ required: true, message: '回款编号不能为空', trigger: 'blur' }],
customerId: [{ required: true, message: '客户不能为空', trigger: 'blur' }], customerId: [{ required: true, message: '客户不能为空', trigger: 'blur' }],
contractId: [{ required: true, message: '合同不能为空', trigger: 'blur' }], contractId: [{ required: true, message: '合同不能为空', trigger: 'blur' }],
auditStatus: [{ required: true, message: '审批状态不能为空', trigger: 'blur' }],
returnTime: [{ required: true, message: '回款日期不能为空', trigger: 'blur' }], returnTime: [{ required: true, message: '回款日期不能为空', trigger: 'blur' }],
price: [{ required: true, message: '回款金额不能为空', trigger: 'blur' }] price: [{ required: true, message: '回款金额不能为空', trigger: 'blur' }]
}) })
@ -150,8 +170,13 @@ const formRef = ref() // 表单 Ref
const customerList = ref<CustomerApi.CustomerVO[]>([]) // const customerList = ref<CustomerApi.CustomerVO[]>([]) //
const contractList = ref<ContractApi.ContractVO[]>([]) // const contractList = ref<ContractApi.ContractVO[]>([]) //
const receivablePlanList = ref<ReceivablePlanApi.ReceivablePlanVO[]>([]) // const receivablePlanList = ref<ReceivablePlanApi.ReceivablePlanVO[]>([]) //
/** 打开弹窗 */ /** 打开弹窗 */
const open = async (type: string, id?: number, planData?: ReceivablePlanApi.ReceivablePlanVO) => { const open = async (
type: string,
id?: number,
receivablePlan?: ReceivablePlanApi.ReceivablePlanVO
) => {
dialogVisible.value = true dialogVisible.value = true
dialogTitle.value = t('action.' + type) dialogTitle.value = t('action.' + type)
formType.value = type formType.value = type
@ -166,7 +191,7 @@ const open = async (type: string, id?: number, planData?: ReceivablePlanApi.Rece
} }
} }
// //
userList.value = await UserApi.getSimpleUserList() userOptions.value = await UserApi.getSimpleUserList()
// //
customerList.value = await CustomerApi.getCustomerSimpleList() customerList.value = await CustomerApi.getCustomerSimpleList()
// //
@ -174,10 +199,12 @@ const open = async (type: string, id?: number, planData?: ReceivablePlanApi.Rece
formData.value.ownerUserId = useUserStore().getUser.id formData.value.ownerUserId = useUserStore().getUser.id
} }
// //
if (planData) { if (receivablePlan) {
formData.value.customerId = planData.customerId formData.value.customerId = receivablePlan.customerId
formData.value.contractId = planData.contractId formData.value.contractId = receivablePlan.contractId
formData.value.planId = planData.id formData.value.planId = receivablePlan.id
formData.value.price = receivablePlan.price
formData.value.returnType = receivablePlan.returnType
} }
} }
defineExpose({ open }) // open defineExpose({ open }) // open
@ -214,53 +241,47 @@ const resetForm = () => {
formRef.value?.resetFields() formRef.value?.resetFields()
} }
const getContractList = async (customerId: number) => { /** 处理切换客户 */
const handleCustomerChange = async (customerId: number) => {
//
formData.value.contractId = undefined
//
if (customerId) {
contractList.value = []
contractList.value = await ContractApi.getContractSimpleList(customerId) contractList.value = await ContractApi.getContractSimpleList(customerId)
} }
const getReceivablePlanList = async (contractId: number) => { }
receivablePlanList.value = await ReceivablePlanApi.getReceivablePlanListByContractId(
/** 处理切换合同 */
const handleContractChange = async (contractId: number) => {
//
formData.value.planId = undefined
if (contractId) {
//
receivablePlanList.value = []
receivablePlanList.value = await ReceivablePlanApi.getReceivablePlanSimpleList(
formData.value.customerId, formData.value.customerId,
contractId contractId
) )
//
const contract = contractList.value.find((item) => item.id === contractId)
if (contract) {
// TODO @
formData.value.price = contract.totalPrice
} }
watch( }
() => formData.value.customerId, }
(newVal) => {
if (!newVal) { /** 处理切换回款计划 */
const handleReceivablePlanChange = (planId: number) => {
if (!planId) {
return return
} }
getContractList(newVal) const receivablePlan = receivablePlanList.value.find((item) => item.id === planId)
},
{
immediate: true
}
)
watch(
() => formData.value.contractId,
(newVal) => {
if (!newVal) {
return
}
getReceivablePlanList(newVal)
},
{
immediate: true
}
)
watch(
() => formData.value.planId,
(newVal) => {
if (!newVal) {
return
}
const receivablePlan = receivablePlanList.value.find((item) => item.id === newVal)
if (!receivablePlan) { if (!receivablePlan) {
return return
} }
//
if (!formData.value.price || formData.value.price === 0) {
formData.value.price = receivablePlan.price formData.value.price = receivablePlan.price
formData.value.returnType = receivablePlan.returnType
} }
}
)
</script> </script>

View File

@ -195,7 +195,6 @@
<!-- 表单弹窗添加/修改 --> <!-- 表单弹窗添加/修改 -->
<ReceivableForm ref="formRef" @success="getList" /> <ReceivableForm ref="formRef" @success="getList" />
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { DICT_TYPE } from '@/utils/dict' import { DICT_TYPE } from '@/utils/dict'
import { dateFormatter, dateFormatter2 } from '@/utils/formatTime' import { dateFormatter, dateFormatter2 } from '@/utils/formatTime'

View File

@ -31,17 +31,6 @@
/> />
<el-table-column label="负责人" prop="ownerUserName" width="120" /> <el-table-column label="负责人" prop="ownerUserName" width="120" />
<el-table-column align="center" label="备注" prop="remark" /> <el-table-column align="center" label="备注" prop="remark" />
<el-table-column
align="center"
fixed="right"
label="完成状态"
prop="finishStatus"
width="130px"
>
<template #default="scope">
<dict-tag :type="DICT_TYPE.INFRA_BOOLEAN_STRING" :value="scope.row.finishStatus" />
</template>
</el-table-column>
<el-table-column align="center" fixed="right" label="操作" width="200px"> <el-table-column align="center" fixed="right" label="操作" width="200px">
<template #default="scope"> <template #default="scope">
<el-button <el-button
@ -141,6 +130,7 @@ const openForm = (type: string, id?: number) => {
formRef.value.open(type, id) formRef.value.open(type, id)
} }
// todo @puhui999
const emits = defineEmits<{ const emits = defineEmits<{
(e: 'crateReceivable', v: ReceivablePlanApi.ReceivablePlanVO) (e: 'crateReceivable', v: ReceivablePlanApi.ReceivablePlanVO)
}>() }>()
@ -161,6 +151,7 @@ const handleDelete = async (id: number) => {
await getList() await getList()
} catch {} } catch {}
} }
/** 监听打开的 customerId + contractId从而加载最新的列表 */ /** 监听打开的 customerId + contractId从而加载最新的列表 */
watch( watch(
() => [props.customerId, props.contractId], () => [props.customerId, props.contractId],

View File

@ -152,17 +152,6 @@
<el-text v-else>{{ erpPriceInputFormatter(scope.row.price) }}</el-text> <el-text v-else>{{ erpPriceInputFormatter(scope.row.price) }}</el-text>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column
align="center"
fixed="right"
label="完成状态"
prop="finishStatus"
width="130px"
>
<template #default="scope">
<dict-tag :type="DICT_TYPE.INFRA_BOOLEAN_STRING" :value="scope.row.finishStatus" />
</template>
</el-table-column>
<el-table-column <el-table-column
:formatter="dateFormatter" :formatter="dateFormatter"
align="center" align="center"
@ -178,9 +167,17 @@
width="180px" width="180px"
/> />
<el-table-column align="center" label="创建人" prop="creatorName" width="100px" /> <el-table-column align="center" label="创建人" prop="creatorName" width="100px" />
<el-table-column align="center" fixed="right" label="操作" width="130px"> <el-table-column align="center" fixed="right" label="操作" width="180px">
<!-- TODO @puhui999新建回款 -->
<template #default="scope"> <template #default="scope">
<el-button
v-hasPermi="['crm:receivable:create']"
link
type="success"
@click="openReceivableForm(scope.row)"
:disabled="scope.row.receivableId"
>
创建回款
</el-button>
<el-button <el-button
v-hasPermi="['crm:receivable-plan:update']" v-hasPermi="['crm:receivable-plan:update']"
link link
@ -211,6 +208,7 @@
<!-- 表单弹窗添加/修改 --> <!-- 表单弹窗添加/修改 -->
<ReceivablePlanForm ref="formRef" @success="getList" /> <ReceivablePlanForm ref="formRef" @success="getList" />
<ReceivableForm ref="receivableFormRef" @success="getList" />
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
@ -222,6 +220,7 @@ import ReceivablePlanForm from './ReceivablePlanForm.vue'
import * as CustomerApi from '@/api/crm/customer' import * as CustomerApi from '@/api/crm/customer'
import { erpPriceInputFormatter, erpPriceTableColumnFormatter } from '@/utils' import { erpPriceInputFormatter, erpPriceTableColumnFormatter } from '@/utils'
import { TabsPaneContext } from 'element-plus' import { TabsPaneContext } from 'element-plus'
import ReceivableForm from '@/views/crm/receivable/ReceivableForm.vue'
defineOptions({ name: 'ReceivablePlan' }) defineOptions({ name: 'ReceivablePlan' })
@ -279,6 +278,12 @@ const openForm = (type: string, id?: number) => {
formRef.value.open(type, id) formRef.value.open(type, id)
} }
/** 创建回款操作 */
const receivableFormRef = ref()
const openReceivableForm = (row: ReceivablePlanApi.ReceivablePlanVO) => {
receivableFormRef.value.open('create', undefined, row)
}
/** 删除按钮操作 */ /** 删除按钮操作 */
const handleDelete = async (id: number) => { const handleDelete = async (id: number) => {
try { try {