<template>
  <div id="rebuild-modal">
    <el-dialog
      width="800px"
      class="rebuild"
      :visible.sync="showRebuildDetailModal"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      :show-close="false"
    >
      <div class="rebuild__content">
        <div class="rebuild__close" @click="showRebuildDetailModal = false">
          X
        </div>
        <div class="rebuild__header">审核详情</div>
        <div class="rebuild__body">
          <div class="content">
            <div class="content__header">
              <div class="title">重要提示：</div>
              <div class="desc">
                您的学时审核不通过，不通过原因如下，请查阅，并重学不通过的课程内容。
              </div>
            </div>

            <div class="content__body">
              <div class="list">
                <div
                  class="list__item"
                  v-for="(item, index) in rebuildItems"
                  :key="index"
                >
                  <div class="title">
                    <span class="note" v-if="item.type == 0"> 测试 </span>
                    <span class="note note--yellow" v-if="item.type == 1"
                      >录播</span
                    >
                    <span class="note note--yellow" v-if="item.type == 2"
                      >直播</span
                    >
                    <span class="note note--yellow" v-if="item.type == 3"
                      >回放</span
                    >
                    {{ index + 1 }}、{{ item.name }}
                  </div>
                  <div class="desc">
                    <!-- <div class="imgs">
                      <div
                        class="img"
                        v-for="(items, indexs) in item.userStudyRecordPhoto"
                        :key="indexs"
                      >
                        <img :src="$tools.splitImgHost(items.photo)" />
                        <div class="note">
                          {{ $tools.timestampToTime(items.createTime, false) }}
                        </div>
                      </div>
                    </div> -->
                  </div>
                  <div class="desc">
                    原因：
                    <span class="note">{{ item.auditReason }}</span>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
        <div class="rebuild__footer" v-if="rebuildShow">
          <el-button class="confirm" @click="rebuildSubmit" type="primary"
            >确认已阅读</el-button
          >
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
export default {
  name: "showRebuildDetailModal",
  computed: {
    ...mapGetters(["userInfo"]),
  },
  data() {
    return {
      showRebuildDetailModal: false,
      rebuildItem: {},
      rebuildItems: {},
      rebuildShow: false,
    };
  },
  mounted() {},
  methods: {
    showModal(item) {
      this.rebuildShow = false;
      this.rebuildItem = item;
      this.$request
        .getcourseperiodcheat({
          goodsId: item.goodsId,
          gradeId: item.gradeId,
        })
        .then((res) => {
          this.rebuildItems = res.rows;
          this.showRebuildDetailModal = true;

          let sysTime = this.$tools.timest();
          //学习服务期没过
          if (item.serviceEndTime && item.serviceEndTime > +sysTime) {
            console.log(1);
            this.rebuildShow = true;
          } else {
            //已过学习服务期
            console.log(2);
            this.rebuildShow = false;
            this.showRebuildDetailModal = true;
            return;
          }
          console.log(item.classEndTime, "item.classEndTime");
          console.log(sysTime, "sysTime");
          //有班级有效期
          if (item.classEndTime) {
            //班级有效期没过
            if (item.classEndTime > +sysTime) {
              console.log(3);
              this.rebuildShow = true;
            } else {
              //已过班级有效期
              this.rebuildShow = false;
              console.log(4);
              this.showRebuildDetailModal = true;
              return;
            }
          } else {
          }

          this.rebuildShow = true;
          this.showRebuildDetailModal = true;
        });
    },
    rebuildSubmit() {
      this.$request
        .courseperiodrebuild({
          goodsId: this.rebuildItem.goodsId,
          gradeId: this.rebuildItem.gradeId,
        })
        .then((res) => {
          this.showRebuildDetailModal = false;
          this.$emit("rebuildSubmit", this.rebuildItem);
          // this.$router.push({
          //   path: `/my-course-detail/${this.rebuildItem.goodsId}`,
          //   query: {
          //     gradeId: this.rebuildItem.gradeId,
          //     orderGoodsId: this.rebuildItem.orderGoodsId,
          //   },
          // });
        });
      // this.$confirm(
      //   "如对审核结果有异议，请勿点击确认重学。致电020-87085982咨询",
      //   "注意",
      //   {
      //     confirmButtonText: "确认重学",
      //     cancelButtonText: "取消",
      //     closeOnClickModal: false,
      //     closeOnPressEscape: false,
      //     distinguishCancelAndClose: false,
      //     showClose: false,
      //   }
      // )
      //   .then((_) => {
      //     this.$request
      //       .courseperiodrebuild({
      //         goodsId: this.rebuildItem.goodsId,
      //         gradeId: this.rebuildItem.gradeId,
      //       })
      //       .then((res) => {
      //         this.showRebuildDetailModal = false;
      //         this.$emit("rebuildSubmit", this.rebuildItem);
      //         // this.$router.push({
      //         //   path: `/my-course-detail/${this.rebuildItem.goodsId}`,
      //         //   query: {
      //         //     gradeId: this.rebuildItem.gradeId,
      //         //     orderGoodsId: this.rebuildItem.orderGoodsId,
      //         //   },
      //         // });
      //       });
      //   })
      //   .catch((_) => {});
    },
  },
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="scss">
.rebuild {
  /deep/ .el-dialog__header {
    display: none;
  }
  /deep/ .el-dialog__body {
    padding: 0;
    overflow: unset;
  }

  &__close {
    cursor: pointer;
    position: absolute;
    right: 0;
    top: -28px;
    width: 24px;
    height: 24px;
    line-height: 24px;
    text-align: center;
    color: #eee;
    border: 1px solid #eee;
    border-radius: 50%;
  }

  &__header {
    height: 40px;
    border-bottom: 1px solid #eee;
    line-height: 40px;
    font-size: 16px;
    font-family: Microsoft YaHei;
    font-weight: bold;
    color: #333333;
    padding-left: 24px;
  }

  &__body {
    height: 400px;
    padding: 0 24px;

    .content {
      height: 100%;
      overflow-y: auto;

      &__header {
        padding: 16px 0;
        border-bottom: 1px solid #eee;

        .title {
          font-size: 16px;
          font-family: Microsoft YaHei;
          font-weight: bold;
          color: #ff3b30;
          line-height: 24px;
        }

        .desc {
          margin-top: 10px;
          font-size: 16px;
          font-family: Microsoft YaHei;
          font-weight: 400;
          color: #ff3b30;
          line-height: 24px;
        }
      }

      &__body {
        .list {
          &__item {
            padding: 16px 0;
            border-bottom: 1px solid #eee;

            .title {
              font-size: 14px;
              font-family: Microsoft YaHei;
              font-weight: 400;
              color: #333333;

              .note {
                display: inline-block;
                text-align: center;
                line-height: 18px;
                width: 32px;
                height: 20px;
                border: 1px solid #3f8dfd;
                border-radius: 4px;
                color: #3f8dfd;
                font-size: 12px;

                &--yellow {
                  border: 1px solid #ff9500;
                  color: #ff9500;
                }
              }
            }

            .desc {
              margin-top: 10px;
              font-size: 14px;
              font-family: Microsoft YaHei;
              font-weight: 400;
              color: #333333;

              .note {
                color: #ff3b30;
                line-height: 20px;
              }

              .img {
                width: 100px;
                height: 100px;
                display: inline-block;
                text-align: center;

                img {
                  max-width: 100%;
                  max-height: 100%;
                }
              }
            }
          }
        }
      }
    }
  }

  &__footer {
    height: 90px;
    border-top: 1px solid #eee;
    text-align: center;
    .confirm {
      width: 200px;
      height: 40px;
      padding: 0;
      border-radius: 20px;
      text-align: center;
      line-height: 40px;
      color: #fff;
      margin: 24px auto;
    }
  }
}
</style>
