CRM:完成商机状态的变更

(cherry picked from commit bbf6c16b8d)
This commit is contained in:
YunaiV 2024-02-22 20:41:37 +08:00 committed by shizhong
parent d19bfb73e2
commit ffb06a4af0
4 changed files with 135 additions and 0 deletions

View File

@ -72,6 +72,11 @@ export const updateBusiness = async (data: BusinessVO) => {
return await request.put({ url: `/crm/business/update`, data })
}
// 修改 CRM 商机状态
export const updateBusinessStatus = async (data: BusinessVO) => {
return await request.put({ url: `/crm/business/update-status`, data })
}
// 删除 CRM 商机
export const deleteBusiness = async (id: number) => {
return await request.delete({ url: `/crm/business/delete?id=` + id })

View File

@ -61,3 +61,8 @@ export const deleteBusinessStatus = async (id: number) => {
export const getBusinessStatusTypeSimpleList = async () => {
return await request.get({ url: `/crm/business-status/type-simple-list` })
}
// 获得商机阶段列表
export const getBusinessStatusSimpleList = async (typeId: number) => {
return await request.get({ url: `/crm/business-status/status-simple-list`, params: { typeId } })
}

View File

@ -0,0 +1,108 @@
<template>
<Dialog title="变更商机状态" v-model="dialogVisible" width="400">
<el-form
ref="formRef"
:model="formData"
:rules="formRules"
label-width="80px"
v-loading="formLoading"
>
<el-form-item label="商机阶段" prop="status">
<el-select v-model="formData.status" placeholder="请选择商机阶段" class="w-1/1">
<el-option
v-for="item in statusList"
:key="item.id"
:label="item.name + '(赢单率:' + item.percent + '%)'"
:value="item.id"
/>
<el-option
v-for="item in BusinessStatusApi.DEFAULT_STATUSES"
:key="item.endStatus"
:label="item.name + '(赢单率:' + item.percent + '%)'"
:value="-item.endStatus"
/>
</el-select>
</el-form-item>
</el-form>
<template #footer>
<el-button @click="submitForm" type="primary" :disabled="formLoading"> </el-button>
<el-button @click="dialogVisible = false"> </el-button>
</template>
</Dialog>
</template>
<script setup lang="ts">
import * as BusinessApi from '@/api/crm/business'
import * as BusinessStatusApi from '@/api/crm/business/status'
const { t } = useI18n() //
const message = useMessage() //
const dialogVisible = ref(false) //
const formLoading = ref(false) //
const formData = ref({
id: undefined,
statusId: undefined,
endStatus: undefined,
status: undefined
})
const formRules = reactive({
status: [{ required: true, message: '商机阶段不能为空', trigger: 'blur' }]
})
const formRef = ref() // Ref
const statusList = ref([]) //
/** 打开弹窗 */
const open = async (business: BusinessApi.BusinessVO) => {
dialogVisible.value = true
resetForm()
formData.value = {
id: business.id,
statusId: business.statusId,
endStatus: business.endStatus,
status: business.endStatus != null ? -business.endStatus : business.statusId
}
//
formLoading.value = true
try {
statusList.value = await BusinessStatusApi.getBusinessStatusSimpleList(business.statusTypeId)
} finally {
formLoading.value = false
}
}
defineExpose({ open }) // open
/** 提交表单 */
const emit = defineEmits(['success']) // success
const submitForm = async () => {
//
if (!formRef) return
const valid = await formRef.value.validate()
if (!valid) return
//
formLoading.value = true
try {
await BusinessApi.updateBusinessStatus({
id: formData.value.id,
statusId: formData.value.status > 0 ? formData.value.status : undefined,
endStatus: formData.value.status < 0 ? -formData.value.status : undefined
})
message.success('更新商机状态成功')
dialogVisible.value = false
//
emit('success')
} finally {
formLoading.value = false
}
}
/** 重置表单 */
const resetForm = () => {
formData.value = {
id: undefined,
statusId: undefined,
endStatus: undefined,
status: undefined
}
formRef.value?.resetFields()
}
</script>

View File

@ -3,6 +3,14 @@
<el-button v-if="permissionListRef?.validateWrite" @click="openForm('update', business.id)">
编辑
</el-button>
<el-button
:disabled="business.endStatus"
v-if="permissionListRef?.validateWrite"
type="success"
@click="openStatusForm()"
>
变更商机状态
</el-button>
<el-button v-if="permissionListRef?.validateOwnerUser" type="primary" @click="transfer">
转移
</el-button>
@ -41,8 +49,10 @@
</el-tab-pane>
</el-tabs>
</el-col>
<!-- 表单弹窗添加/修改 -->
<ContactForm ref="formRef" @success="getContact(business.id)" />
<BusinessUpdateStatusForm ref="statusFormRef" @success="getContact(business.id)" />
<CrmTransferForm ref="transferFormRef" @success="close" />
</template>
<script lang="ts" setup>
@ -59,6 +69,7 @@ import ContactForm from '@/views/crm/contact/ContactForm.vue'
import CrmTransferForm from '@/views/crm/permission/components/TransferForm.vue'
import FollowUpList from '@/views/crm/followup/index.vue'
import ContactList from '@/views/crm/contact/components/ContactList.vue'
import BusinessUpdateStatusForm from '@/views/crm/business/BusinessUpdateStatusForm.vue'
defineOptions({ name: 'CrmBusinessDetail' })
@ -86,6 +97,12 @@ const openForm = (type: string, id?: number) => {
formRef.value.open(type, id)
}
/** 变更商机状态 */
const statusFormRef = ref()
const openStatusForm = () => {
statusFormRef.value.open(business.value)
}
/** 联系人转移 */
const transferFormRef = ref<InstanceType<typeof CrmTransferForm>>() // ref
const transfer = () => {