<template>
  <div class="timeCycleDiv" v-if="show">
    <basicPop :pop="pop" @closeClick="closeClick">
      <div class="context">
        <div v-for="(item,index) in codeList" class="codeItem">
          <div class="top">
            第{{item.position}}期({{ item.startTime | filterDate }}-{{ item.endTime | filterDate}})
          </div>

          <div class="haveCode" v-if="item.taskList.length > 0">
            <div class="head">
              <div class="item">任务类型</div>
              <div class="item" style="width:34%">完成时间</div>
              <div class="item">抽奖码</div>
              <div class="item">状态</div>
            </div>
            <div v-for="it in item.taskList" :key="it.id" class="foot">
              <div class="taskItem">{{it.taskTypeName}}</div>
              <div class="taskItem" style="width:34%">{{it.completeCreateTime | filterDate}}</div>
              <div class="taskItem">{{it.drawCode}}</div>
              <div class="taskItem">{{it.statusStr}}</div>
            </div>
          </div>
          <div class="noCode" v-else>
            <div class="noCodeMsg" style="text-align: center;">您当前暂无抽奖码，无法参与开奖</div>
            <div class="noCodeMsg" style="text-align: center;" v-if="index == 0 && isBeforeEndTime(item.endTime)">请前往活动首页报名并参与吧～</div>
          </div>
        </div>
      </div>
    </basicPop>
  </div>
</template>

<script>
  import basicPop from "./hdzxtbasicPop.vue";
  import apis1 from "../../../util/apis1.js";
  let { getMyCycleDrawCodeApi } = apis1;
  export default {
    props: [],
    components: {
      basicPop,
    },
    data() {
      return {
        pop: {
          title: '我的抽奖码',
          titlepop: ''
        },
        codeList: []
      };
    },
    created() {
      this.pop.titlepop = this.styleDataNew.titlepop ? this.styleDataNew.titlepop : { "backgroundImage": "url(//img10.360buyimg.com/imgzone/jfs/t1/141588/29/18217/44025/5fd571b9Ef55329ec/42dba91b188b9dce.png)" }
      this.pop.leftLineDiv = this.styleDataNew.leftLineDiv;
      this.pop.rightLineDiv = this.styleDataNew.rightLineDiv;
      this.pop.centerLineDiv = this.styleDataNew.centerLineDiv;
      this.pop.leftLineDiv = this.styleDataNew.leftLineDiv
      this.pop.rightLineDiv = this.styleDataNew.rightLineDiv
      document
        .querySelector("body")
        .setAttribute(
          "style",
          "position:#fixed;top:0;height:100%;overflow:hidden"
        );

      this.initData();
    },
    methods: {
      isBeforeEndTime(endTime){
         const currentTime = new Date();
          const endTimeDate = new Date(endTime);
          return currentTime < endTimeDate;
      },
      initData() {
        if (this.isTemplate == true) {

          return;
        } else {
          getMyCycleDrawCodeApi(res => {
            this.codeList = res.data
          })
        }
      },
      closeClick() {
        document.querySelector("body").removeAttribute("style");
        this.submit();
      },
    },
  };
</script>

<style lang="scss">
  .timeCycleDiv {
    .basicPopDiv {
      height: 9.13rem;
      .context {
        margin-top: 0.2rem;
        height: 7.5rem;
        font-size: 0.24rem;
        color: #333333;
        padding: 0 0.2rem;
        overflow-y: scroll;
      }
      .codeItem {
        width: 100%;
        background: #ff6870;
        margin-bottom: 0.15rem;
        display: flex;
        justify-content: center;
        flex-wrap: wrap;
        border-radius: 0.05rem;
        .top {
          width: 5.63rem;
          height: 0.38rem;
          display: flex;
          align-items: center;
          justify-content: center;
          background-image: url(//img10.360buyimg.com/imgzone/jfs/t1/291675/10/4236/810/681d6277Ff7e2e632/228ab8cd771f814b.png);
          background-size: 100%;
          font-size: 0.2rem;
          color: #f94349;
        }
        .haveCode {
          width: 100%;
          margin-top: 0.1rem;
          .head {
            width: 100%;
            height: 0.4rem;
            background: #fff;
            display: flex;
            .item {
              width: 22%;
              height: 0.4rem;
              color: #f94349;
              line-height: 0.4rem;
              text-align: center;
            }
          }
          .foot {
            width: 100%;
            display: flex;
            padding-top: .1rem;
            .taskItem {
              width: 22%;
              height: 0.5rem;
              color: #fff;
              line-height: 0.5rem;
              text-align: center;
              font-size:.18rem
            }
          }
        }
        .noCode {
          width: 100%;
          color: #fff;
          margin: 0.2rem 0;
          .noCodeMsg {
            line-height: 0.3rem;
          }
        }
      }
    }
  }
</style>
