import { formatTime } from '@/utils/util';

Component({
  options: { multipleSlots: true },
  /**
   * 组件的属性列表
   */
  properties: {},

  lifetimes: {
    attached() {
      // console.log('attached-----');
    },
    detached() {
      clearInterval(this.data.timer);
    },
  },
  pageLifetimes: {
    show() {
      clearInterval(this.data.timer);
      console.log('show-----');
      this.setDateMsg();
      this.data.timer = setInterval(() => {
        this.setDateMsg();
      }, 1000);
    },
    hide() {
      console.log('hide-----');
      clearInterval(this.data.timer);
    },
  },

  /**
   * 组件的初始数据
   */
  data: {
    timer: null as any,
    date: '',
    week: '',
    weekArr: ['日', '一', '二', '三', '四', '五', '六'],
  },

  /**
   * 组件的方法列表
   */
  methods: {
    setDateMsg() {
      console.log('ddd');
      this.setData({
        date: formatTime(new Date()),
        week: `星期${this.data.weekArr[new Date().getDay()]}`,
      });
    },
  },
});
