<template>
  <el-dialog title="审核" append-to-body :modelValue="openShow" width="30%" @close="closeDialog">
    <avue-form v-model="obj" :option="option" ref="form"></avue-form>

    <template #footer>
      <span class="dialog-footer">
        <el-button @click="closeDialog">取 消</el-button>
        <el-button type="primary" @click="submit" v-loading="submitLoading"> 确 定</el-button>
      </span>
    </template>
  </el-dialog>
</template>
<script>
import { directorApproval, factoryApproval } from '@/api/processManagement/planClass.js';

export default {
  props: {
    showDialog: {
      type: Boolean,
      default: false,
    },
    rowItem: {
      type: Object,
      default: {},
    },
  },
  data() {
    return {
      obj: {},
      openShow: false,
      submitLoading: false,
      option: {
        submitBtn: false,
        emptyBtn: false,
        column: [
          {
            label: '审批结果',
            prop: 'isPass',
            span: 24,
            type: 'radio',
            dicData: [
              { label: '审批通过', value: 1 },
              { label: '审批不通过', value: 2 },
            ],
            rules: [{ required: true, message: '请选择', trigger: 'blur' }],
          },
          {
            label: '驳回原因',
            prop: 'approvalOpinions',
            type: 'textarea',
            span: 24,
          },
        ],
      },
    };
  },
  mounted() {
    this.openShow = this.showDialog;
  },
  methods: {
    closeDialog() {
      this.openShow = false;
      this.$emit('closeDialog');
    },
    submit() {
      this.$refs.form.validate((valid, done, msg) => {
        if (valid) {
          this.submitLoading = true;
          // 室主任审核
          if (this.rowItem.approvalStatus == '-1' || this.rowItem.approvalStatus == 1) {
            directorApproval({ ...this.obj, id: this.rowItem.id }).then(res => {
              this.$message({
                type: 'success',
                message: '操作成功!',
              });
              this.closeDialog();
              this.submitLoading = false;
            });
          }
          //   厂长审核
          if (this.rowItem.approvalStatus == 2) {
            factoryApproval({ ...this.obj, id: this.rowItem.id }).then(res => {
              this.$message({
                type: 'success',
                message: '操作成功!',
              });
              this.closeDialog();
              this.submitLoading = false;
            });
          }
          this.submitLoading = false;
          done();
        } else {
          console.log('error submit!!');
          this.submitLoading = false;
          return false;
        }
      });
    },
  },
};
</script>
<style lang="scss" scoped></style>
