修改删除员工,以及删除客户单位的js
This commit is contained in:
@@ -162,6 +162,7 @@ const submitCustomer = async () => {
|
||||
const res = await customerApi.addCustomerName({
|
||||
company_name: customerForm.value.company_name
|
||||
})
|
||||
console.log('返回数据',res)
|
||||
if (res.code === 200) {
|
||||
ElMessage.success('客户单位创建成功')
|
||||
customerDialogVisible.value = false
|
||||
@@ -173,17 +174,47 @@ const submitCustomer = async () => {
|
||||
}
|
||||
|
||||
const handleDeleteCustomer = (row) => {
|
||||
ElMessageBox.confirm(`确定删除单位【${row.company_name}】吗?这将导致关联员工数据异常!`, '警告', {
|
||||
type: 'error',
|
||||
confirmButtonText: '确定删除',
|
||||
cancelButtonText: '取消'
|
||||
}).then(async () => {
|
||||
// 这里应调用你后端的删除接口,例如:
|
||||
// await customerApi.deleteCustomer(row.customer_id)
|
||||
ElMessage.warning('请确保后端已实现删除逻辑')
|
||||
fetchCustomers()
|
||||
}).catch(() => {})
|
||||
}
|
||||
ElMessageBox.confirm(
|
||||
`确定删除单位【${row.company_name}】吗?这将同时移除该单位下所有员工,操作不可恢复!`,
|
||||
'极其危险的操作',
|
||||
{
|
||||
confirmButtonText: '确定彻底删除',
|
||||
cancelButtonText: '取消',
|
||||
type: 'error',
|
||||
// 让确定按钮看起来更显眼(红色)
|
||||
confirmButtonClass: 'el-button--danger',
|
||||
}
|
||||
).then(async () => {
|
||||
// 1. 开启全局或表格的 loading 状态(如果有的话)
|
||||
loading.value = true;
|
||||
|
||||
try {
|
||||
// 2. 调用接口,注意参数要包装成对象,匹配后端 $this->request->param('customer_id')
|
||||
const res = await customerApi.deleteCustomer(row.customer_id);
|
||||
|
||||
// 3. 根据返回结果进行反馈
|
||||
if (res.code === 200) {
|
||||
ElMessage.success({
|
||||
message: `单位【${row.company_name}】及其员工已成功清理`,
|
||||
showClose: true
|
||||
});
|
||||
// 4. 刷新列表数据
|
||||
await fetchCustomers();
|
||||
} else {
|
||||
ElMessage.error(res.msg || '删除失败,请联系管理员');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('删除客户出错:', error);
|
||||
ElMessage.error('网络连接超时或服务器异常');
|
||||
} finally {
|
||||
// 5. 无论成功失败都关闭 loading
|
||||
loading.value = false;
|
||||
}
|
||||
}).catch(() => {
|
||||
// 用户点击取消,无需处理
|
||||
console.log('用户取消删除');
|
||||
});
|
||||
};
|
||||
|
||||
// 4. 员工管理逻辑
|
||||
const handleAddEmployee = () => {
|
||||
@@ -197,11 +228,13 @@ const submitEmployee = async () => {
|
||||
return ElMessage.error('请填写员工姓名并选择所属单位')
|
||||
}
|
||||
try {
|
||||
// console.log('这个是姓名',employeeForm.value.employee_name)
|
||||
// 注意:确保你的 api 文件中有 addEmployee 方法
|
||||
const res = await customerApi.addEmployee({
|
||||
emp_name: employeeForm.value.employee_name,
|
||||
customer_id: employeeForm.value.customer_id
|
||||
})
|
||||
|
||||
if (res.code === 200) {
|
||||
ElMessage.success('员工保存成功')
|
||||
employeeDialogVisible.value = false
|
||||
@@ -218,14 +251,17 @@ const showEmployeeDetails = (row) => {
|
||||
employeeDetailVisible.value = true
|
||||
}
|
||||
|
||||
// 需要修改,,这只是临时前端过滤,,并没有真正对接数据库
|
||||
//删除所属员工
|
||||
const confirmDeleteEmployee = (empId) => {
|
||||
ElMessageBox.confirm('确定要从该单位移除此员工吗?', '提示', { type: 'warning' }).then(async () => {
|
||||
try {
|
||||
// 假设接口:await customerApi.deleteEmployee(empId)
|
||||
ElMessage.success('操作成功(请对接后端删除接口)')
|
||||
// 临时前端过滤
|
||||
employeeList.value = employeeList.value.filter(e => e.employee_id !== empId)
|
||||
// console.log('删除员工的ID',empId);
|
||||
const res = await customerApi.deleteEmployee(empId) // 后端删除员工接口
|
||||
if (res.code == 200 || res.code == true){
|
||||
ElMessage.success('操作成功')
|
||||
employeeDetailVisible.value = false;
|
||||
fetchCustomers();
|
||||
}
|
||||
} catch (e) {
|
||||
ElMessage.error('删除失败')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user