Skip to content

Commit 0a4023e

Browse files
committed
📖 CRM:code review 商机模块
1 parent 45521c1 commit 0a4023e

File tree

7 files changed

+107
-182
lines changed

7 files changed

+107
-182
lines changed

src/api/crm/contact/index.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ export interface ContactVO {
2525
areaName: string
2626
ownerUserName: string
2727
}
28-
export interface ContactBusinessLinkVO {
29-
id: number
28+
29+
export interface ContactBusinessReqVO {
3030
contactId: number
31-
businessId: number
31+
businessIds: number[]
3232
}
33+
3334
// 查询 CRM 联系人列表
3435
export const getContactPage = async (params) => {
3536
return await request.get({ url: `/crm/contact/page`, params })
@@ -70,12 +71,12 @@ export const getSimpleContactList = async () => {
7071
return await request.get({ url: `/crm/contact/simple-all-list` })
7172
}
7273

73-
//批量新增联系人商机关联
74-
export const createContactBusinessLinkBatch = async (data: ContactBusinessLinkVO[]) => {
75-
return await request.post({ url: `/crm/contact/create-batch-business`, data })
74+
// 批量新增联系人商机关联
75+
export const createContactBusinessList = async (data: ContactBusinessReqVO) => {
76+
return await request.post({ url: `/crm/contact/create-business-list`, data })
7677
}
7778

78-
//解除联系人商机关联
79-
export const deleteContactBusinessLink = async (data: ContactBusinessLinkVO) => {
80-
return await request.delete({ url: `/crm/contact/delete-batch-business`, data })
81-
}
79+
// 解除联系人商机关联
80+
export const deleteContactBusinessList = async (data: ContactBusinessReqVO) => {
81+
return await request.delete({ url: `/crm/contact/delete-business-list`, data })
82+
}

src/views/crm/business/BusinessForm.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@
6262
</el-row>
6363
</el-popover>
6464
</el-form-item>
65+
<!-- TODO @ljlleo:idea 红色的报错,可以解决下 -->
6566
<el-form-item label="商机状态类型" prop="statusTypeId">
6667
<el-select
6768
v-model="formData.statusTypeId"
6869
placeholder="请选择商机状态类型"
6970
clearable
70-
size="small"
7171
@change="changeBusinessStatusType"
7272
>
7373
<el-option
@@ -79,7 +79,7 @@
7979
</el-select>
8080
</el-form-item>
8181
<el-form-item label="商机状态" prop="statusId">
82-
<el-select v-model="formData.statusId" placeholder="请选择商机状态" clearable size="small">
82+
<el-select v-model="formData.statusId" placeholder="请选择商机状态" clearable>
8383
<el-option
8484
v-for="item in businessStatusList"
8585
:key="item.id"
@@ -243,7 +243,7 @@ const queryParams = reactive({
243243
industryId: null,
244244
level: null,
245245
source: null,
246-
pool:false
246+
pool: false
247247
})
248248
// 选择客户
249249
const showCustomer = ref(false)
@@ -252,12 +252,12 @@ const openCustomerSelect = () => {
252252
queryParams.pageNo = 1
253253
getCustomerList()
254254
}
255+
255256
/** 查询客户列表 */
256257
const getCustomerList = async () => {
257258
loading.value = true
258259
try {
259260
const data = await CustomerApi.getCustomerPage(queryParams)
260-
console.log(JSON.stringify(data))
261261
customerList.value = data.list
262262
total.value = data.total
263263
} finally {

src/views/crm/business/components/BusinessList.vue

Lines changed: 75 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,32 @@
55
<Icon class="mr-5px" icon="ep:opportunity" />
66
创建商机
77
</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>
822
</el-row>
923

1024
<!-- 列表 -->
1125
<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" />
1334
<el-table-column label="商机名称" fixed="left" align="center" prop="name">
1435
<template #default="scope">
1536
<el-link type="primary" :underline="false" @click="openDetail(scope.row.id)">
@@ -33,18 +54,28 @@
3354

3455
<!-- 表单弹窗:添加 -->
3556
<BusinessForm ref="formRef" @success="getList" />
57+
<!-- 关联商机选择弹框 -->
58+
<BusinessListModal
59+
ref="businessModalRef"
60+
:customer-id="props.customerId"
61+
@success="createContactBusinessList"
62+
/>
3663
</template>
3764
<script setup lang="ts">
3865
import * as BusinessApi from '@/api/crm/business'
66+
import * as ContactApi from '@/api/crm/contact'
3967
import BusinessForm from './../BusinessForm.vue'
4068
import { BizTypeEnum } from '@/api/crm/permission'
4169
import { fenToYuanFormat } from '@/utils/formatter'
42-
import * as ContactApi from '@/api/crm/contact'
70+
import BusinessListModal from './BusinessListModal.vue'
71+
72+
const message = useMessage() // 消息
4373
4474
defineOptions({ name: 'CrmBusinessList' })
4575
const props = defineProps<{
4676
bizType: number // 业务类型
4777
bizId: number // 业务编号
78+
customerId: number // 关联联系人与商机时,需要传入 customerId 进行筛选
4879
}>()
4980
5081
const loading = ref(true) // 列表的加载中
@@ -53,7 +84,8 @@ const list = ref([]) // 列表的数据
5384
const queryParams = reactive({
5485
pageNo: 1,
5586
pageSize: 10,
56-
customerId: undefined as unknown // 允许 undefined + number
87+
customerId: undefined as unknown, // 允许 undefined + number
88+
contactId: undefined as unknown // 允许 undefined + number
5789
})
5890
5991
/** 查询列表 */
@@ -62,21 +94,23 @@ const getList = async () => {
6294
try {
6395
// 置空参数
6496
queryParams.customerId = undefined
97+
queryParams.contactId = undefined
6598
// 执行查询
6699
let data = { list: [], total: 0 }
67100
switch (props.bizType) {
68101
case BizTypeEnum.CRM_CUSTOMER:
69102
queryParams.customerId = props.bizId
70103
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)
73108
break
74109
default:
75110
return
76111
}
77112
list.value = data.list
78113
total.value = data.total
79-
console.log(list.value)
80114
} finally {
81115
loading.value = false
82116
}
@@ -100,6 +134,41 @@ const openDetail = (id: number) => {
100134
push({ name: 'CrmBusinessDetail', params: { id } })
101135
}
102136
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+
103172
/** 监听打开的 bizId + bizType,从而加载最新的列表 */
104173
watch(
105174
() => [props.bizId, props.bizType],

src/views/crm/business/components/BusinessListByContact.vue

Lines changed: 0 additions & 141 deletions
This file was deleted.

0 commit comments

Comments
 (0)