export default {
  data() {
    return {
      d: null,
      h: null,
      m: null,
      s: null
    }
  },
  computed: {
    day: {
      get () {
        return this.d
      },
      set () {
        //
      }
    },
    hours: {
      get () {
        return this.h
      },
      set () {
        //
      }
    },
    minutes: {
      get () {
        return this.m
      },
      set () {
        //
      }
    },
    seconds: {
      get () {
        return this.s
      },
      set () {
        //
      }
    }
  },
  methods: {
    timeFn(d1) {
      const dateDiff = d1 - new Date().getTime() // 时间差的毫秒数
      const dayDiff = Math.floor(dateDiff / (24 * 3600 * 1000)) // 计算出相差天数
      const leave1 = dateDiff % (24 * 3600 * 1000) // 计算天数后剩余的毫秒数
      const hours = Math.floor(leave1 / (3600 * 1000)) // 计算出小时数
      // 计算相差分钟数
      const leave2 = leave1 % (3600 * 1000) // 计算小时数后剩余的毫秒数
      const minutes = Math.floor(leave2 / (60 * 1000)) // 计算相差分钟数
      // 计算相差秒数
      const leave3 = leave2 % (60 * 1000) // 计算分钟数后剩余的毫秒数
      const seconds = Math.round(leave3 / 1000)
      this.d = dayDiff
      this.h = hours
      this.m = minutes
      this.s = seconds
      // console.log(" 相差 "+dayDiff+"天 "+hours+"小时 "+minutes+" 分钟"+seconds+" 秒")
      // console.log(dateDiff+"时间差的毫秒数",dayDiff+"计算出相差天数",leave1+"计算天数后剩余的毫秒数",hours+"计算出小时数",minutes+"计算相差分钟数",seconds+"计算相差秒数");
    }
  }
}
