123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- <template>
- <el-dialog :title="dialogTitle" v-model="state.dialogVisible" draggable append-to-body destroy-on-close @close="close">
- <el-form :model="state.ruleForm" ref="ruleFormRef" label-width="80px" v-loading="state.loading">
- <el-form-item :label="textTip" v-if="[1, 2].includes(planInfo.applyStatus)">{{ applyReason }}</el-form-item>
- <el-form-item label="审批结果" prop="state" :rules="[{ required: true, message: '请选择审批结果', trigger: 'change' }]">
- <el-radio-group v-model="state.ruleForm.state">
- <el-radio :value="1">同意</el-radio>
- <el-radio :value="0">不同意</el-radio>
- </el-radio-group>
- </el-form-item>
- <el-form-item label="审批意见" prop="examinOpinion" :rules="[{ required: true, message: '请填写审批意见', trigger: 'blur' }]">
- <el-input v-model="state.ruleForm.examinOpinion" type="textarea" :autosize="{ minRows: 6, maxRows: 10 }" placeholder="请填写审批意见">
- </el-input>
- </el-form-item>
- </el-form>
- <template #footer>
- <span class="dialog-footer">
- <el-button @click="closeDialog" class="default-button">取 消</el-button>
- <el-button type="primary" @click="onSubmit(ruleFormRef)" :loading="state.loading">确 定</el-button>
- </span>
- </template>
- </el-dialog>
- </template>
- <script setup lang="ts">
- import { computed, reactive, ref } from 'vue';
- import { ElMessage, FormInstance } from 'element-plus';
- import { planAudit, planReason } from '@/api/plan';
- // 定义子组件向父组件传值/事件
- const emit = defineEmits(['updateList']);
- // 定义变量内容
- const state = reactive<any>({
- dialogVisible: false, // 弹窗
- ruleForm: {
- state: 1, // 默认同意
- examinOpinion: null, //审核意见
- },
- loading: false, // 加载
- });
- const planType = ref('update');
- const textTip = computed(() => {
- if (planType.value === 'update') {
- return '更新说明';
- } else if (planType.value === 'delete') {
- return '删除说明';
- }
- });
- // 查询申请审批意见
- const applyReason = ref<any>('');
- const getTips = async (row: any) => {
- try {
- const { result } = await planReason(row.id);
- applyReason.value = result.applyReason;
- } catch (e) {
- console.log(e);
- }
- };
- // 打开弹窗
- const ruleFormRef = ref<any>(); // 表单ref
- const planInfo = ref<any>();
- const dialogTitle = ref('预案更新审批');
- /*[
- {
- "key": -1,
- "value": "全部"
- },
- {
- "key": 0,
- "value": "新增审核"
- },
- {
- "key": 1,
- "value": "修改审核"
- },
- {
- "key": 2,
- "value": "删除审核"
- }
- ]*/
- const openDialog = (row: any) => {
- switch (row.applyStatus) {
- case 0:
- dialogTitle.value = '预案新增审批';
- break;
- case 1:
- planType.value = 'update';
- dialogTitle.value = '预案修改审批';
- break;
- case 2:
- planType.value = 'delete';
- dialogTitle.value = '预案删除审批';
- break;
- }
- planInfo.value = row;
- getTips(row);
- state.dialogVisible = true;
- };
- const close = () => {
- ruleFormRef.value?.clearValidate();
- ruleFormRef.value?.resetFields();
- };
- // 关闭弹窗
- const closeDialog = () => {
- state.dialogVisible = false;
- };
- // 新增
- const onSubmit = async (formEl: FormInstance | undefined) => {
- if (!formEl) return;
- await formEl.validate((valid: boolean) => {
- if (!valid) return;
- state.loading = true;
- planAudit({
- id: planInfo.value.id,
- state: state.ruleForm.state,
- examinOpinion: state.ruleForm.examinOpinion,
- })
- .then(() => {
- emit('updateList');
- closeDialog(); // 关闭弹窗
- ElMessage.success('审核成功');
- state.loading = false;
- })
- .catch(() => {
- state.loading = false;
- });
- });
- };
- // 暴露变量
- defineExpose({
- openDialog,
- closeDialog,
- });
- </script>
|