<!--
 * @Author: 纪泽龙 jizelong@qq.com
 * @Date: 2022-09-20 14:29:26
 * @LastEditors: 纪泽龙 jizelong@qq.com
 * @LastEditTime: 2022-09-28 18:00:44
 * @FilePath: /danger-manage-web/src/views/myLessons/components/LearnItem.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div class="item flex">
    <div class="title">{{ itemData.courseType||'-' }}</div>
    <div class="lesson">{{ itemData.courseName }}</div>
    <div class="time">发布时间：{{ itemData.createTime }}</div>
    <div class="bottom flex">
      <div @click="click" class="btn" :class="{ again: yesOrNo }">
        {{ yesOrNo ? "重新考试" : "开始学习" }}
      </div>
    </div>
    <div
      class="img"
      :class="{
        no: itemData.state === 1,
        yes: itemData.state === 2,
      }"
    >
      {{ state[itemData.state] }}
    </div>
  </div>
</template>

<script>
export default {
  name: "",
  props: {
    itemData: {
      type: Object,
      default: () => {
        return {
          again: 2,
        };
      },
    },
    state: {
      type: Object,
    },
  },
  computed: {
    yesOrNo() {
      return this.itemData.state == 1 || this.itemData.state == 2;
    },
  },
  data() {
    return {};
  },
  methods: {
    click() {
      const { courseId, userCourseId, state, examinationResult, topicNum } =
        this.itemData;
      // if (!this.yesOrNo) {
        // this.$router.push("myLessons/CheckLesson");

        let fenshu;
        if (examinationResult) {
          fenshu = Math.floor((examinationResult / topicNum) * 100);
        } else {
          fenshu = 0;
        }
        this.$router.push({
          path: "myLessons/CheckLesson",
          query: { courseId, userCourseId, state, fenshu },
        });
      // } else {
      //   this.$emit("examination", { courseId, userCourseId });
      // }
      // $router.push("myLessons/CheckLesson");
    },
  },
};
</script>
<style lang="scss" scoped>
.item {
  width: 100%;
  height: 100%;
  // background: red;
  overflow: hidden;
  padding-top: 15px;
  padding-left: 18px;
  box-shadow: 0px 2px 6px 0px rgba(0, 0, 0, 0.12);
  border-radius: 5px;
  flex-direction: column;
  position: relative;
  > div {
    font-size: 14px;
  }
  .title {
    color: #606266;
    margin-bottom: 8%;
  }
  .lesson {
    color: #1d84ff;
    text-align: center;
    margin-bottom: 3%;
  }
  .time {
    text-align: center;
    font-size: 12px;
    color: #7b808a;
    margin-bottom: 5%;
  }
  .bottom {
    flex: 1;
    justify-content: center;
    .btn {
      width: 110px;
      height: 40px;
      border-radius: 4px;
      font-size: 14px;
      text-align: center;
      line-height: 40px;
      color: #1d84ff;
      border: 1px solid #a3d3ff;
      background: #e8f4ff;
      font-size: 14;
      cursor: pointer;
      &.again {
        color: #ffffff;
        border: 1px solid #a3d3ff;
        background: #1d84ff 100%;
      }
      &:hover {
        background: rgba(29, 132, 255, 0.5);
        color: #ffffff;
      }
    }
  }
  .img {
    position: absolute;
    width: 100px;
    height: 20px;
    background: #1d84ff;
    // opacity: .2;
    top: 3%;
    right: -7%;
    text-align: center;
    line-height: 20px;
    font-size: 10px;
    color: #ffffff;
    transform: rotateZ(40deg);
    &.no {
      background: #e2852a;
    }
    &.yes {
      background: #3cc426 !important;
    }
  }
}
</style>
