Advice-edit.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <template>
  2. <el-dialog v-model="state.dialogVisible" width="50%" draggable title="修改常用意见">
  3. <el-form :model="state.ruleForm" label-width="90px" ref="ruleFormRef">
  4. <el-row :gutter="10">
  5. <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
  6. <el-form-item label="意见内容" prop="content" :rules="[{ required: true, message: '请输入意见内容', trigger: 'blur' }]">
  7. <el-input v-model="state.ruleForm.content" placeholder="请输入意见内容" clearable type="textarea" show-word-limit maxlength="200"></el-input>
  8. </el-form-item>
  9. </el-col>
  10. <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
  11. <el-form-item label="意见类型" prop="commonType" :rules="[{ required: true, message: '请选择意见类型', trigger: 'change' }]">
  12. <el-select v-model="state.ruleForm.commonType" placeholder="请选择意见类型" clearable class="w100">
  13. <el-option v-for="item in commonType" :value="item.key" :key="item.key" :label="item.value" />
  14. </el-select>
  15. </el-form-item>
  16. </el-col>
  17. </el-row>
  18. </el-form>
  19. <template #footer>
  20. <span class="dialog-footer">
  21. <el-button @click="onCancel" class="default-button">取 消</el-button>
  22. <el-button type="primary" @click="onSubmit(ruleFormRef)" :loading="loading">确 定</el-button>
  23. </span>
  24. </template>
  25. </el-dialog>
  26. </template>
  27. <script setup lang="ts" name="auxiliaryAdviceEdit">
  28. import { reactive, ref } from 'vue';
  29. import { ElMessage, FormInstance } from 'element-plus';
  30. import { throttle } from '/@/utils/tools';
  31. import { commonUpdate } from '/@/api/auxiliary/advice';
  32. import other from "/@/utils/other";
  33. // 定义子组件向父组件传值/事件
  34. const emit = defineEmits(['updateList']);
  35. const props = defineProps({
  36. commonType: {
  37. type: Array,
  38. default: () => [],
  39. },
  40. });
  41. // 定义变量内容
  42. const state = reactive<any>({
  43. dialogVisible: false,
  44. ruleForm: {
  45. content: '', // 意见内容
  46. CommonType: '', // 意见类型
  47. isOpen:true, // 是否公开意见
  48. },
  49. });
  50. let loading = ref<boolean>(false); // 加载状态
  51. // 打开弹窗
  52. const ruleFormRef = ref<RefType>();
  53. const openDialog = async (row:any) => {
  54. ruleFormRef.value?.resetFields();
  55. try {
  56. state.ruleForm = other.deepClone(row);
  57. state.dialogVisible = true;
  58. } catch (error) {
  59. console.log(error);
  60. }
  61. };
  62. // 关闭弹窗
  63. const closeDialog = () => {
  64. state.dialogVisible = false;
  65. };
  66. // 取消
  67. const onCancel = () => {
  68. closeDialog();
  69. };
  70. // 新增
  71. const onSubmit = throttle(async (formEl: FormInstance | undefined) => {
  72. if (!formEl) return;
  73. await formEl.validate((valid: boolean) => {
  74. if (!valid) return;
  75. loading.value = true;
  76. commonUpdate(state.ruleForm)
  77. .then(() => {
  78. ElMessage({
  79. message: '操作成功',
  80. type: 'success',
  81. });
  82. loading.value = false;
  83. closeDialog();
  84. emit('updateList');
  85. })
  86. .catch(() => {
  87. }).finally(() => {
  88. loading.value = false;
  89. closeDialog();
  90. });
  91. });
  92. }, 300);
  93. // 暴露变量
  94. defineExpose({
  95. openDialog,
  96. closeDialog,
  97. });
  98. </script>