<template>
  <el-dialog v-model="visible" width="60%" :title="`面试审核(${row.name})`">
    <el-row>
      <el-radio v-model="status" label="1">通过</el-radio>
      <el-radio v-model="status" label="-1">未通过</el-radio>
    </el-row>
    <el-row v-if="status == '-1'">
      <br />
      <el-input type="textarea" v-model="reason" placeholder="请输入未通过的原因"></el-input>
    </el-row>

    <template #footer>
      <div class="dialog-footer">
        <el-button type="primary" @click="confirm"><span>确认</span></el-button>
        <el-button @click="visible = false">取消</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script setup lang="ts">
import { ref, reactive } from 'vue'
import { useMessage } from '/@/hooks/message'
// @ts-ignore
import global from "@/components/tools/commondict"
import { interview } from "@/api/recruit/recruitstudentsignup"

// 消息提示 hooks
const message = useMessage()

// Emits
const emit = defineEmits<{
  (e: 'refresh'): void
}>()

// 响应式数据
const visible = ref(false)
const row = reactive<any>({})
const status = ref('1')
const reason = ref('')

// 初始化
const init = (rowData: any) => {
  visible.value = true
  Object.assign(row, rowData)
  status.value = rowData.interview || '1'
  reason.value = rowData.interviewReason || ''
}

// 确认
const confirm = () => {
  if (!status.value || (status.value == '-1' && !reason.value)) {
    message.warning('请选择通过还是未通过，未通过请输入原因')
    return
  } else {
    interview({ "id": row.id, "interview": status.value, "interviewReason": reason.value }).then(() => {
      message.success('操作成功')
      visible.value = false
      emit('refresh')
    }).catch(() => {
      message.error('操作失败')
    })
  }
}

// 暴露方法给父组件
defineExpose({
  init
})
</script>

<style scoped>
.dialog-footer {
  text-align: right;
}
</style>
