Tem-add.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <template>
  2. <el-dialog title="新增外呼任务模板" v-model="state.dialogVisible" width="800px" draggable @close="close">
  3. <el-form :model="state.ruleForm" ref="ruleFormRef" label-width="100px">
  4. <el-form-item label="模板名称" prop="name" :rules="[{ required: true, message: '请输入模板名称', trigger: 'blur' }]">
  5. <el-input v-model="state.ruleForm.name" placeholder="请输入模板名称" clearable></el-input>
  6. </el-form-item>
  7. <el-form-item label="模板内容" prop="content" :rules="[{ required: true, message: '请输入模板内容', trigger: 'blur' }]">
  8. <el-input v-model="state.ruleForm.content" placeholder="请输入模板内容" type="textarea" :autosize="{ minRows: 4, maxRows: 8 }"></el-input>
  9. </el-form-item>
  10. </el-form>
  11. <template #footer>
  12. <span class="dialog-footer">
  13. <el-button @click="closeDialog" class="default-button">取 消</el-button>
  14. <el-button type="primary" @click="onSubmit(ruleFormRef)" :loading="state.loading">确 定 </el-button>
  15. </span>
  16. </template>
  17. </el-dialog>
  18. </template>
  19. <script setup lang="ts" name="qualityLexiconAdd">
  20. import { reactive, ref } from 'vue';
  21. import { ElInput, ElMessage, ElMessageBox, FormInstance } from 'element-plus';
  22. // 定义子组件向父组件传值/事件
  23. const emit = defineEmits(['updateList']);
  24. // 定义变量内容
  25. const ruleFormRef = ref<FormInstance>();
  26. const state = reactive<any>({
  27. dialogVisible: false, // 弹窗显示隐藏
  28. ruleForm: {
  29. name: '', // 模板名称
  30. content: '', // 模板内容
  31. },
  32. loading: false, // 确定按钮loading
  33. });
  34. // 打开弹窗
  35. const openDialog = async () => {
  36. try {
  37. state.dialogVisible = true;
  38. } catch (e) {
  39. console.log(e);
  40. }
  41. };
  42. // 关闭弹窗
  43. const closeDialog = () => {
  44. state.dialogVisible = false;
  45. };
  46. const close = () => {
  47. ruleFormRef.value?.clearValidate();
  48. ruleFormRef.value?.resetFields();
  49. };
  50. // 保存
  51. const onSubmit = (formEl: FormInstance | undefined) => {
  52. if (!formEl) return;
  53. formEl.validate((valid: boolean) => {
  54. if (!valid) return;
  55. state.loading = true;
  56. const request = {
  57. ...state.ruleForm,
  58. };
  59. });
  60. };
  61. // 暴露变量
  62. defineExpose({
  63. openDialog,
  64. closeDialog,
  65. });
  66. </script>