1
1
<!-- 跟进记录的添加表单弹窗 -->
2
2
<template >
3
- <Dialog v-model =" dialogVisible" : title =" dialogTitle " width =" 50%" >
3
+ <Dialog v-model =" dialogVisible" title =" 添加跟进记录 " width =" 50%" >
4
4
<el-form
5
5
ref =" formRef"
6
6
v-loading =" formLoading"
36
36
<el-input v-model =" formData.content" :rows =" 3" type =" textarea" />
37
37
</el-form-item >
38
38
</el-col >
39
- <el-col :span =" 24 " >
40
- <el-form-item label =" 图片" prop =" content " >
39
+ <el-col :span =" 12 " >
40
+ <el-form-item label =" 图片" prop =" picUrls " >
41
41
<UploadImgs v-model =" formData.picUrls" class =" min-w-80px" />
42
42
</el-form-item >
43
43
</el-col >
44
- <el-col :span =" 24 " >
45
- <el-form-item label =" 附件" prop =" content " >
44
+ <el-col :span =" 12 " >
45
+ <el-form-item label =" 附件" prop =" fileUrls " >
46
46
<UploadFile v-model =" formData.fileUrls" class =" min-w-80px" />
47
47
</el-form-item >
48
48
</el-col >
49
- <el-col :span =" 24" >
49
+ <el-col :span =" 24" v-if = " formData.bizType == BizTypeEnum.CRM_CUSTOMER " >
50
50
<el-form-item label =" 关联联系人" prop =" contactIds" >
51
51
<el-button @click =" handleAddContact" >
52
52
<Icon class =" mr-5px" icon =" ep:plus" />
55
55
<contact-list v-model:contactIds =" formData.contactIds" />
56
56
</el-form-item >
57
57
</el-col >
58
- <el-col :span =" 24" >
58
+ <el-col :span =" 24" v-if = " formData.bizType == BizTypeEnum.CRM_CUSTOMER " >
59
59
<el-form-item label =" 关联商机" prop =" businessIds" >
60
- <el-button @click =" handleAddBusiness " >
60
+ <el-button @click =" handleOpenBusiness " >
61
61
<Icon class =" mr-5px" icon =" ep:plus" />
62
62
添加商机
63
63
</el-button >
64
- <business-list v-model:businessIds =" formData.businessIds " />
64
+ <FollowUpRecordBusinessForm :businesses =" formData.businesses " />
65
65
</el-form-item >
66
66
</el-col >
67
67
</el-row >
71
71
<el-button @click =" dialogVisible = false" >取 消</el-button >
72
72
</template >
73
73
</Dialog >
74
+
75
+ <!-- 弹窗 -->
74
76
<ContactTableSelect ref =" contactTableSelectRef" v-model =" formData.contactIds" />
75
- <BusinessTableSelect ref =" businessTableSelectRef" v-model =" formData.businessIds" />
77
+ <BusinessListModal
78
+ ref =" businessTableSelectRef"
79
+ :customer-id =" formData.bizId"
80
+ @success =" handleAddBusiness"
81
+ />
76
82
</template >
77
83
<script lang="ts" setup>
78
84
import { DICT_TYPE , getIntDictOptions } from ' @/utils/dict'
79
85
import { FollowUpRecordApi , FollowUpRecordVO } from ' @/api/crm/followup'
80
- import { BusinessList , BusinessTableSelect , ContactList , ContactTableSelect } from ' ./components'
86
+ import { ContactList , ContactTableSelect } from ' ./components'
87
+ import { BizTypeEnum } from ' @/api/crm/permission'
88
+ import FollowUpRecordBusinessForm from ' ./components/FollowUpRecordBusinessForm.vue'
89
+ import BusinessListModal from ' @/views/crm/business/components/BusinessListModal.vue'
90
+ import * as BusinessApi from ' @/api/crm/business'
81
91
82
92
defineOptions ({ name: ' FollowUpRecordForm' })
83
93
@@ -87,8 +97,12 @@ const message = useMessage() // 消息弹窗
87
97
const dialogVisible = ref (false ) // 弹窗的是否展示
88
98
const dialogTitle = ref (' ' ) // 弹窗的标题
89
99
const formLoading = ref (false ) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
90
- const formType = ref (' ' ) // 表单的类型:create - 新增;update - 修改
91
- const formData = ref <FollowUpRecordVO >({} as FollowUpRecordVO )
100
+ const formData = ref ({
101
+ bizType: undefined ,
102
+ bizId: undefined ,
103
+ businesses: [],
104
+ contacts: []
105
+ })
92
106
const formRules = reactive ({
93
107
type: [{ required: true , message: ' 跟进类型不能为空' , trigger: ' change' }],
94
108
content: [{ required: true , message: ' 跟进内容不能为空' , trigger: ' blur' }],
@@ -98,22 +112,11 @@ const formRules = reactive({
98
112
const formRef = ref () // 表单 Ref
99
113
100
114
/** 打开弹窗 */
101
- const open = async (bizType : number , bizId : number , type : string , id ? : number ) => {
115
+ const open = async (bizType : number , bizId : number ) => {
102
116
dialogVisible .value = true
103
- dialogTitle .value = t (' action.' + type )
104
- formType .value = type
105
117
resetForm ()
106
118
formData .value .bizType = bizType
107
119
formData .value .bizId = bizId
108
- // 修改时,设置数据
109
- if (id ) {
110
- formLoading .value = true
111
- try {
112
- formData .value = await FollowUpRecordApi .getFollowUpRecord (id )
113
- } finally {
114
- formLoading .value = false
115
- }
116
- }
117
120
}
118
121
defineExpose ({ open }) // 提供 open 方法,用于打开弹窗
119
122
@@ -126,13 +129,8 @@ const submitForm = async () => {
126
129
formLoading .value = true
127
130
try {
128
131
const data = formData .value as unknown as FollowUpRecordVO
129
- if (formType .value === ' create' ) {
130
- await FollowUpRecordApi .createFollowUpRecord (data )
131
- message .success (t (' common.createSuccess' ))
132
- } else {
133
- await FollowUpRecordApi .updateFollowUpRecord (data )
134
- message .success (t (' common.updateSuccess' ))
135
- }
132
+ await FollowUpRecordApi .createFollowUpRecord (data )
133
+ message .success (t (' common.createSuccess' ))
136
134
dialogVisible .value = false
137
135
// 发送操作成功的事件
138
136
emit (' success' )
@@ -148,14 +146,26 @@ const handleAddContact = () => {
148
146
}
149
147
150
148
/** 关联商机 */
151
- const businessTableSelectRef = ref <InstanceType <typeof BusinessTableSelect >>()
152
- const handleAddBusiness = () => {
149
+ const businessTableSelectRef = ref <InstanceType <typeof BusinessListModal >>()
150
+ const handleOpenBusiness = () => {
153
151
businessTableSelectRef .value ?.open ()
154
152
}
153
+ const handleAddBusiness = (businessId : [], newBusinesses : BusinessApi .BusinessVO []) => {
154
+ newBusinesses .forEach ((business ) => {
155
+ if (! formData .value .businesses .some ((item ) => item .id === business .id )) {
156
+ formData .value .businesses .push (business )
157
+ }
158
+ })
159
+ }
155
160
156
161
/** 重置表单 */
157
162
const resetForm = () => {
158
163
formRef .value ?.resetFields ()
159
- formData .value = {} as FollowUpRecordVO
164
+ formData .value = {
165
+ bizId: undefined ,
166
+ bizType: undefined ,
167
+ businesses: [],
168
+ contacts: []
169
+ }
160
170
}
161
171
</script >
0 commit comments