<template>
  <el-dialog
    title="拒绝原因"
    :visible.sync="dialogVisible"
    width="40%"
    :before-close="handleClose"
  >
    <div class="refuse-dialog">
      <el-radio
        v-model="checkId"
        v-for="item in list"
        :key="item.id"
        :label="item.id"
        >{{ item.name }}</el-radio
      >
      <el-radio v-model="checkId" :label="4">手动输入</el-radio>
      <el-input
        v-if="checkId === -1"
        type="textarea"
        placeholder="请输入拒绝原因"
        v-model="refuse"
        maxlength="30"
        show-word-limit
      />
    </div>
    <div class="btn">
      <el-button type="default" size="small" @click="handleClose"
        >取消</el-button
      >
      <el-button type="primary" size="small" @click="confirm">确认</el-button>
    </div>
  </el-dialog>
</template>
<script>
import { getRefuseTemplate } from "@/utils/qualification";

export default {
  props: {},
  data() {
    return {
      dialogVisible: false,
      checkId: -1,
      refuse: "",
      list:[],
      type:''
    };
  },
  created() {},
  methods: {
    init(type) {
      this.type = type
      getRefuseTemplate({ type }).then((res) => {
        console.log(res);
        this.list = res.data || []
      });
    },
    show() {
      this.dialogVisible = true;
    },
    handleClose() {
      this.dialogVisible = false;
    },
    confirm() {
      const params = {
        refuseTemplateNo:this.checkId,
        infoType:this.type
      }
      if(this.checkId === -1) {
        params.refuseContent = this.refuse
      } else {
        params.refuseContent = this.list.filters(v => {
          return v.id === checkId
        })[0].name
      }
      this.handleClose();
      this.$emit("confirm",params);
    },
  },
};
</script>
<style lang='less' scoped>
.refuse-dialog {
  display: flex;
  flex-direction: column;
  margin-bottom: 20px;
}
.btn {
  text-align: right;
}
</style>
