小程序日期选择组件

小程序日期选择组件(适用于酒店入住日期)

效果图

小记:2020年2月3日13:08:00
今天天气阴,受新冠状病毒的影响,公司推迟上班,闲着在家无聊,写下第一篇博客,整理之前写过的组件,方便以后还会用到,也方便各位小伙伴们借鉴,如果哪里写不对了望各位大佬指出,谢谢!

组件代码部分
// components/date-modal/date-modal.js
const common = require("../../utils/util.js")
Component({
   
  /**
   * 组件的属性列表
   */
  properties: {
   
    isshowDatemodal:{
   
      type: [Boolean],
      value: false
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
   
    timearr:[],
    DateData:{
   },
    selectIndex:0,
    selectTime:"00:00",
    dateCycle: ['周日', '周一', '周二', '周三', '周四', '周五', '周六']
  },
  lifetimes:{
   
    attached: function() {
   
      // 在组件实例进入页面节点树时执行
      let timearr = []
      for(let i = 0; i< 24; i++) {
   
      if (i < 10) {
   
        i = "0" + i
      }
      timearr.push(i + ":00")
      timearr.push(i + ":30")
    }



    this.setData({
   
      timearr: timearr,
      DateData: common.GetDateMonthDay(new Date())
    })
    //console.log(common.GetDateMonthDay(new Date()))
    },
  },
  pageLifetimes: {
   
    // 组件所在页面的生命周期函数
  show() {
   
     
    }



    },

  /**
   * 组件的方法列表
   */
  methods: {
   
    touchmove(e) {
   
      return false 
    },
    //关闭日期
    closeDateBtn(){
   
      this.setData({
   
        isshowDatemodal:false
      })
    },
    //时间选择
    selectTimeBtn(e){
   
      let time=this.data.timearr[e.detail.value[0]]
      //console.log(time)
      this.setData({
   
        selectTime:time
      })

    },
    //日期选择
    selectDateBtn(e) {
   
      let index = e.currentTarget.dataset.index
      let month=e.currentTarget.dataset.month
      let year=e.currentTarget.dataset.year
        if (index >= this.data.DateData.today||this.data.DateData.ymarr[0].month!=month) {
   
          this.data.DateData.selectday = index
          this.data.DateData.selectmonth = month
          this.data.DateData.selectyear = year
          this.setData({
   
            DateData: this.data.DateData
          })
         
        }
    },
    //即时入住 
    nowDateBtn(e){
   
      //console.log(this.data.DateData.selectdate)
      let times = common.getNowTimes()
      let today = this.data.DateData.selectdate
      this.triggerEvent('todayEven', {
    today, times})
      this.closeDateBtn();
    },
    //确认日期
    ortherDateBtn(e) {
   
      let date=this.data.DateData
      let selectTime=this.data.selectTime
      this.triggerEvent('dateModalData', {
   
        datetime: date.selectyea
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值