<template>
  <el-dialog
    title="拒绝原因"
    v-model:visible="dialogVisible"
    width="40%"
    :before-close="handleClose"
  >
    <div class="refuse-dialog">
      <el-radio
        class="radio"
        v-model:value="checkId"
        v-for="item in list"
        :key="item.id"
        :label="item.id"
        >{{ item.name }}</el-radio
      >
      <el-radio class="radio" v-model:value="checkId" :label="-1"
        >手动输入</el-radio
      >
      <el-input
        v-if="checkId === -1"
        type="textarea"
        placeholder="请输入拒绝原因"
        v-model:value="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 { $on, $off, $once, $emit } from '../../../../utils/gogocodeTransfer'
import { getRefuseTemplate } from '@/utils/qualification'

export default {
  props: {},
  data() {
    return {
      dialogVisible: false,
      checkId: -1,
      refuse: '',
      list: [],
      type: '',
      typeData: {
        1: '公司信息',
        2: '营业执照',
        3: '上一年年度报告',
        4: '委托人身份证照片',
        5: '委托书',
        6: '法人身份证照片',
        7: '药品经营许可证',
        8: '药品经营质量管理规范认证证书',
        9: '食品经营许可证',
        10: '医疗器械经营许可证',
        11: '二级医疗器械经营备案凭证',
        12: '事业单位法人证',
      },
    }
  },
  created() {},
  methods: {
    init() {
      getRefuseTemplate(this.type).then((res) => {
        console.log(res)
        this.list = res.data || []
      })
    },
    show(type) {
      console.log(type)
      this.type = type
      this.init(type)
      this.dialogVisible = true
    },
    handleClose() {
      this.list = []
      this.refuse = ''
      this.checkId = -1
      this.dialogVisible = false
    },
    confirm() {
      const params = {
        refuseTemplateNo: this.checkId,
        infoType: this.type,
        infoTypeName: this.typeData[this.type],
      }
      if (this.checkId === -1) {
        params.refuseContent = this.refuse
      } else {
        params.refuseContent = this.list.filter((v) => {
          return v.id === this.checkId
        })[0].name
      }
      this.handleClose()
      $emit(this, 'confirm', params)
    },
  },
  emits: ['confirm'],
}
</script>

<style lang="less" scoped>
.refuse-dialog {
  display: flex;
  flex-direction: column;
  margin-bottom: 20px;
}
.radio {
  margin-bottom: 10px;
}
.btn {
  text-align: right;
}
</style>
