Calendar.js 3.21 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() { },
    /** 日期手动改 */
    resetData(date) {
      // let _this = this[_CalendarObject_]
      let { monthList, current } = this.data
      console.log(monthList)
      console.log(date)
      // return
      monthList.map(x => {
        x.data.map(i => (i.active = false))
      })

      monthList.map((item, index) => {
        item.data.map(ele => {
          if (ele.data == date) {
            console.log(ele.data)
            console.log(current)
            ele.active = true
            current = index
          }
        })
      })
      this.setData({
        monthList,
        current
      })
    },
    // resetData(date) {
    //   // console.log(this.resetData)
    //   // this.getUserDayReport(n)[CalendarFunction]
    //   // this[CalendarFunction].resetData(date)
    //   // console.log(date)
    //   // console.log(this[CalendarFunction].setCalenderBodyHeight)
    // },
    setCalenderBodyHeight() {
      this[CalendarFunction].setCalenderBodyHeight()
    },
    showCalendar(e) {
      console.log(e)
      let { disabled } = this.data
      if (disabled) return false;
      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()
      }
    },
    dateChange(e) {
      let { current, source } = e.detail
      /**
       * 根据官方 source 来进行判断swiper的change事件是通过什么来触发的,autoplay是自动轮播。
       * touch是用户手动滑动。其他的就是未知问题。抖动问题主要由于未知问题引起的,所以做了限制
       * 只有在自动轮播和用户主动触发才去改变current值,达到规避了抖动bug
       */
      source == 'touch' &&
        this.setData({
          current
        })
    },
    choose(e) {
      let { dateType, minDate, maxDate } = this.data
      let { data } = e.currentTarget.dataset
      if ((minDate && Date.parse(minDate) > Date.parse(data)) || (maxDate && Date.parse(maxDate) < Date.parse(data))) return
      this[CalendarFunction][dateType](e)
    },
    done() {
      let { dateType } = this.data
      this[CalendarFunction].done(dateType)
    },
    changeDate(e) {
      let { value } = e.detail
      this.setData({
        current: value
      })
    },
    showShortcutPicker() {
      this.setData({
        showShortcut: !this.data.showShortcut
      })
    },
    chooseAll() {
      this[CalendarFunction].chooseAll()
    }
  },
  ready() {
    this[CalendarFunction] = new Calendar(this)
  }
})