index.js 1.78 KB
Component({
  options: {
    multipleSlots: true
  },
  /**
   * 组件的属性列表
   */
  properties: {
    show: {
      type: Boolean,
      observer: function (n) {
        if (n) {
          let date =new Date().getTime();
          console.log(date)
          this.setData({
            showPop:false,
            start: date,
            currentDate:date,
            startEffectiveTime: new Date().format(`yyyy-MM-dd`)
          })
        }
      }
    },
    confirmText: String,
    cancelText: String,
    showCancelButton: Boolean,
    success: Boolean,
    text: String
  },

  /**
   * 组件的初始数据
   */
  data: {
    timeShow:false,
    startEffectiveTime: '',
    start: '',
    formatter(type, value) {
      if (type === 'year') {
        return `${value}年`;
      }
      if (type === 'month') {
        return `${value}月`;
      }
      return value
    },
  },

  /**
   * 组件的方法列表
   */
  methods: {
    bindDateChange(e) {
      console.log(e)
      const 
        value
       = e.detail
      this.setData({
        timeShow:false,
        currentDate:value,
        startEffectiveTime: new Date(value).format(`yyyy-MM-dd`),

      })
    },
    confirm() {
      this.triggerEvent('confirm', {
        startEffectiveTime: this.data.startEffectiveTime
      })
    },
    cancel() {
      this.calcelDate()
      this.triggerEvent('cancel')
    },
    calcelDate(){
      this.setData({
        timeShow:false
      })
    },
    showPop(){
      this.setData({
        timeShow:true
      })
    }
  },
  lifetimes: {
    attached() {
      let date =new Date().getTime();
      console.log(date)
      this.setData({
        showPop:false,
        start: date,
        currentDate:date,
        startEffectiveTime: new Date().format(`yyyy-MM-dd`)
      })
    }
  }
})