<template>
|
<div class="app-container">
|
<el-card class="box-card">
|
<!-- 搜索区域 -->
|
<el-row :gutter="20"
|
class="search-row">
|
<el-col :span="6">
|
<el-input v-model="searchForm.name"
|
placeholder="请输入客户名称"
|
clearable
|
@keyup.enter="handleSearch">
|
<template #prefix>
|
<el-icon>
|
<Search />
|
</el-icon>
|
</template>
|
</el-input>
|
</el-col>
|
<el-col :span="6">
|
<el-select v-model="searchForm.region"
|
placeholder="请选择区域"
|
clearable>
|
<el-option label="华东区"
|
value="华东区"></el-option>
|
<el-option label="华南区"
|
value="华南区"></el-option>
|
<el-option label="华北区"
|
value="华北区"></el-option>
|
<el-option label="西南区"
|
value="西南区"></el-option>
|
</el-select>
|
</el-col>
|
<el-col :span="6">
|
<el-select v-model="searchForm.level"
|
placeholder="请选择客户等级"
|
clearable>
|
<el-option label="VIP客户"
|
value="VIP客户"></el-option>
|
<el-option label="重要客户"
|
value="重要客户"></el-option>
|
<el-option label="普通客户"
|
value="普通客户"></el-option>
|
</el-select>
|
</el-col>
|
<el-col :span="6">
|
<el-button type="primary"
|
@click="handleSearch">搜索</el-button>
|
<el-button @click="resetSearch">重置</el-button>
|
<el-button style="float: right;"
|
type="primary"
|
@click="handleAdd">
|
新增客户
|
</el-button>
|
</el-col>
|
</el-row>
|
<!-- 客户列表 -->
|
<el-table :data="filteredList"
|
style="width: 100%"
|
v-loading="loading"
|
border
|
stripe
|
height="calc(100vh - 22em)">
|
<el-table-column prop="id"
|
label="ID"
|
width="80"
|
align="center" />
|
<el-table-column prop="name"
|
label="客户名称"
|
width="150" />
|
<el-table-column prop="contactPerson"
|
label="联系人"
|
width="100" />
|
<el-table-column prop="phone"
|
label="联系电话"
|
width="140" />
|
<el-table-column prop="email"
|
label="邮箱" />
|
<el-table-column prop="region"
|
label="区域"
|
width="100" />
|
<el-table-column prop="level"
|
label="客户等级"
|
width="100">
|
<template #default="scope">
|
<el-tag :type="getLevelType(scope.row.level)">
|
{{ scope.row.level }}
|
</el-tag>
|
</template>
|
</el-table-column>
|
<el-table-column prop="salesperson"
|
label="负责业务员"
|
width="120" />
|
<el-table-column prop="status"
|
label="状态"
|
width="80">
|
<template #default="scope">
|
<el-tag :type="getStatusType(scope.row.status)">
|
{{ scope.row.status }}
|
</el-tag>
|
</template>
|
</el-table-column>
|
<el-table-column label="操作"
|
width="200"
|
fixed="right"
|
align="center">
|
<template #default="scope">
|
<el-button link
|
type="primary"
|
@click="handleEdit(scope.row)">编辑</el-button>
|
<el-button link
|
type="primary"
|
@click="handleAllocation(scope.row)">分配</el-button>
|
<el-button link
|
type="danger"
|
@click="handleDelete(scope.row)">删除</el-button>
|
</template>
|
</el-table-column>
|
</el-table>
|
<!-- 分页 -->
|
<pagination :total="pagination.total"
|
layout="total, sizes, prev, pager, next, jumper"
|
:page="pagination.currentPage"
|
:limit="pagination.pageSize"
|
@pagination="handleCurrentChange" />
|
</el-card>
|
<!-- 新增/编辑对话框 -->
|
<el-dialog v-model="dialogVisible"
|
:title="dialogTitle"
|
width="600px">
|
<el-form :model="form"
|
:rules="rules"
|
ref="formRef"
|
label-width="100px">
|
<el-row :gutter="20">
|
<el-col :span="12">
|
<el-form-item label="客户名称"
|
prop="name">
|
<el-input v-model="form.name"
|
placeholder="请输入客户名称"></el-input>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="联系人"
|
prop="contactPerson">
|
<el-input v-model="form.contactPerson"
|
placeholder="请输入联系人"></el-input>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row :gutter="20">
|
<el-col :span="12">
|
<el-form-item label="联系电话"
|
prop="phone">
|
<el-input v-model="form.phone"
|
placeholder="请输入联系电话"></el-input>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="邮箱"
|
prop="email">
|
<el-input v-model="form.email"
|
placeholder="请输入邮箱"></el-input>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row :gutter="20">
|
<el-col :span="12">
|
<el-form-item label="区域"
|
prop="region">
|
<el-select v-model="form.region"
|
placeholder="请选择区域"
|
style="width: 100%">
|
<el-option label="华东区"
|
value="华东区"></el-option>
|
<el-option label="华南区"
|
value="华南区"></el-option>
|
<el-option label="华北区"
|
value="华北区"></el-option>
|
<el-option label="西南区"
|
value="西南区"></el-option>
|
</el-select>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="客户等级"
|
prop="level">
|
<el-select v-model="form.level"
|
placeholder="请选择客户等级"
|
style="width: 100%">
|
<el-option label="VIP客户"
|
value="VIP客户"></el-option>
|
<el-option label="重要客户"
|
value="重要客户"></el-option>
|
<el-option label="普通客户"
|
value="普通客户"></el-option>
|
</el-select>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row :gutter="20">
|
<el-col :span="12">
|
<el-form-item label="负责业务员"
|
prop="salesperson">
|
<el-select v-model="form.salesperson"
|
placeholder="请选择业务员"
|
style="width: 100%">
|
<el-option label="陈志强"
|
value="陈志强"></el-option>
|
<el-option label="刘雅婷"
|
value="刘雅婷"></el-option>
|
<el-option label="王建国"
|
value="王建国"></el-option>
|
</el-select>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="状态"
|
prop="status">
|
<el-select v-model="form.status"
|
placeholder="请选择状态"
|
style="width: 100%">
|
<el-option label="活跃"
|
value="活跃"></el-option>
|
<el-option label="潜在"
|
value="潜在"></el-option>
|
<el-option label="流失"
|
value="流失"></el-option>
|
</el-select>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
</el-form>
|
<template #footer>
|
<div class="dialog-footer">
|
<el-button type="primary"
|
@click="handleSubmit">确 定</el-button>
|
<el-button @click="dialogVisible = false">取 消</el-button>
|
</div>
|
</template>
|
</el-dialog>
|
<!-- 客户分配对话框 -->
|
<el-dialog v-model="allocationDialogVisible"
|
title="客户分配"
|
width="500px">
|
<el-form label-width="100px">
|
<el-form-item label="客户名称">
|
<span>{{ currentCustomer.name }}</span>
|
</el-form-item>
|
<el-form-item label="当前业务员">
|
<span>{{ currentCustomer.salesperson }}</span>
|
</el-form-item>
|
<el-form-item label="重新分配">
|
<el-select v-model="newSalesperson"
|
placeholder="请选择新业务员"
|
style="width: 100%">
|
<el-option label="陈志强"
|
value="陈志强"></el-option>
|
<el-option label="刘雅婷"
|
value="刘雅婷"></el-option>
|
<el-option label="王建国"
|
value="王建国"></el-option>
|
</el-select>
|
</el-form-item>
|
<el-form-item label="分配原因">
|
<el-input v-model="allocationReason"
|
type="textarea"
|
rows="3"
|
placeholder="请输入分配原因"></el-input>
|
</el-form-item>
|
</el-form>
|
<template #footer>
|
<div class="dialog-footer">
|
<el-button type="primary"
|
@click="saveAllocation">确 定</el-button>
|
<el-button @click="allocationDialogVisible = false">取 消</el-button>
|
</div>
|
</template>
|
</el-dialog>
|
</div>
|
</template>
|
|
<script setup>
|
import { ref, reactive, computed } from "vue";
|
import { ElMessage, ElMessageBox } from "element-plus";
|
import { Plus, Search } from "@element-plus/icons-vue";
|
import Pagination from "@/components/PIMTable/Pagination.vue";
|
|
// 响应式数据
|
const loading = ref(false);
|
const searchForm = reactive({
|
name: "",
|
region: "",
|
level: "",
|
});
|
|
const customerList = ref([
|
{
|
id: 1,
|
name: "上海科技有限公司",
|
contactPerson: "陈志强",
|
phone: "021-12345678",
|
email: "zhang@shanghai-tech.com",
|
region: "华东区",
|
level: "VIP客户",
|
salesperson: "陈志强",
|
status: "活跃",
|
},
|
{
|
id: 2,
|
name: "深圳电子有限公司",
|
contactPerson: "刘雅婷",
|
phone: "0755-87654321",
|
email: "li@shenzhen-elec.com",
|
region: "华南区",
|
level: "重要客户",
|
salesperson: "刘雅婷",
|
status: "活跃",
|
},
|
{
|
id: 3,
|
name: "北京贸易公司",
|
contactPerson: "王建国",
|
phone: "010-11223344",
|
email: "wang@beijing-trade.com",
|
region: "华北区",
|
level: "普通客户",
|
salesperson: "王建国",
|
status: "潜在",
|
},
|
]);
|
|
const pagination = reactive({
|
total: 3,
|
currentPage: 1,
|
pageSize: 10,
|
});
|
|
const dialogVisible = ref(false);
|
const dialogTitle = ref("新增客户");
|
const form = reactive({
|
name: "",
|
contactPerson: "",
|
phone: "",
|
email: "",
|
region: "",
|
level: "",
|
salesperson: "",
|
status: "活跃",
|
});
|
|
const rules = {
|
name: [{ required: true, message: "请输入客户名称", trigger: "blur" }],
|
contactPerson: [{ required: true, message: "请输入联系人", trigger: "blur" }],
|
phone: [{ required: true, message: "请输入联系电话", trigger: "blur" }],
|
email: [{ required: true, message: "请输入邮箱", trigger: "blur" }],
|
region: [{ required: true, message: "请选择区域", trigger: "change" }],
|
level: [{ required: true, message: "请选择客户等级", trigger: "change" }],
|
salesperson: [{ required: true, message: "请选择业务员", trigger: "change" }],
|
status: [{ required: true, message: "请选择状态", trigger: "change" }],
|
};
|
|
const isEdit = ref(false);
|
const editId = ref(null);
|
const allocationDialogVisible = ref(false);
|
const currentCustomer = ref({});
|
const newSalesperson = ref("");
|
const allocationReason = ref("");
|
const formRef = ref();
|
|
// 计算属性
|
const filteredList = computed(() => {
|
let list = customerList.value;
|
if (searchForm.name) {
|
list = list.filter(item => item.name.includes(searchForm.name));
|
}
|
if (searchForm.region) {
|
list = list.filter(item => item.region === searchForm.region);
|
}
|
if (searchForm.level) {
|
list = list.filter(item => item.level === searchForm.level);
|
}
|
return list;
|
});
|
|
// 方法
|
const getLevelType = level => {
|
const levelMap = {
|
VIP客户: "danger",
|
重要客户: "warning",
|
普通客户: "info",
|
};
|
return levelMap[level] || "info";
|
};
|
|
const getStatusType = status => {
|
const statusMap = {
|
活跃: "success",
|
潜在: "warning",
|
流失: "danger",
|
};
|
return statusMap[status] || "info";
|
};
|
|
const handleSearch = () => {
|
// 搜索逻辑已在computed中处理
|
};
|
|
const resetSearch = () => {
|
searchForm.name = "";
|
searchForm.region = "";
|
searchForm.level = "";
|
};
|
|
const handleAdd = () => {
|
dialogTitle.value = "新增客户";
|
isEdit.value = false;
|
form.name = "";
|
form.contactPerson = "";
|
form.phone = "";
|
form.email = "";
|
form.region = "";
|
form.level = "";
|
form.salesperson = "";
|
form.status = "活跃";
|
dialogVisible.value = true;
|
};
|
|
const handleEdit = row => {
|
dialogTitle.value = "编辑客户";
|
isEdit.value = true;
|
editId.value = row.id;
|
Object.assign(form, row);
|
dialogVisible.value = true;
|
};
|
|
const handleDelete = row => {
|
ElMessageBox.confirm("确认删除该客户吗?", "提示", {
|
confirmButtonText: "确定",
|
cancelButtonText: "取消",
|
type: "warning",
|
}).then(() => {
|
const index = customerList.value.findIndex(item => item.id === row.id);
|
if (index > -1) {
|
customerList.value.splice(index, 1);
|
pagination.total--;
|
ElMessage.success("删除成功");
|
}
|
});
|
};
|
|
const handleAllocation = row => {
|
currentCustomer.value = row;
|
newSalesperson.value = "";
|
allocationReason.value = "";
|
allocationDialogVisible.value = true;
|
};
|
|
const saveAllocation = () => {
|
if (!newSalesperson.value) {
|
ElMessage.warning("请选择新业务员");
|
return;
|
}
|
|
const index = customerList.value.findIndex(
|
item => item.id === currentCustomer.value.id
|
);
|
if (index > -1) {
|
customerList.value[index].salesperson = newSalesperson.value;
|
ElMessage.success("客户分配成功");
|
allocationDialogVisible.value = false;
|
}
|
};
|
|
const handleSubmit = () => {
|
formRef.value.validate(valid => {
|
if (valid) {
|
if (isEdit.value) {
|
// 编辑
|
const index = customerList.value.findIndex(
|
item => item.id === editId.value
|
);
|
if (index > -1) {
|
customerList.value[index] = { ...form, id: editId.value };
|
ElMessage.success("编辑成功");
|
}
|
} else {
|
// 新增
|
const newId = Math.max(...customerList.value.map(item => item.id)) + 1;
|
customerList.value.push({
|
...form,
|
id: newId,
|
});
|
pagination.total++;
|
ElMessage.success("新增成功");
|
}
|
dialogVisible.value = false;
|
}
|
});
|
};
|
|
const handleCurrentChange = val => {
|
pagination.currentPage = val.page;
|
pagination.pageSize = val.limit;
|
};
|
</script>
|
|
<style scoped>
|
.search-row {
|
margin-bottom: 20px;
|
}
|
</style>
|