Files
admin-ui/src/views/customerService/account/index.vue

248 lines
6.4 KiB
Vue
Raw Normal View History

2025-11-22 16:39:01 +08:00
<template>
2025-11-24 16:55:18 +08:00
<div class="system-role-container">
<el-card shadow="hover">
<div class="system-user-search mb15">
<el-form :inline="true">
<el-form-item label="客服ID">
2025-11-28 17:17:07 +08:00
<el-input size="default" v-model="tableData.param.customerServiceId" placeholder="请输入客服ID" class="w-50 m-2" clearable />
2025-11-24 16:55:18 +08:00
</el-form-item>
<el-form-item label="客服平台" prop="status" style="width: 200px">
2025-11-25 17:02:31 +08:00
<el-select v-model="tableData.param.platform" placeholder="请选择客服平台" clearable size="default" style="width: 240px">
2025-11-28 17:17:07 +08:00
<el-option label="小红书" value="小红书" />
<el-option label="抖音" value="抖音" />
<el-option label="快手" value="快手" />
2025-11-24 16:55:18 +08:00
</el-select>
</el-form-item>
<el-form-item>
2025-11-25 17:02:31 +08:00
<el-button size="default" type="primary" class="ml10" @click="handleSearch">
2025-11-24 16:55:18 +08:00
<el-icon>
<ele-Search />
</el-icon>
查询
</el-button>
<el-button size="default" type="success" class="ml10" @click="onOpenAddRole">
<el-icon>
<ele-FolderAdd />
</el-icon>
新增客服
</el-button>
</el-form-item>
</el-form>
</div>
2025-11-25 17:02:31 +08:00
<el-table :data="tableData.data" style="width: 100%" v-loading="tableData.loading">
2025-11-24 16:55:18 +08:00
<el-table-column type="index" label="序号" width="60" />
2025-11-28 17:17:07 +08:00
<el-table-column prop="customerServiceId" label="客服ID" show-overflow-tooltip></el-table-column>
2025-11-24 16:55:18 +08:00
<el-table-column prop="status" label="客服状态" show-overflow-tooltip>
<template #default="scope">
2025-11-28 17:17:07 +08:00
<el-button
size="small"
:type="scope.row.status === 1 ? 'success' : 'info'"
@click="handleStatusChange(scope.row)"
:loading="scope.row.statusLoading"
>
{{ scope.row.status === 1 ? '启用' : '禁用' }}
</el-button>
2025-11-24 16:55:18 +08:00
</template>
</el-table-column>
2025-11-28 17:17:07 +08:00
<el-table-column prop="platform" label="客服平台" show-overflow-tooltip></el-table-column>
2025-11-25 17:02:31 +08:00
<el-table-column prop="creator" label="创建人" show-overflow-tooltip></el-table-column>
2025-11-28 17:17:07 +08:00
<el-table-column prop="modifier" label="修改人" show-overflow-tooltip></el-table-column>
<el-table-column prop="createdAtString" label="创建时间" show-overflow-tooltip></el-table-column>
<el-table-column prop="updatedAtString" label="修改时间" show-overflow-tooltip></el-table-column>
2025-11-24 16:55:18 +08:00
<el-table-column label="操作" width="220">
<template #default="scope">
2025-11-28 17:17:07 +08:00
<el-button style="color: deepskyblue" size="small" text type="primary" @click="onOpenEditRole(scope.row)">
2025-11-25 17:02:31 +08:00
<el-icon><ele-EditPen /></el-icon>修改
</el-button>
2025-11-24 16:55:18 +08:00
</template>
</el-table-column>
</el-table>
<pagination
v-show="tableData.total > 0"
:total="tableData.total"
v-model:page="tableData.param.pageNum"
v-model:limit="tableData.param.pageSize"
2025-11-28 17:17:07 +08:00
@pagination="getList"
2025-11-24 16:55:18 +08:00
/>
</el-card>
2025-11-28 17:17:07 +08:00
<EditRole ref="editRoleRef" @getRoleList="getList" />
2025-11-24 16:55:18 +08:00
</div>
2025-11-22 16:39:01 +08:00
</template>
2025-11-25 17:02:31 +08:00
<script lang="ts" setup>
2025-11-28 17:17:07 +08:00
import { ref, reactive, onMounted } from 'vue';
2025-11-22 16:39:01 +08:00
import { ElMessageBox, ElMessage } from 'element-plus';
import EditRole from '/@/views/customerService/account/component/editRole.vue';
2025-11-28 17:17:07 +08:00
import { getaccountAdd, getaccountList, updatestate } from '/@/api/customerService/account';
import { number } from 'echarts';
2025-11-25 17:02:31 +08:00
// 定义类型接口
interface TableDataItem {
2025-11-28 17:17:07 +08:00
id: string;
customerServiceId: string;
2025-11-24 16:55:18 +08:00
status: number;
2025-11-28 17:17:07 +08:00
platform: string;
creator: string;
modifier: string;
createdAt: number;
createdAtString: string;
updatedAt: number;
updatedAtString: string;
statusLoading?: boolean;
2025-11-22 16:39:01 +08:00
}
2025-11-25 17:02:31 +08:00
interface TableParam {
2025-11-28 17:17:07 +08:00
customerServiceId: string;
2025-11-25 17:02:31 +08:00
platform: string;
pageNum: number;
pageSize: number;
2025-11-28 17:17:07 +08:00
status: number;
2025-11-22 16:39:01 +08:00
}
2025-11-25 17:02:31 +08:00
interface TableState {
data: TableDataItem[];
total: number;
loading: boolean;
param: TableParam;
}
// 响应式数据
const tableData = reactive<TableState>({
data: [],
total: 0,
loading: false,
param: {
2025-11-28 17:17:07 +08:00
customerServiceId: '',
2025-11-25 17:02:31 +08:00
platform: '',
pageNum: 1,
pageSize: 10,
2025-11-28 17:17:07 +08:00
status: 0,
2025-11-25 17:02:31 +08:00
},
});
2025-11-22 16:39:01 +08:00
2025-11-25 17:02:31 +08:00
// 模板引用
const editRoleRef = ref<InstanceType<typeof EditRole>>();
/**
2025-11-28 17:17:07 +08:00
* 获取客服账号列表
2025-11-25 17:02:31 +08:00
*/
2025-11-28 17:17:07 +08:00
const getList = async () => {
2025-11-25 17:02:31 +08:00
try {
tableData.loading = true;
2025-11-28 17:17:07 +08:00
const res = await getaccountList(tableData.param);
tableData.data = (res.data.list || []).map((item: TableDataItem) => ({
...item,
statusLoading: false,
}));
tableData.total = res.data.total || 0;
2025-11-25 17:02:31 +08:00
} catch (error) {
2025-11-28 17:17:07 +08:00
console.error('获取客服账号列表失败:', error);
2025-11-25 17:02:31 +08:00
ElMessage.error('获取数据失败');
} finally {
tableData.loading = false;
}
};
2025-11-28 17:17:07 +08:00
/**
* 处理客服状态切换
* @param row - 客服数据
*/
const handleStatusChange = async (row: TableDataItem) => {
try {
await ElMessageBox.confirm(`确定要${row.status === 1 ? '禁用' : '启用'}客服账号 "${row.customerServiceId}" 吗?`, '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
});
row.statusLoading = true;
const newStatus = row.status === 1 ? 0 : 1;
// 调用状态更新接口
await updatestate({
id: row.id,
status: newStatus,
});
ElMessage.success(`客服账号已${newStatus === 1 ? '启用' : '禁用'}`);
// 重新获取数据确保数据同步
await getList();
} catch (error) {
if (error === 'cancel') {
console.log('用户取消状态切换');
return;
}
console.error('状态切换失败:', error);
ElMessage.error('状态切换失败');
} finally {
setTimeout(() => {
row.statusLoading = false;
}, 300);
}
};
2025-11-25 17:02:31 +08:00
/**
* 处理搜索
*/
const handleSearch = () => {
2025-11-28 17:17:07 +08:00
tableData.param.pageNum = 1;
getList();
2025-11-25 17:02:31 +08:00
};
/**
* 处理分页变化
2025-11-28 17:17:07 +08:00
* @param pagination - 分页参数 { page: number, limit: number }
2025-11-25 17:02:31 +08:00
*/
const handlePaginationChange = (pagination: { page: number; limit: number }) => {
2025-11-28 17:17:07 +08:00
console.log('分页参数:', pagination.limit); // 调试用
2025-11-25 17:02:31 +08:00
tableData.param.pageNum = pagination.page;
tableData.param.pageSize = pagination.limit;
2025-11-28 17:17:07 +08:00
getList();
2025-11-25 17:02:31 +08:00
};
/**
2025-11-28 17:17:07 +08:00
* 打开新增客服对话框
2025-11-25 17:02:31 +08:00
*/
const onOpenAddRole = () => {
2025-11-28 17:17:07 +08:00
editRoleRef.value?.openDialog();
2025-11-25 17:02:31 +08:00
};
/**
2025-11-28 17:17:07 +08:00
* 打开编辑客服对话框
2025-11-25 17:02:31 +08:00
*/
const onOpenEditRole = (row: TableDataItem) => {
2025-11-28 17:17:07 +08:00
editRoleRef.value?.openDialog(row);
2025-11-25 17:02:31 +08:00
};
// 生命周期
onMounted(() => {
2025-11-28 17:17:07 +08:00
getList();
2025-11-22 16:39:01 +08:00
});
</script>
2025-11-25 17:02:31 +08:00
<style scoped>
.system-user-search {
margin-bottom: 15px;
}
.mb15 {
margin-bottom: 15px;
}
.ml10 {
margin-left: 10px;
}
.w-50 {
width: 240px;
}
.system-role-container {
padding: 20px;
}
:deep(.el-table) {
margin-top: 10px;
}
</style>