微信小程序:酒店訂房之時間選擇器 picker


下單頁面,選擇開始日期和結束日期,不廢話,直接代碼:

1、wxml:

  <picker mode="date" value="{{date1}}" start="2010-01-01" end="2030-12-31" bindchange="bindDateChange">
    <view class="form_group">
        <text>住房時間:</text>
        <text class="textss" style="width:460rpx;text-align:left;">{{date1}}</text>
    </view>
  </picker>
  <picker mode="date" value="{{date2}}" start="2010-01-01" end="2030-12-31" bindchange="bindDateChangeTwo">
    <view class="form_group">
        <text>退房時間:</text>
        <text class="textss" style="width:460rpx;text-align:left;">{{date2}}</text>
    </view>
  </picker>

2、js:

page({
    ...

//為picker綁定方法: 其中獲得的時間為2017-06-01格式的。
bindDateChange: function (e) {
    var that = this;
    that.setData({
      date1: e.detail.value
    })
    console.log(that.data.date1);
  },
  bindDateChangeTwo: function (e) {
    var that = this;
    that.setData({
      date2: e.detail.value
    })
    console.log(that.data.date2);
  },
//表單提交
 submitForm: function(e){
   //字符串轉換為時間戳,單位毫秒
    var date1 = new Date(Date.parse(that.data.date1.replace(/-/g, "/")));
    var date_in = date1.getTime();
    var date2 = new Date(Date.parse(that.data.date2.replace(/-/g, "/")));
    var date_out = date2.getTime();
  if (that.data.is_home == 1 && date1 >= date2 ){

      wx.showToast({

        title: '退房時間必須大於住房時間!',

        icon: 'loading',

        duration: 1500

      })

      setTimeout(function () {

        wx.hideToast()

      }, 2000) 
    } else if (that.data.is_home==1&& date1<Date.parse(new Date())-86400000 ) {

      wx.showToast({

        title: '住房時間不能小於當前時間!',

        icon: 'loading',

        duration: 1500

      })

      setTimeout(function () {

        wx.hideToast()

      }, 2000)      

     } else{
          //處理表單的code,自己來
     }
  }
})

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM