<template>
  <view class="bg-header">
    <u-image src="../../static/img/background.png" width="100%" height="100%" />
  </view>
  <view class="home-container">
    <!-- 用户信息部分 -->
    <view class="user-info">
      <u-image
        width="240rpx"
        height="240rpx"
        mode="aspectFit"
        :src="'data:image/png;base64,' + globalStore.infoData?.img"
        border-radius="24"
      />
      <text class="name">{{ globalStore.infoData?.Name }}</text>
      <view v-if="globalStore.Phone" class="info">
        <text>班主任</text>
      </view>
    </view>

    <view class="menu-title">
      <view class="half-circle"></view>
      <view class="title">服务功能</view>
    </view>

    <view class="user-menu">
      <view
        class="menu-item"
        v-for="item in menuList"
        :key="item.id"
        @tap="gridChange(item.id)"
      >
        <u-image :src="item.src" width="120rpx" height="120rpx" />
        <text>{{ item.name }}</text>
      </view>
    </view>
    <view class="bg-footer">
      <u-image
        src="../../static/img/mask_group.png"
        width="100%"
        height="100%"
      />
    </view>
  </view>
</template>

<script setup lang="ts">
import { useGlobalStore } from "@/store/useStore";

const globalStore = useGlobalStore();

const menuList = [
  {
    id: 0,
    src: "../../static/img/Ribbon1.png",
    name: "班级管理",
  },
  {
    id: 1,
    src: "../../static/img/Ribbon2.png",
    name: "我的课程",
  },
  {
    id: 2,
    src: "../../static/img/Ribbon3.png",
    name: "考勤定位",
  },
  {
    id: 3,
    src: "../../static/img/Ribbon4.png",
    name: "讲师列表",
  },
  {
    id: 4,
    src: "../../static/img/Ribbon5.png",
    name: "现场教学",
  },
  {
    id: 5,
    src: "../../static/img/Ribbon6.png",
    name: "培训评价",
  },
];

const toClass = () => {
  uni.navigateTo({
    url: "/pages/class/index",
  });
};

const toCourse = () => {
  uni.navigateTo({
    url: "/pages/course/index",
  });
};
const toSetPositioning = () => {
  uni.navigateTo({
    url: "/pages/setPositioning/index",
  });
};
const toTeachPoints = () => {
  uni.navigateTo({
    url: "/pages/teachPoints/index",
  });
};

const gridChange = (type: number) => {
  switch (type) {
    case 0:
      toClass();
      break;
    case 1:
      toCourse();
      break;
    case 2:
      toSetPositioning();
      break;
    case 3:
      uni.navigateTo({
        url: "/pages/lecturer/index",
      });
      break;
    case 4:
      toTeachPoints();
      break;
    case 5:
      uni.navigateTo({
        url: "/pages/trainingEvaluation/index",
      });
      break;
  }
};
</script>

<style lang="scss" scoped>
page {
  background-color: #ffffff;
}
.bg-header {
  position: relative;
}
.home-container {
  position: absolute;
  top: 3%;
  width: 100%;

  .user-info {
    margin: 40rpx 0 40rpx 0;
    width: 100%;
    height: 30%;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;

    .name {
      font-size: 36rpx;
      font-weight: bold;
      padding: 20rpx 0;
      color: #000;
    }

    .info {
      display: flex;
      justify-content: center;
      align-items: center;
    }
  }

  .menu-title {
    margin: 0 32rpx;
    width: 100%;
    display: flex;
    margin-bottom: 32rpx;

    .title {
      font-size: 34rpx;
      font-weight: 600;
      color: #222222;
      line-height: 40rpx;
    }
  }

  .user-menu {
    // height: 238rpx;
    margin: 0 32rpx;
    padding: 48rpx;
    background: transparent;
    box-shadow: 0rpx 8rpx 60rpx 0rpx rgba(0, 0, 0, 0.05);
    border-radius: 24rpx;
    display: flex;
    flex-wrap: wrap;
    box-sizing: border-box;

    .menu-item {
      text-align: center;
      flex-basis: calc((100% - 96rpx) / 3);
      // height: 200rpx;
      display: flex;
      flex-direction: column;
      align-items: center;
      margin-right: 48rpx;
      margin-bottom: 24rpx;
    }

    & .menu-item:nth-child(3n) {
      margin-right: 0;
    }
  }
}
</style>
