<template>
  <div class="distancebigbox" :style="styleData.distancebigbox">
    <div :style="styleData.distanceTime">
      <span>距结束:</span>
      <span>{{ day }}</span>
      <span>天</span>
      <span>{{ hour }}</span>
      <span>时</span>
      <span>{{ minute }}</span>
      <span>分</span>
      <span>{{ second }}</span>
      <span>秒</span>
    </div>
  </div>
</template>
<script>
import apis1 from "../../../util/apis1.js";
import bus from "../../../util/bus.js";
let { getWinnerData } = apis1;
export default {
  props: ["isTemplate", "datas", "keyData", "styleData", "templateData"],
  data() {
    return {
      day: 0, //天
      hour: 0, //时
      minute: 0, //分
      second: 0, //秒
      startTime: true, //起始时间
      timer: {}, //时间数据
      nowTime: null, //当前时间
      endTime: null, //结束时间
    };
  },
  created() {
    this.initData();
  },
  methods: {
    initData() {
      bus.$on("initdata", (content) => {
        this.timer = content.data; //接收初始化数据
        this.endTime = this.timer.endTime; //将时间戳转换为时间
        console.log(this.startTime);
      });
      setInterval(() => {
        //定时器计算时间
        if (this.isTemplate == true) {
          this.nowTime -= 1000;
        } else {
          this.nowTime = new Date().getTime(); //获取当前时间
        }
        var time = (this.endTime - this.nowTime) / 1000; //计算总时间
        this.day = Math.floor(time / (24 * 60 * 60)); //做时间处理
        this.hour = Math.floor((time % (24 * 60 * 60)) / (60 * 60)); //做时间处理
        this.minute = Math.floor(((time % (24 * 60 * 60)) % (60 * 60)) / 60); //做时间处理
        this.second = Math.floor(((time % (24 * 60 * 60)) % (60 * 60)) % 60); //做时间处理
        if (this.day < 10) {
          //如果判定为一位数
          this.day = "0" + this.day;
        }
        if (this.hour < 10) {
          //如果判定为一位数
          this.hour = "0" + this.hour;
        }
        if (this.minute < 10) {
          //如果判定为一位数
          this.minute = "0" + this.minute;
        }
        if (this.second < 10) {
          //如果判定为一位数
          this.second = "0" + this.second;
        }
        this.moveEndTime = //计算结果
          this.day +
          "天" +
          this.hour +
          "时" +
          this.minute +
          "分" +
          this.second +
          "秒";
      }, 1000);
    },
  },
};
</script>