5
5
<Icon class =" mr-5px" icon =" ep:opportunity" />
6
6
创建商机
7
7
</el-button >
8
+ <el-button
9
+ @click =" openBusinessModal"
10
+ v-hasPermi =" ['crm:contact:create-business']"
11
+ v-if =" queryParams.contactId"
12
+ >
13
+ <Icon class =" mr-5px" icon =" ep:circle-plus" />关联
14
+ </el-button >
15
+ <el-button
16
+ @click =" deleteContactBusinessList"
17
+ v-hasPermi =" ['crm:contact:delete-business']"
18
+ v-if =" queryParams.contactId"
19
+ >
20
+ <Icon class =" mr-5px" icon =" ep:remove" />解除关联
21
+ </el-button >
8
22
</el-row >
9
23
10
24
<!-- 列表 -->
11
25
<ContentWrap class =" mt-10px" >
12
- <el-table v-loading =" loading" :data =" list" :stripe =" true" :show-overflow-tooltip =" true" >
26
+ <el-table
27
+ ref =" businessRef"
28
+ v-loading =" loading"
29
+ :data =" list"
30
+ :stripe =" true"
31
+ :show-overflow-tooltip =" true"
32
+ >
33
+ <el-table-column type =" selection" width =" 55" v-if =" queryParams.contactId" />
13
34
<el-table-column label =" 商机名称" fixed =" left" align =" center" prop =" name" >
14
35
<template #default =" scope " >
15
36
<el-link type =" primary" :underline =" false" @click =" openDetail(scope.row.id)" >
33
54
34
55
<!-- 表单弹窗:添加 -->
35
56
<BusinessForm ref =" formRef" @success =" getList" />
57
+ <!-- 关联商机选择弹框 -->
58
+ <BusinessListModal
59
+ ref =" businessModalRef"
60
+ :customer-id =" props.customerId"
61
+ @success =" createContactBusinessList"
62
+ />
36
63
</template >
37
64
<script setup lang="ts">
38
65
import * as BusinessApi from ' @/api/crm/business'
66
+ import * as ContactApi from ' @/api/crm/contact'
39
67
import BusinessForm from ' ./../BusinessForm.vue'
40
68
import { BizTypeEnum } from ' @/api/crm/permission'
41
69
import { fenToYuanFormat } from ' @/utils/formatter'
42
- import * as ContactApi from ' @/api/crm/contact'
70
+ import BusinessListModal from ' ./BusinessListModal.vue'
71
+
72
+ const message = useMessage () // 消息
43
73
44
74
defineOptions ({ name: ' CrmBusinessList' })
45
75
const props = defineProps <{
46
76
bizType: number // 业务类型
47
77
bizId: number // 业务编号
78
+ customerId: number // 关联联系人与商机时,需要传入 customerId 进行筛选
48
79
}>()
49
80
50
81
const loading = ref (true ) // 列表的加载中
@@ -53,7 +84,8 @@ const list = ref([]) // 列表的数据
53
84
const queryParams = reactive ({
54
85
pageNo: 1 ,
55
86
pageSize: 10 ,
56
- customerId: undefined as unknown // 允许 undefined + number
87
+ customerId: undefined as unknown , // 允许 undefined + number
88
+ contactId: undefined as unknown // 允许 undefined + number
57
89
})
58
90
59
91
/** 查询列表 */
@@ -62,21 +94,23 @@ const getList = async () => {
62
94
try {
63
95
// 置空参数
64
96
queryParams .customerId = undefined
97
+ queryParams .contactId = undefined
65
98
// 执行查询
66
99
let data = { list: [], total: 0 }
67
100
switch (props .bizType ) {
68
101
case BizTypeEnum .CRM_CUSTOMER :
69
102
queryParams .customerId = props .bizId
70
103
data = await BusinessApi .getBusinessPageByCustomer (queryParams )
71
-
72
- console .log (data )
104
+ break
105
+ case BizTypeEnum .CRM_CONTACT :
106
+ queryParams .contactId = props .bizId
107
+ data = await BusinessApi .getBusinessPageByContact (queryParams )
73
108
break
74
109
default :
75
110
return
76
111
}
77
112
list .value = data .list
78
113
total .value = data .total
79
- console .log (list .value )
80
114
} finally {
81
115
loading .value = false
82
116
}
@@ -100,6 +134,41 @@ const openDetail = (id: number) => {
100
134
push ({ name: ' CrmBusinessDetail' , params: { id } })
101
135
}
102
136
137
+ /** 打开联系人与商机的关联弹窗 */
138
+ const businessModalRef = ref ()
139
+ const openBusinessModal = () => {
140
+ businessModalRef .value .open ()
141
+ }
142
+ const createContactBusinessList = async (businessIds : number []) => {
143
+ const data = {
144
+ contactId: props .bizId ,
145
+ businessIds: businessIds
146
+ } as ContactApi .ContactBusinessReqVO
147
+ businessRef .value .getSelectionRows ().forEach ((row : BusinessApi .BusinessVO ) => {
148
+ data .businessIds .push (row .id )
149
+ })
150
+ await ContactApi .createContactBusinessList (data )
151
+ // 刷新列表
152
+ message .success (' 关联商机成功' )
153
+ handleQuery ()
154
+ }
155
+
156
+ /** 解除联系人与商机的关联 */
157
+ const businessRef = ref ()
158
+ const deleteContactBusinessList = async () => {
159
+ const data = {
160
+ contactId: props .bizId ,
161
+ businessIds: businessRef .value .getSelectionRows ().map ((row : BusinessApi .BusinessVO ) => row .id )
162
+ } as ContactApi .ContactBusinessReqVO
163
+ if (data .businessIds .length === 0 ) {
164
+ return message .error (' 未选择商机' )
165
+ }
166
+ await ContactApi .deleteContactBusinessList (data )
167
+ // 刷新列表
168
+ message .success (' 取关商机成功' )
169
+ handleQuery ()
170
+ }
171
+
103
172
/** 监听打开的 bizId + bizType,从而加载最新的列表 */
104
173
watch (
105
174
() => [props .bizId , props .bizType ],
0 commit comments