<script setup lang="ts">
import user from '~/store/user';
const router = useRouter()
const route = useRoute()
import { showFailToast } from 'vant'

// let isPbTeacher = -1
// await request({
//   url: '/dyaw/xlfw_pbgl/index',
//   data: {
//     user_id: user.user_id
//   }
// }).then(res => {
//   if (res.code === '1') {
//     isPbTeacher = res.data?.page_data?.length
//   }
// })

const list = [
  { title: '个人中心', route: 'teacher_personal', icon: "user-o", bg: 'linear-gradient(142deg,#69b3fd 15%, #89c4ff 64%);' },
  { title: '咨询页面', route: 'teacher_consult', icon: "service-o", bg: 'linear-gradient(142deg,#fea200 20%, #ffbd00 71%);' },
  { title: '学生档案', route: 'teacher_archives', icon: "records", bg: 'linear-gradient(142deg,#14c080 15%, #66ea9e 64%);' }
]


async function routerPush(routename: string) {
  const teacher = (await request({
    url: '/dyaw/xlfw_pbgl/detail',
    data: {
      user_id: user.user_id
    }
  }))?.data?.one_info
  const ifAuth = (!teacher?.dxp_user_name) && routename !== 'teacher_personal'
  if (ifAuth) {
    // console.log(true, ifAuth, (!teacher?.dxp_user_name) && routename !== 'teacher_personal')
    showFailToast('请先去个人中心完善信息')
    return;
  }
  else {
    router.push({ name: routename })
  }
}

const imgSrc = (await request({
  url: '/dyaw/xlfw_hbgl/index',
  data: {
    limit: 1
  }
})).data?.page_data?.[0]?.dxh_path

function onClickLeft() {
  window.history.back()
}
</script>

<template>
  <div class=" flex flex-col justify-start ">
    <van-nav-bar title="心理健康" left-text="" left-arrow @click-left="onClickLeft"
      style="--van-nav-bar-background:#397FF6;--van-nav-bar-icon-color:#fff;--van-nav-bar-title-text-color:#fff;--van-nav-bar-title-font-size:18px;" />
    <div class="w-full max-h-590px flex_center overflow-hidden">
      <img v-show="imgSrc" :src="imgSrc" class="w-full h-full max-h-590px object-contain">
    </div>
    <div class="p-2 w-full mt-2">
      <div class="bg-white w-full flex justify-around items-center shadow">
        <div v-for="({ title, route, icon, bg }) in list" :key="route" class="py-4 space-y-2" @click="routerPush(route)">
          <div class="w-75px h-75px rounded-full flex_center text-white" :style="`background:${bg}`">
            <van-icon :name="icon" size="52"></van-icon>
          </div>
          <div class="text-center">{{ title }}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<style scoped>
</style>
