// pages/components/select-date/index.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    counts:{
      type:Number
    },
    maxDate:{
      type:Number,
      value:new Date().getTime()
    },
    minDate:{
      type:Number,
      value:new Date(2020,1,1).getTime()
    },
    currentDate:{
      type:Number,
      value:new Date().getTime()
    }
  },

  observers: {
    counts: function (val) {
      if(val){
        this.setData({
          count: val
        });
      }
    },
  },
  /**
   * 组件的初始数据
   */
  data: {
    count:3,
    formatter(type, value) {
      if (type === 'year') {
        return `${value}`;
      }
      if (type === 'month') {
        return `${value}`;
      }
      return value;
    },
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onInput(event) {
      this.setData({
        currentDate: event.detail,
      });
      let date = new Date(event.detail)
      let Y = date.getFullYear() 
      let M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) 
      let D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ''
      var lot = Y + '-' + M + '-' + D
      this.triggerEvent('change',lot)
    },
  }
})
