<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.permissions" :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="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="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 @click="dialogVisible = false">取 消</el-button>
|
<el-button type="primary" @click="handleSubmit">确 定</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 @click="permissionDialogVisible = false">取 消</el-button>
|
<el-button type="primary" @click="savePermissions">确 定</el-button>
|
</div>
|
</template>
|
</el-dialog>
|
</div>
|
</template>
|
|
<script setup>
|
import { ref, reactive, computed, nextTick } 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: '',
|
department: '',
|
status: ''
|
})
|
|
const salespersonList = ref([
|
{
|
id: 1,
|
name: '陈志强',
|
phone: '13800138001',
|
email: 'chenzhiqiang@company.com',
|
department: '销售部',
|
position: '销售经理',
|
hireDate: '2023-01-15',
|
status: '在职',
|
permissions: ['订单管理', '客户管理', '财务管理']
|
},
|
{
|
id: 2,
|
name: '刘雅婷',
|
phone: '13800138002',
|
email: 'liuyating@company.com',
|
department: '市场部',
|
position: '市场专员',
|
hireDate: '2023-03-20',
|
status: '在职',
|
permissions: ['客户管理', '报表查看']
|
},
|
{
|
id: 3,
|
name: '王建国',
|
phone: '13800138003',
|
email: 'wangjianguo@company.com',
|
department: '客服部',
|
position: '客服主管',
|
hireDate: '2022-11-10',
|
status: '在职',
|
permissions: ['客户管理', '发货管理']
|
}
|
])
|
|
const pagination = ref({
|
total: 3,
|
currentPage: 1,
|
pageSize: 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 = () => {
|
// 搜索逻辑已在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(() => {
|
const index = salespersonList.value.findIndex(item => item.id === row.id)
|
if (index > -1) {
|
salespersonList.value.splice(index, 1)
|
pagination.value.total--
|
ElMessage.success('删除成功')
|
}
|
})
|
}
|
|
const handlePermissions = (row) => {
|
currentSalesperson.value = row
|
currentPermissions.value = [...row.permissions]
|
permissionDialogVisible.value = true
|
}
|
|
const savePermissions = () => {
|
const index = salespersonList.value.findIndex(item => item.id === currentSalesperson.value.id)
|
if (index > -1) {
|
salespersonList.value[index].permissions = [...currentPermissions.value]
|
ElMessage.success('权限设置成功')
|
permissionDialogVisible.value = false
|
}
|
}
|
|
const handleSubmit = () => {
|
formRef.value.validate((valid) => {
|
if (valid) {
|
if (isEdit.value) {
|
// 编辑
|
const index = salespersonList.value.findIndex(item => item.id === editId.value)
|
if (index > -1) {
|
salespersonList.value[index] = { ...form, id: editId.value }
|
ElMessage.success('编辑成功')
|
}
|
} else {
|
// 新增
|
const newId = Math.max(...salespersonList.value.map(item => item.id)) + 1
|
salespersonList.value.push({
|
...form,
|
id: newId,
|
permissions: []
|
})
|
pagination.value.total++
|
ElMessage.success('新增成功')
|
}
|
dialogVisible.value = false
|
}
|
})
|
}
|
|
const handleCurrentChange = (val) => {
|
pagination.value.currentPage = val.page
|
pagination.value.pageSize = val.limit
|
}
|
</script>
|
|
<style scoped>
|
.search-row {
|
margin-bottom: 20px;
|
}
|
</style>
|