Skip to content

Commit bbf6c16

Browse files
committed
✨ CRM:完成商机状态的变更
1 parent cf7036d commit bbf6c16

File tree

4 files changed

+135
-0
lines changed

4 files changed

+135
-0
lines changed

src/api/crm/business/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ export const updateBusiness = async (data: BusinessVO) => {
7272
return await request.put({ url: `/crm/business/update`, data })
7373
}
7474

75+
// 修改 CRM 商机状态
76+
export const updateBusinessStatus = async (data: BusinessVO) => {
77+
return await request.put({ url: `/crm/business/update-status`, data })
78+
}
79+
7580
// 删除 CRM 商机
7681
export const deleteBusiness = async (id: number) => {
7782
return await request.delete({ url: `/crm/business/delete?id=` + id })

src/api/crm/business/status/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,8 @@ export const deleteBusinessStatus = async (id: number) => {
6161
export const getBusinessStatusTypeSimpleList = async () => {
6262
return await request.get({ url: `/crm/business-status/type-simple-list` })
6363
}
64+
65+
// 获得商机阶段列表
66+
export const getBusinessStatusSimpleList = async (typeId: number) => {
67+
return await request.get({ url: `/crm/business-status/status-simple-list`, params: { typeId } })
68+
}
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
<template>
2+
<Dialog title="变更商机状态" v-model="dialogVisible" width="400">
3+
<el-form
4+
ref="formRef"
5+
:model="formData"
6+
:rules="formRules"
7+
label-width="80px"
8+
v-loading="formLoading"
9+
>
10+
<el-form-item label="商机阶段" prop="status">
11+
<el-select v-model="formData.status" placeholder="请选择商机阶段" class="w-1/1">
12+
<el-option
13+
v-for="item in statusList"
14+
:key="item.id"
15+
:label="item.name + '(赢单率:' + item.percent + '%)'"
16+
:value="item.id"
17+
/>
18+
<el-option
19+
v-for="item in BusinessStatusApi.DEFAULT_STATUSES"
20+
:key="item.endStatus"
21+
:label="item.name + '(赢单率:' + item.percent + '%)'"
22+
:value="-item.endStatus"
23+
/>
24+
</el-select>
25+
</el-form-item>
26+
</el-form>
27+
<template #footer>
28+
<el-button @click="submitForm" type="primary" :disabled="formLoading">确 定</el-button>
29+
<el-button @click="dialogVisible = false">取 消</el-button>
30+
</template>
31+
</Dialog>
32+
</template>
33+
<script setup lang="ts">
34+
import * as BusinessApi from '@/api/crm/business'
35+
import * as BusinessStatusApi from '@/api/crm/business/status'
36+
37+
const { t } = useI18n() // 国际化
38+
const message = useMessage() // 消息弹窗
39+
40+
const dialogVisible = ref(false) // 弹窗的是否展示
41+
const formLoading = ref(false) // 表单的加载中
42+
const formData = ref({
43+
id: undefined,
44+
statusId: undefined,
45+
endStatus: undefined,
46+
status: undefined
47+
})
48+
const formRules = reactive({
49+
status: [{ required: true, message: '商机阶段不能为空', trigger: 'blur' }]
50+
})
51+
const formRef = ref() // 表单 Ref
52+
const statusList = ref([]) // 商机状态列表
53+
54+
/** 打开弹窗 */
55+
const open = async (business: BusinessApi.BusinessVO) => {
56+
dialogVisible.value = true
57+
resetForm()
58+
formData.value = {
59+
id: business.id,
60+
statusId: business.statusId,
61+
endStatus: business.endStatus,
62+
status: business.endStatus != null ? -business.endStatus : business.statusId
63+
}
64+
// 加载状态列表
65+
formLoading.value = true
66+
try {
67+
statusList.value = await BusinessStatusApi.getBusinessStatusSimpleList(business.statusTypeId)
68+
} finally {
69+
formLoading.value = false
70+
}
71+
}
72+
defineExpose({ open }) // 提供 open 方法,用于打开弹窗
73+
74+
/** 提交表单 */
75+
const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
76+
const submitForm = async () => {
77+
// 校验表单
78+
if (!formRef) return
79+
const valid = await formRef.value.validate()
80+
if (!valid) return
81+
// 提交请求
82+
formLoading.value = true
83+
try {
84+
await BusinessApi.updateBusinessStatus({
85+
id: formData.value.id,
86+
statusId: formData.value.status > 0 ? formData.value.status : undefined,
87+
endStatus: formData.value.status < 0 ? -formData.value.status : undefined
88+
})
89+
message.success('更新商机状态成功')
90+
dialogVisible.value = false
91+
// 发送操作成功的事件
92+
emit('success')
93+
} finally {
94+
formLoading.value = false
95+
}
96+
}
97+
98+
/** 重置表单 */
99+
const resetForm = () => {
100+
formData.value = {
101+
id: undefined,
102+
statusId: undefined,
103+
endStatus: undefined,
104+
status: undefined
105+
}
106+
formRef.value?.resetFields()
107+
}
108+
</script>

src/views/crm/business/detail/index.vue

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
<el-button v-if="permissionListRef?.validateWrite" @click="openForm('update', business.id)">
44
编辑
55
</el-button>
6+
<el-button
7+
:disabled="business.endStatus"
8+
v-if="permissionListRef?.validateWrite"
9+
type="success"
10+
@click="openStatusForm()"
11+
>
12+
变更商机状态
13+
</el-button>
614
<el-button v-if="permissionListRef?.validateOwnerUser" type="primary" @click="transfer">
715
转移
816
</el-button>
@@ -41,8 +49,10 @@
4149
</el-tab-pane>
4250
</el-tabs>
4351
</el-col>
52+
4453
<!-- 表单弹窗:添加/修改 -->
4554
<ContactForm ref="formRef" @success="getContact(business.id)" />
55+
<BusinessUpdateStatusForm ref="statusFormRef" @success="getContact(business.id)" />
4656
<CrmTransferForm ref="transferFormRef" @success="close" />
4757
</template>
4858
<script lang="ts" setup>
@@ -59,6 +69,7 @@ import ContactForm from '@/views/crm/contact/ContactForm.vue'
5969
import CrmTransferForm from '@/views/crm/permission/components/TransferForm.vue'
6070
import FollowUpList from '@/views/crm/followup/index.vue'
6171
import ContactList from '@/views/crm/contact/components/ContactList.vue'
72+
import BusinessUpdateStatusForm from '@/views/crm/business/BusinessUpdateStatusForm.vue'
6273
6374
defineOptions({ name: 'CrmBusinessDetail' })
6475
@@ -86,6 +97,12 @@ const openForm = (type: string, id?: number) => {
8697
formRef.value.open(type, id)
8798
}
8899
100+
/** 变更商机状态 */
101+
const statusFormRef = ref()
102+
const openStatusForm = () => {
103+
statusFormRef.value.open(business.value)
104+
}
105+
89106
/** 联系人转移 */
90107
const transferFormRef = ref<InstanceType<typeof CrmTransferForm>>() // 联系人转移表单 ref
91108
const transfer = () => {

0 commit comments

Comments
 (0)