Files
shanxia2.0/web-admin/src/views/crm/customer/IntoPoolDialog.vue
T
2026-06-01 08:21:21 +08:00

187 lines
4.7 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<el-dialog
title="放入公海池"
v-model="dialog.visible"
width="560px"
class="dialog-form-layout"
align-center
destroy-on-close
:close-on-click-modal="false"
>
<el-alert title="公海池说明" type="warning" :closable="false" show-icon class="pool-alert">
<div>已选择 {{ selectedIds.length }} 位客户,将统一放入公海池</div>
</el-alert>
<el-form ref="formRef" :model="form" :rules="rules" label-position="top">
<el-form-item label="放入原因" prop="reason">
<el-input
v-model="form.reason"
type="textarea"
:rows="6"
placeholder="请输入放入公海池的原因"
maxlength="500"
show-word-limit
/>
<div class="pool-reason-hint">
<div>常见原因:</div>
<ul class="hint-list">
<li>客户长期未跟进,无合作意向</li>
<li>客户联系不上,失去联系</li>
<li>客户明确拒绝合作</li>
<li>客户资源重复或无效</li>
<li>负责人离职,客户需重新分配</li>
</ul>
</div>
</el-form-item>
</el-form>
<el-alert title="温馨提示" type="info" :closable="false" show-icon class="pool-tip-alert">
<ul class="tip-list">
<li>放入公海池后,您将失去对这些客户的编辑权限</li>
<li>其他销售人员可以在公海池中领取这些客户</li>
<li>管理员可以从公海池中重新分配客户</li>
<li>客户的历史跟进记录将被保留</li>
<li>放入公海池的记录将被保存到操作日志中</li>
</ul>
</el-alert>
<template #footer>
<div class="dialog-footer">
<el-button class="btn-ghost" @click="cancel">
<el-icon><Close /></el-icon>取消
</el-button>
<el-button class="btn-main" type="primary" :loading="submitting" @click="submitForm">
<el-icon><Upload /></el-icon>确认放入
</el-button>
</div>
</template>
</el-dialog>
</template>
<script setup lang="ts" name="CustomerIntoPoolForm">
import { Close, Upload } from '@element-plus/icons-vue'
import { fetchIntoPool } from '@/api/crm/customer'
import type { CustomerIntoPoolParams } from '@/api/crm/customerTypes'
const emit = defineEmits(['success'])
// 选中的客户ID(兼容字符串和数字类型)
const selectedIds = ref<(number | string)[]>([])
// 表单数据
const form = ref<CustomerIntoPoolParams>({
ids: [],
reason: '',
remark: '',
})
// 表单校验规则
const rules = ref({
reason: [{ required: true, message: '放入原因不能为空', trigger: 'blur' }],
})
// 对话框
const dialog = reactive({
visible: false,
})
// 提交状态
const submitting = ref(false)
const formRef = ref()
/** 打开对话框 */
const open = async (ids: (number | string | null)[]) => {
reset()
// 过滤掉无效值(兼容字符串和数字类型)
const validIds = ids.filter((id) => id !== null && id !== undefined && id !== '')
if (validIds.length === 0) {
ElMessage.warning('请选择有效的客户')
return
}
selectedIds.value = validIds
form.value.ids = validIds
dialog.visible = true
}
/** 提交表单 */
const submitForm = () => {
formRef.value?.validate(async (valid: boolean) => {
if (valid) {
// 二次确认
try {
await ElMessageBox.confirm(
`确定要将选中的 ${selectedIds.value.length} 位客户放入公海池吗?此操作不可撤销!`,
'提示',
{
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
},
)
submitting.value = true
await fetchIntoPool(form.value)
ElMessage.success('已成功放入公海池')
dialog.visible = false
emit('success')
} catch (error) {
if (error !== 'cancel') {
console.error(error)
}
} finally {
submitting.value = false
}
}
})
}
/** 取消按钮 */
const cancel = () => {
dialog.visible = false
reset()
}
/** 表单重置 */
const reset = () => {
selectedIds.value = []
form.value = {
ids: [],
reason: '',
remark: '',
}
submitting.value = false
formRef.value?.resetFields()
}
defineExpose({ open })
</script>
<style scoped lang="scss">
.pool-alert {
margin-bottom: 16px;
}
.pool-reason-hint {
margin-top: 8px;
font-size: 12px;
color: var(--el-text-color-placeholder);
}
.hint-list {
padding-left: 20px;
margin: 4px 0 0;
list-style: disc;
}
.pool-tip-alert {
margin-top: 16px;
}
.tip-list {
padding-left: 20px;
margin: 0;
list-style: disc;
}
</style>