<template>
  <view class="class-item-container">
    <u-card :show-head="false" margin="0" border-radius="20">
      <template #body>
        <view class="calss-header">
          <h3>{{ classItem.className }}</h3>
          <view
            v-show="current == 2 && !classItem.iEevaluate"
            @tap="toEvaluate"
            style="color: #04a7ff"
          >
            去评价<u-icon name="arrow-right-double" style="margin-left: 8rpx" />
          </view>
          <!-- <view
            v-show="current == 2 && classItem.iEevaluate"
            @tap="toEvaluate"
            style="color: #04a7ff"
          >
            查看评价<u-icon
              name="arrow-right-double"
              style="margin-left: 8rpx"
            />
          </view> -->
        </view>
        <view class="item">
          <text>课程时间：</text>
          <text>{{ classItem.startDate }} 至 {{ classItem.endDate }}</text>
        </view>
        <view class="item">
          <text>教室地点：</text>
          <text>{{ classItem.classArea }}</text>
        </view>
        <view> </view>
        <view class="class-progress item">
          <text>课程进度：</text>
          <u-line-progress
            active-color="#5363FF"
            :percent="percent ? percent : 0"
            :show-percent="false"
            :height="20"
            style="margin-top: 10rpx"
          />
          <view class="progress">
            {{
              (props.classItem.coursePro[0]?.SumPro
                ? props.classItem.coursePro[0]?.SumPro
                : "0") +
              "/" +
              props.classItem.courseSum[0]?.Sum
            }}
          </view>
        </view>

        <view class="class-teacher item">
          <text>班主任：</text>
          <view>
            <view
              v-for="(item, index) in classItem.Management"
              :key="index"
              class="btn"
              @tap="contact(item.teacPhone)"
            >
              <u-image src="../../../static/img/phone.png" />
              <view>{{ item.teachName }}</view>
            </view>
          </view>
        </view>
      </template>
      <template #foot>
        <view class="class-footer">
          <u-button size="mini" shape="circle" @tap="toAddressBook"
            >班级通讯录</u-button
          >
          <u-button size="mini" shape="circle" @tap="classQrCode"
            >班级二维码</u-button
          >
          <u-button
            size="mini"
            shape="circle"
            hover-class="background-color: #04a7ff; color: #ffffff"
            style="background-color: #04a7ff; color: #ffffff"
            @tap="toCourseArrange"
            >课程安排</u-button
          >
        </view>
      </template>
    </u-card>
  </view>

  <saveQrCode
    v-model="show"
    :Url="classItem.Url"
    :title="classItem.className"
  />
</template>

<script setup lang="ts">
import saveQrCode from "./saveQrCode.vue";

const props = defineProps({
  classItem: {
    type: Array,
    default: () => [],
  } as any,
  current: {
    type: Number,
    default: 0,
  },
});

const show = ref(false);

const percent = computed(
  () =>
    (props.classItem.coursePro[0]?.SumPro / props.classItem.courseSum[0]?.Sum) *
    100
);

const classQrCode = () => {
  show.value = true;
};

const toAddressBook = () => {
  uni.navigateTo({
    url: "/pages/class/addressBook?classId=" + props.classItem.classId,
  });
};
const toCourseArrange = () => {
  uni.navigateTo({
    url: "/pages/class/courseArrange?classId=" + props.classItem.classId,
  });
};

const toEvaluate = () => {
  uni.navigateTo({
    url:
      "/pages/class/evaluate?classNumber=" +
      props.classItem.classNumber +
      "&iEvaluate=" +
      props.classItem.iEevaluate +
      "&classId=" +
      props.classItem.classId +
      "&ItemNumber=" +
      props.classItem.ItemNumber,
  });
};

const contact = (tel: string) => {
  location.href = "tel:" + tel;
};
</script>

<style lang="scss" scoped>
.class-item-container {
  margin-bottom: 32rpx;

  :deep(.u-card__body) {
    padding: 40rpx 32rpx !important;
  }

  .calss-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 32rpx;

    h3 {
      margin: 0;
      font-size: 34rpx;
      font-weight: 500;
      color: #222222;
    }

    uni-button {
      margin: 0;
    }
  }

  .item {
    display: flex;
    align-items: flex-start;
    margin-bottom: 24rpx;

    text {
      display: block;
      font-size: 28rpx;
      font-weight: 400;
      color: rgba(34, 34, 34, 0.9);
    }

    text:first-child {
      width: 160rpx;
    }

    text:last-child {
      flex: 1;
    }
  }

  .class-progress {
    display: flex;
    align-items: center;

    .progress {
      margin-left: 10px;
      margin-top: 8rpx;
    }

    .u-progress {
      margin-left: 20rpx;
    }

    text {
      white-space: nowrap;
    }

    .registered {
      margin-left: 30rpx;
      color: #3b99fc;
    }
  }

  .class-teacher {
    display: flex;
    align-items: center;
    margin-top: 16rpx;

    .btn {
      height: 56rpx;
      padding: 14rpx 36rpx 14rpx 14rpx;
      background: #04a7ff;
      border-radius: 112rpx;
      color: #ffffff;
      display: flex;
      align-items: center;
      justify-content: center;

      .u-image {
        margin-right: 6rpx;
        width: 50rpx !important;
        height: 46rpx !important;
      }
    }
  }

  .class-footer {
    width: 100%;
    display: flex;
    justify-content: flex-end;

    .u-btn {
      height: 56rpx;
      margin: 0 16rpx 0 0;
    }
  }
}
</style>
