<template>
  <div class="my-5">
    <v-card class="default-width" elevation="10">
      <div style="margin: 70px auto; width: 600px;">
        <!-- 提交老师注册以后跳转显示页面 -->
        <div v-if="applyInfo && applyInfo?.authStatus === '0'" class="d-flex flex-column align-center">
          <svg-icon name="submit" size="300"></svg-icon>
          <div><strong class="color-primary font-size-20">已收到您的老师账号注册申请，</strong>审核时间预计在1~3个工作日内，申请结果会以短信方式通知到您的手机上，请注意查收。</div>
          <div style="width: 100%;">
            <div class="mt-5 mb-1">如有疑问请扫码添加下方企业微信联系我们：</div>
            <div style="width: 150px; height: 150px; margin: auto;">
              <v-img src="https://minio.menduner.com/dev/90d8688e33f024a1be2460a3524709ac7f027e9f023b3fce77acf60fdfd2c587.png" width="150" height="150"></v-img>
            </div>
            <div class="text-center ml-5">郑玉洁女士</div> 
          </div>
        </div>

        <!-- 审核不通过 -->
        <div v-else-if="applyInfo?.authStatus === '2'"> 
          <div class="mb-3" style="color: red;">
            您的老师账号注册申请<strong class="color-error font-size-20"> 审核不通过，</strong>
            具体原因如下：{{ applyInfo?.authMessage }}
          </div>
          <div class="mt-5">
            <span>审核时间：{{ timesTampChange(applyInfo?.authTime) }}</span>
          </div>
          <div style="width: 100%;">
            <div class="mt-5 mb-1">如有疑问请扫码添加下方企业微信联系我们：</div>
            <div style="width: 150px; height: 150px; margin: auto;">
              <v-img src="https://minio.menduner.com/dev/90d8688e33f024a1be2460a3524709ac7f027e9f023b3fce77acf60fdfd2c587.png" width="150" height="150"></v-img>
            </div>
            <div class="text-center ml-5">郑玉洁女士</div>
          </div>
        </div>
      </div>
      <div class="text-center mb-15">
        <v-btn class="mt-16 mr-3 buttons" color="primary" @click="handleBackToFlame">回到火苗儿校企</v-btn>
        <v-btn v-if="getToken()" class="mt-16 mr-3 buttons" color="primary" @click="handleRefreshApproved">刷新审核进度</v-btn>
        <v-btn v-if="applyInfo?.authStatus === '2'" class="mt-16 buttons" color="primary" @click="handleConfirm">{{ $t('common.resubmit') }}</v-btn>
      </div>
    </v-card>
  </div>
</template>

<script setup>
defineOptions({ name: 'register-schoolForm'})
import { ref, onMounted } from 'vue'
import { webContentStore } from '@/store/webContent'
import { useRouter } from 'vue-router'
import { timesTampChange } from '@/utils/date'
import { useUserStore } from '@/store/user'
import { getToken } from '@/utils/auth'
import { getSchoolInformation } from '@/api/school'
import Snackbar from '@/plugins/snackbar'

const userStore = useUserStore()
const applyInfo = ref(localStorage.getItem('registerSchoolInfo') ? JSON.parse(localStorage.getItem('registerSchoolInfo')) : {})
console.log(applyInfo.value, '注册审核信息')

const router = useRouter()
const webContent = webContentStore()

onMounted(async () => {
  await webContent.getSystemWebContent()
})

// 回到火苗儿校企页面
const handleBackToFlame = async () => {
  await userStore.userLogout(1)
  router.push('/flameLogin')
}

// 重新提交
const handleConfirm = async () => {
  router.push('/recruit/teacher/register/schoolIndex')
}

// 刷新审核状态
const handleRefreshApproved = async () => {
  const data = await getSchoolInformation()
  if (!data) return
  localStorage.setItem('schoolInfo', data ? JSON.stringify(data) : '{}')
  
  if (data?.authStatus === '1') {
    Snackbar.success('您的账号审核已通过')
    router.push('/recruit/teacher/studentList/index')
  }
  if (data?.authStatus === '0') {
    Snackbar.warning('您的账号还在审核中，请耐心等待')
  }
  if (data?.authStatus === '2') {
    Snackbar.warning('您的账号审核未通过，请重新提交')
  }
  
  applyInfo.value = data
  localStorage.setItem('registerSchoolInfo', JSON.stringify(data))
  console.log('刷新审核状态', applyInfo.value)
}
</script>

<style scoped lang="scss">
.navBar {
  position: absolute;
  top: 0;
}
.box {
  position: relative;
  width: 100%;
  height: 100%;
  background-size: cover;
  background-repeat: no-repeat;
  background-position: center center;
}
.content {
  position: absolute;
  top: 50%;
  left: 50%;
  translate: -50% -50%;
  width: 600px;
  height: 80%;
  overflow: auto;
  background-color: #fff;
  border-radius: 10px;
}
.upload-box {
	width: 100px;
}
</style>
