Knowledge-audit.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <template>
  2. <el-dialog :title="dialogTitle" v-model="state.dialogVisible" draggable append-to-body destroy-on-close @close="close">
  3. <el-form :model="state.ruleForm" ref="ruleFormRef" label-width="80px" v-loading="state.loading">
  4. <el-form-item :label="textTip" v-if="[1, 2].includes(planInfo.applyStatus)">{{ applyReason }}</el-form-item>
  5. <el-form-item label="审批结果" prop="state" :rules="[{ required: true, message: '请选择审批结果', trigger: 'change' }]">
  6. <el-radio-group v-model="state.ruleForm.state">
  7. <el-radio :value="1">同意</el-radio>
  8. <el-radio :value="0">不同意</el-radio>
  9. </el-radio-group>
  10. </el-form-item>
  11. <el-form-item label="审批意见" prop="examinOpinion" :rules="[{ required: true, message: '请填写审批意见', trigger: 'blur' }]">
  12. <el-input v-model="state.ruleForm.examinOpinion" type="textarea" :autosize="{ minRows: 6, maxRows: 10 }" placeholder="请填写审批意见">
  13. </el-input>
  14. </el-form-item>
  15. </el-form>
  16. <template #footer>
  17. <span class="dialog-footer">
  18. <el-button @click="closeDialog" class="default-button">取 消</el-button>
  19. <el-button type="primary" @click="onSubmit(ruleFormRef)" :loading="state.loading">确 定</el-button>
  20. </span>
  21. </template>
  22. </el-dialog>
  23. </template>
  24. <script setup lang="ts">
  25. import { computed, reactive, ref } from 'vue';
  26. import { ElMessage, FormInstance } from 'element-plus';
  27. import { planAudit, planReason } from '@/api/plan';
  28. // 定义子组件向父组件传值/事件
  29. const emit = defineEmits(['updateList']);
  30. // 定义变量内容
  31. const state = reactive<any>({
  32. dialogVisible: false, // 弹窗
  33. ruleForm: {
  34. state: 1, // 默认同意
  35. examinOpinion: null, //审核意见
  36. },
  37. loading: false, // 加载
  38. });
  39. const planType = ref('update');
  40. const textTip = computed(() => {
  41. if (planType.value === 'update') {
  42. return '更新说明';
  43. } else if (planType.value === 'delete') {
  44. return '删除说明';
  45. }
  46. });
  47. // 查询申请审批意见
  48. const applyReason = ref<any>('');
  49. const getTips = async (row: any) => {
  50. try {
  51. const { result } = await planReason(row.id);
  52. applyReason.value = result.applyReason;
  53. } catch (e) {
  54. console.log(e);
  55. }
  56. };
  57. // 打开弹窗
  58. const ruleFormRef = ref<any>(); // 表单ref
  59. const planInfo = ref<any>();
  60. const dialogTitle = ref('预案更新审批');
  61. /*[
  62. {
  63. "key": -1,
  64. "value": "全部"
  65. },
  66. {
  67. "key": 0,
  68. "value": "新增审核"
  69. },
  70. {
  71. "key": 1,
  72. "value": "修改审核"
  73. },
  74. {
  75. "key": 2,
  76. "value": "删除审核"
  77. }
  78. ]*/
  79. const openDialog = (row: any) => {
  80. switch (row.applyStatus) {
  81. case 0:
  82. dialogTitle.value = '预案新增审批';
  83. break;
  84. case 1:
  85. planType.value = 'update';
  86. dialogTitle.value = '预案修改审批';
  87. break;
  88. case 2:
  89. planType.value = 'delete';
  90. dialogTitle.value = '预案删除审批';
  91. break;
  92. }
  93. planInfo.value = row;
  94. getTips(row);
  95. state.dialogVisible = true;
  96. };
  97. const close = () => {
  98. ruleFormRef.value?.clearValidate();
  99. ruleFormRef.value?.resetFields();
  100. };
  101. // 关闭弹窗
  102. const closeDialog = () => {
  103. state.dialogVisible = false;
  104. };
  105. // 新增
  106. const onSubmit = async (formEl: FormInstance | undefined) => {
  107. if (!formEl) return;
  108. await formEl.validate((valid: boolean) => {
  109. if (!valid) return;
  110. state.loading = true;
  111. planAudit({
  112. id: planInfo.value.id,
  113. state: state.ruleForm.state,
  114. examinOpinion: state.ruleForm.examinOpinion,
  115. })
  116. .then(() => {
  117. emit('updateList');
  118. closeDialog(); // 关闭弹窗
  119. ElMessage.success('审核成功');
  120. state.loading = false;
  121. })
  122. .catch(() => {
  123. state.loading = false;
  124. });
  125. });
  126. };
  127. // 暴露变量
  128. defineExpose({
  129. openDialog,
  130. closeDialog,
  131. });
  132. </script>