Files
admin-ui/src/views/customerService/account/component/editAccount.vue

176 lines
3.9 KiB
Vue
Raw Normal View History

2025-11-22 16:39:01 +08:00
<template>
2025-12-05 15:45:14 +08:00
<div class="account-edit-dialog">
2025-11-28 17:17:07 +08:00
<el-dialog :title="(formData.id ? '修改' : '添加') + '客服账号'" v-model="isShowDialog" width="769px">
2025-11-25 17:02:31 +08:00
<el-form ref="formRef" :model="formData" :rules="rules" size="default" label-width="90px">
<el-row :gutter="35">
<!-- 客服ID输入框 -->
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
2025-11-28 17:17:07 +08:00
<el-form-item label="客服ID" prop="customerServiceId">
<el-input v-model="formData.customerServiceId" placeholder="请输入客服IDCS001" clearable />
2025-11-25 17:02:31 +08:00
</el-form-item>
</el-col>
2025-11-28 17:17:07 +08:00
<!-- 客服平台选择 -->
2025-11-25 17:02:31 +08:00
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
<el-form-item label="客服平台" prop="platform">
2025-11-28 17:17:07 +08:00
<el-select v-model="formData.platform" placeholder="请选择客服平台" clearable style="width: 100%">
<el-option label="小红书" value="小红书" />
<el-option label="抖音" value="抖音" />
<el-option label="快手" value="快手" />
</el-select>
2025-11-25 17:02:31 +08:00
</el-form-item>
</el-col>
</el-row>
</el-form>
2025-11-22 16:39:01 +08:00
2025-11-25 17:02:31 +08:00
<template #footer>
<span class="dialog-footer">
<el-button @click="onCancel" size="default"> </el-button>
<el-button type="primary" @click="onSubmit" size="default" :loading="loading">
2025-11-28 17:17:07 +08:00
{{ formData.id ? '修 改' : '新 增' }}
2025-11-25 17:02:31 +08:00
</el-button>
</span>
</template>
</el-dialog>
</div>
</template>
2025-11-22 16:39:01 +08:00
2025-11-25 17:02:31 +08:00
<script lang="ts" setup>
2025-11-28 17:17:07 +08:00
import { ref, reactive, toRefs, nextTick } from 'vue';
2025-11-25 17:02:31 +08:00
import { ElMessage, type FormInstance, type FormRules } from 'element-plus';
2025-12-05 15:45:14 +08:00
import { addAccount, updateAccount } from '/@/api/customerService/account';
2025-11-25 17:02:31 +08:00
interface DialogFormData {
2025-11-28 17:17:07 +08:00
id?: string;
customerServiceId: string;
platform: string;
status: number;
creator: '';
modifier: '';
2025-11-22 16:39:01 +08:00
}
2025-11-25 17:02:31 +08:00
const emit = defineEmits<{
2025-12-05 15:45:14 +08:00
(e: 'refresh'): void;
2025-11-25 17:02:31 +08:00
}>();
2025-11-28 17:17:07 +08:00
const state = reactive({
2025-11-25 17:02:31 +08:00
loading: false,
isShowDialog: false,
formData: {
2025-11-28 17:17:07 +08:00
id: '',
customerServiceId: '',
2025-11-25 17:02:31 +08:00
platform: '',
status: 1,
2025-11-28 17:17:07 +08:00
creator: '',
modifier: '',
} as DialogFormData,
2025-11-25 17:02:31 +08:00
});
const rules: FormRules = {
2025-11-28 17:17:07 +08:00
customerServiceId: [
2025-11-25 17:02:31 +08:00
{ required: true, message: '客服ID不能为空', trigger: 'blur' },
2025-11-28 17:17:07 +08:00
{ min: 2, max: 50, message: '客服ID长度在 2 到 50 个字符', trigger: 'blur' },
2025-11-25 17:02:31 +08:00
],
2025-11-28 17:17:07 +08:00
platform: [{ required: true, message: '请选择客服平台', trigger: 'change' }],
2025-11-25 17:02:31 +08:00
};
const formRef = ref<FormInstance>();
2025-11-28 17:17:07 +08:00
const { loading, isShowDialog, formData } = toRefs(state);
2025-11-25 17:02:31 +08:00
/**
* 打开对话框
*/
2025-11-28 17:17:07 +08:00
const openDialog = (row?: DialogFormData) => {
2025-11-25 17:02:31 +08:00
resetForm();
2025-11-28 17:17:07 +08:00
if (row && row.id) {
// 编辑模式:填充数据
state.formData = { ...row };
} else {
// 新增模式重置ID和状态
state.formData.id = '';
state.formData.status = 1;
2025-11-25 17:02:31 +08:00
}
2025-11-28 17:17:07 +08:00
state.isShowDialog = true;
// 下次DOM更新后清除验证
nextTick(() => {
formRef.value?.clearValidate();
});
2025-11-25 17:02:31 +08:00
};
/**
* 关闭对话框
*/
const closeDialog = () => {
state.isShowDialog = false;
};
/**
* 取消操作
*/
const onCancel = () => {
closeDialog();
};
/**
* 提交表单
*/
const onSubmit = async () => {
2025-11-28 17:17:07 +08:00
if (!formRef.value) return;
2025-11-25 17:02:31 +08:00
try {
const valid = await formRef.value.validate();
2025-11-28 17:17:07 +08:00
if (!valid) return;
2025-11-25 17:02:31 +08:00
state.loading = true;
2025-11-28 17:17:07 +08:00
if (state.formData.id) {
2025-12-05 15:45:14 +08:00
// 修改操作
await updateAccount(state.formData);
2025-11-28 17:17:07 +08:00
ElMessage.success('修改成功');
2025-11-25 17:02:31 +08:00
} else {
2025-11-28 17:17:07 +08:00
// 新增操作
2025-12-05 15:45:14 +08:00
await addAccount(state.formData);
2025-11-28 17:17:07 +08:00
ElMessage.success('添加成功');
2025-11-25 17:02:31 +08:00
}
closeDialog();
2025-12-05 15:45:14 +08:00
emit('refresh');
2025-11-25 17:02:31 +08:00
} catch (error) {
2025-11-28 17:17:07 +08:00
console.error('操作失败:', error);
ElMessage.error(state.formData.id ? '修改失败' : '添加失败');
2025-11-25 17:02:31 +08:00
} finally {
state.loading = false;
}
};
/**
* 重置表单
*/
const resetForm = () => {
state.formData = {
2025-11-28 17:17:07 +08:00
id: '',
customerServiceId: '',
2025-11-25 17:02:31 +08:00
platform: '',
status: 1,
2025-11-28 17:17:07 +08:00
creator: '',
modifier: '',
2025-11-25 17:02:31 +08:00
};
};
defineExpose({
openDialog,
closeDialog,
2025-11-22 16:39:01 +08:00
});
</script>
2025-11-28 17:17:07 +08:00
<style scoped>
.status-tip {
font-size: 12px;
color: #999;
2025-11-25 17:02:31 +08:00
margin-top: 5px;
2025-11-22 16:39:01 +08:00
}
</style>