<template>
  <div class="xl:w-screen-xl m-auto py-4 mt-12 px-4 sm:px-0 sm:mt-2">
    <el-page-header :icon="ArrowLeft" @back="goBack">
      <template #content>
        <span class="text-large font-600"> 实名认证 </span>
      </template>
      <el-card shadow="hover" class="my-10 px-2">
        <el-row :gutter="30" justify="space-between">
          <el-col :sm="16" :xs="24">
            <Auth @done="reload"/>
          </el-col>
          <el-col :md="5" :xs="24">
            <div class="w-full mt-2 text-center" v-if="isCheck">
              <el-alert type="warning" :closable="false" :title="`扫二维码完成实名认证`" />
              <el-image :src="config.wxQrcode" shape="square" class="mt-2" />
            </div>
          </el-col>
        </el-row>
      </el-card>
    </el-page-header>
  </div>
</template>
<script setup lang="ts">
import { ArrowLeft,View,Search } from '@element-plus/icons-vue'
import {useConfigInfo} from "~/composables/configState";
import {ref} from 'vue'
import Auth from './components/Auth.vue';

// 配置信息
const route = useRoute();
const router = useRouter();
const activeIndex = ref('');
const config = useConfigInfo();
const isCheck = ref(true);

const reload = async (status?: boolean) => {
  // 未登录状态(是否强制登录)
  const token = localStorage.getItem('token');
  if (!token || token == '') {
    navigateTo('/passport/login');
    return false;
  }

  if(status){
    isCheck.value = false
  }

  useHead({
    title: `实名认证 - ${config.value?.siteName}`
  });
}

const goBack = () => {
  router.back(); // 返回上一页
}

watch(
    () => route.path,
    (path) => {
      activeIndex.value = path;
      reload();
    },
    {immediate: true}
);
</script>
