| | |
| | | </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;"> |
| | | <el-tag v-for="perm in scope.row.permissionsList" :key="perm" size="small" style="margin-right: 5px;"> |
| | | {{ perm }} |
| | | </el-tag> |
| | | </template> |
| | |
| | | |
| | | <!-- 分页 --> |
| | | <pagination |
| | | :total="pagination.total" |
| | | :total="total" |
| | | layout="total, sizes, prev, pager, next, jumper" |
| | | :page="pagination.currentPage" |
| | | :limit="pagination.pageSize" |
| | | :page="pagination.current" |
| | | :limit="pagination.size" |
| | | @pagination="handleCurrentChange" |
| | | /> |
| | | </el-card> |
| | |
| | | </template> |
| | | |
| | | <script setup> |
| | | import { ref, reactive, computed, nextTick } from 'vue' |
| | | 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) |
| | |
| | | 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 pagination = reactive({ |
| | | current: 1, |
| | | size: 10 |
| | | }) |
| | | |
| | | const dialogVisible = ref(false) |
| | |
| | | } |
| | | |
| | | const handleSearch = () => { |
| | | getList() |
| | | // 搜索逻辑已在computed中处理 |
| | | } |
| | | |
| | |
| | | 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-- |
| | | 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] |
| | | currentPermissions.value = row.permissions.split(",") |
| | | 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] |
| | | 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 = () => { |
| | |
| | | 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 } |
| | | update(form).then(res => { |
| | | if(res.code === 200){ |
| | | 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 |
| | | getList() |
| | | } |
| | | }) |
| | | } else { |
| | | add(form).then(res => { |
| | | if(res.code === 200){ |
| | | ElMessage.success('新增成功') |
| | | dialogVisible.value = false |
| | | getList() |
| | | } |
| | | }) |
| | | |
| | | } |
| | | |
| | | } |
| | | }) |
| | | } |