product-detail-header.js 1.6 KB
// page/subPackage/pages/zeroSell/components/product-detail-header.js

import { fomartCountdownTime,formatTimeByDefined } from '../../../../utils/util';
Component({
  properties: {
    product: {
      type: Object,
      observer(product) {
        const {end_time: endTime, start_time: startTime, status} = product
        let nextActivityTime = ''
        if(status === 1 && endTime) {
          nextActivityTime = `${formatTimeByDefined(startTime, 'Y-M-D h:m')}-${formatTimeByDefined(endTime, 'h:m')}`
        }
        this.setData({
          formatTimeList: this.formatCountDown(),
          nextActivityTime
        });
      },
    },
    avatars: {
      type: Array,
    },
    shareFlag: {
      type: Boolean,
      value: false,
      observer(value) {
        this.setData({ show: value });
      },
    },
  },
  data: {
    show: false,
    isEnd: false,
    formatTimeList: [],
    nextActivityTime: ''
  },
  ready: function() {
    const timeId = setInterval(() => {
      if (this.data.isEnd) {
        const changeStatusTimeId = setTimeout(()=> {
          this.triggerEvent('changeStatus');
          clearTimeout(changeStatusTimeId)
        }, 1000);
        clearInterval(timeId);
      }
      const formatTimeList = this.formatCountDown();
      this.setData({
        formatTimeList: formatTimeList,
        isEnd: formatTimeList.length === 0 && this.properties.product.status === 2,
      });
    }, 1000);
  },
  methods: {
    formatCountDown() {
      // 时间单位为S
      let { end_time: endTime = 0 } = this.properties.product || {};
      return fomartCountdownTime({ endTime });
    },
  },
});