CalendarMonth.js 3.41 KB
// components/Calendar/Calendar.js
import Calendar from './Calendar_Function'
import _component_ from './Static_Properties'
const CalendarFunction = Symbol('CalendarFunction')

Component({
  /**
   * 组件的属性列表
   */
  properties: _component_.properties,

  /**
   * 组件的初始数据
   */
  data: _component_.data,

  /**
   * 组件的方法列表
   */
  methods: {
    noScroll() {},
    setCalenderBodyHeight() {
      this[CalendarFunction].setCalenderBodyHeight()
    },
    showCalendar(e) {
      let type = (e && e.currentTarget && e.currentTarget.dataset.type) || ''
      let result = type === 'show'
      if (!result) {
        this.setData({
          hideCalendar: true
        })
        setTimeout(() => {
          this.setData({
            show: result,
            hideCalendar: false
          })
        }, 300)
      } else {
        this.setData({
          show: result
        })
        if (!this.data.calenderBodyHeight) this[CalendarFunction].setCalenderBodyHeight()
      }
      this.triggerEvent('tapCalendar')
    },
    dateChange(e) {
      let { current, source } = e.detail
      // console.log(source)
      console.log(current)
      /**
       * 根据官方 source 来进行判断swiper的change事件是通过什么来触发的,autoplay是自动轮播。
       * touch是用户手动滑动。其他的就是未知问题。抖动问题主要由于未知问题引起的,所以做了限制
       * 只有在自动轮播和用户主动触发才去改变current值,达到规避了抖动bug
       */
      source == 'touch' &&
        this.setData({
          current
        })
    },
    bindDateChange: function (e) {
      var date = e.detail.value
      console.log(date)
      this.setData({
        date: date
      })
      this.post_data.year = date
      this.renderHtml()
    },
    choose(e) {
      let { dateType, minDate, maxDate } = this.data
      let { data } = e.currentTarget.dataset
      // console.log((minDate && Date.parse(minDate) > Date.parse(data)) || (maxDate && Date.parse(maxDate) < Date.parse(data)))
      console.log(minDate && Date.parse(minDate) > Date.parse(data))
      console.log(maxDate && Date.parse(maxDate) < Date.parse(data))
      if ((minDate && Date.parse(minDate) > Date.parse(data)) || (maxDate && Date.parse(maxDate) < Date.parse(data))) return
      this[CalendarFunction][dateType](e)
    },
    monChoose(e) {
      let { dateType } = this.data
      let { data, type } = e.currentTarget.dataset
      if (data.disable) return false
      this[CalendarFunction][dateType](e)
    },
    done() {
      let { dateType } = this.data
      this[CalendarFunction].done(dateType)
    },
    changeDate(e) {
      let { value } = e.detail
      console.log(value)
      this.setData({
        current: value
      })
    },
    bindYearChange(e) {
      let { value } = e.detail
      this.setData({
        yearCurrent: value
      })
    },
    showShortcutPicker() {
      this.setData({
        showShortcut: !this.data.showShortcut
      })
    },
    showShortcutPickerYear() {
      this.setData({
        showShortcutYear: !this.data.showShortcutYear
      })
    },
    chooseAll() {
      this[CalendarFunction].chooseAll()
    },
    changeModel() {
      let { dayType } = this.data
      this.setData({
        dayType: dayType == 0 ? 1 : 0
      })
    }
  },
  ready() {
    // console.log(this)
    // return
    this[CalendarFunction] = new Calendar(this)
  }
})