<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.department"
|
placeholder="请选择部门"
|
clearable>
|
<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.status"
|
placeholder="请选择状态"
|
clearable>
|
<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-button type="primary"
|
@click="handleSearch">搜索</el-button>
|
<el-button @click="resetSearch">重置</el-button>
|
<el-button type="primary"
|
style="float: right;"
|
@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="120" />
|
<el-table-column prop="phone"
|
label="联系电话"
|
width="140" />
|
<el-table-column prop="email"
|
label="邮箱"
|
width="200" />
|
<el-table-column prop="department"
|
label="部门"
|
width="100" />
|
<el-table-column prop="position"
|
label="职位"
|
width="100" />
|
<el-table-column prop="hireDate"
|
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 prop="permissions"
|
label="权限">
|
<template #default="scope">
|
<el-tag v-for="perm in scope.row.permissionsList"
|
:key="perm"
|
size="small"
|
style="margin-right: 5px;">
|
{{ perm }}
|
</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="handlePermissions(scope.row)">权限</el-button>
|
<el-button link
|
type="danger"
|
@click="handleDelete(scope.row)">删除</el-button>
|
</template>
|
</el-table-column>
|
</el-table>
|
<!-- 分页 -->
|
<pagination :total="total"
|
layout="total, sizes, prev, pager, next, jumper"
|
:page="pagination.current"
|
:limit="pagination.size"
|
@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="phone">
|
<el-input v-model="form.phone"
|
placeholder="请输入联系电话"></el-input>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row :gutter="20">
|
<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-col :span="12">
|
<el-form-item label="部门"
|
prop="department">
|
<el-select v-model="form.department"
|
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-row :gutter="20">
|
<el-col :span="12">
|
<el-form-item label="职位"
|
prop="position">
|
<el-input v-model="form.position"
|
placeholder="请输入职位"></el-input>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="入职日期"
|
prop="hireDate">
|
<el-date-picker v-model="form.hireDate"
|
type="date"
|
placeholder="选择入职日期"
|
style="width: 100%"
|
format="YYYY-MM-DD"
|
value-format="YYYY-MM-DD" />
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row :gutter="20">
|
<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="permissionDialogVisible"
|
title="权限设置"
|
width="500px">
|
<el-form label-width="100px">
|
<el-form-item label="业务员姓名">
|
<span>{{ currentSalesperson.name }}</span>
|
</el-form-item>
|
<el-form-item label="权限设置">
|
<el-checkbox-group v-model="currentPermissions">
|
<el-checkbox label="订单管理">订单管理</el-checkbox>
|
<el-checkbox label="客户管理">客户管理</el-checkbox>
|
<el-checkbox label="财务管理">财务管理</el-checkbox>
|
<el-checkbox label="发货管理">发货管理</el-checkbox>
|
<el-checkbox label="报表查看">报表查看</el-checkbox>
|
<el-checkbox label="系统设置">系统设置</el-checkbox>
|
</el-checkbox-group>
|
</el-form-item>
|
</el-form>
|
<template #footer>
|
<div class="dialog-footer">
|
<el-button type="primary"
|
@click="savePermissions">确 定</el-button>
|
<el-button @click="permissionDialogVisible = false">取 消</el-button>
|
</div>
|
</template>
|
</el-dialog>
|
</div>
|
</template>
|
|
<script setup>
|
import { ref, reactive, computed, onMounted } from "vue";
|
import { ElMessage, ElMessageBox } from "element-plus";
|
import {
|
listPage,
|
add,
|
update,
|
deleteSalespersonManagement,
|
} from "@/api/salesManagement/salespersonManagement.js";
|
import { Plus, Search } from "@element-plus/icons-vue";
|
import Pagination from "@/components/PIMTable/Pagination.vue";
|
|
const salespersonList = ref([]);
|
const total = ref(0);
|
|
onMounted(() => {
|
getList();
|
});
|
const getList = () => {
|
loading.value = true;
|
listPage({ ...pagination, ...searchForm }).then(res => {
|
salespersonList.value = res.data.records;
|
total.value = res.data.total;
|
loading.value = false;
|
});
|
};
|
|
// 响应式数据
|
const loading = ref(false);
|
const searchForm = reactive({
|
name: "",
|
department: "",
|
status: "",
|
});
|
|
const pagination = reactive({
|
current: 1,
|
size: 10,
|
});
|
|
const dialogVisible = ref(false);
|
const dialogTitle = ref("新增业务员");
|
const form = reactive({
|
name: "",
|
phone: "",
|
email: "",
|
department: "",
|
position: "",
|
hireDate: "",
|
status: "在职",
|
});
|
|
const rules = {
|
name: [{ required: true, message: "请输入姓名", trigger: "blur" }],
|
phone: [{ required: true, message: "请输入联系电话", trigger: "blur" }],
|
email: [{ required: true, message: "请输入邮箱", trigger: "blur" }],
|
department: [{ required: true, message: "请选择部门", trigger: "change" }],
|
position: [{ required: true, message: "请输入职位", trigger: "blur" }],
|
hireDate: [{ required: true, message: "请选择入职日期", trigger: "change" }],
|
status: [{ required: true, message: "请选择状态", trigger: "change" }],
|
};
|
|
const isEdit = ref(false);
|
const editId = ref(null);
|
const permissionDialogVisible = ref(false);
|
const currentSalesperson = ref({});
|
const currentPermissions = ref([]);
|
const formRef = ref();
|
|
// 计算属性
|
const filteredList = computed(() => {
|
let list = salespersonList.value;
|
if (searchForm.name) {
|
list = list.filter(item => item.name.includes(searchForm.name));
|
}
|
if (searchForm.department) {
|
list = list.filter(item => item.department === searchForm.department);
|
}
|
if (searchForm.status) {
|
list = list.filter(item => item.status === searchForm.status);
|
}
|
return list;
|
});
|
|
// 方法
|
const getStatusType = status => {
|
const statusMap = {
|
在职: "success",
|
离职: "danger",
|
试用期: "warning",
|
};
|
return statusMap[status] || "info";
|
};
|
|
const handleSearch = () => {
|
getList();
|
// 搜索逻辑已在computed中处理
|
};
|
|
const resetSearch = () => {
|
searchForm.name = "";
|
searchForm.department = "";
|
searchForm.status = "";
|
};
|
|
const handleAdd = () => {
|
dialogTitle.value = "新增业务员";
|
isEdit.value = false;
|
form.name = "";
|
form.phone = "";
|
form.email = "";
|
form.department = "";
|
form.position = "";
|
form.hireDate = "";
|
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(() => {
|
let ids = [row.id];
|
deleteSalespersonManagement(ids).then(res => {
|
if (res.code === 200) {
|
ElMessage.success("删除成功");
|
getList();
|
}
|
});
|
});
|
};
|
|
const handlePermissions = row => {
|
currentSalesperson.value = row;
|
currentPermissions.value = row.permissions.split(",");
|
permissionDialogVisible.value = true;
|
};
|
|
const savePermissions = () => {
|
let splice = currentPermissions.value;
|
if (splice[0] === "") {
|
splice.splice(0, 1);
|
}
|
currentSalesperson.value.permissions = splice.join(",");
|
update(currentSalesperson.value).then(res => {
|
if (res.code === 200) {
|
ElMessage.success("权限设置成功");
|
permissionDialogVisible.value = false;
|
getList();
|
}
|
});
|
};
|
|
const handleSubmit = () => {
|
formRef.value.validate(valid => {
|
if (valid) {
|
if (isEdit.value) {
|
// 编辑
|
update(form).then(res => {
|
if (res.code === 200) {
|
ElMessage.success("编辑成功");
|
dialogVisible.value = false;
|
getList();
|
}
|
});
|
} else {
|
add(form).then(res => {
|
if (res.code === 200) {
|
ElMessage.success("新增成功");
|
dialogVisible.value = false;
|
getList();
|
}
|
});
|
}
|
}
|
});
|
};
|
|
const handleCurrentChange = val => {
|
pagination.value.currentPage = val.page;
|
pagination.value.pageSize = val.limit;
|
};
|
</script>
|
|
<style scoped>
|
.search-row {
|
margin-bottom: 20px;
|
}
|
</style>
|