小程序模板網(wǎng)

微信小程序日歷選擇-類似酒店預(yù)訂方式有節(jié)日標(biāo)識

發(fā)布時間:2018-06-08 10:15 所屬欄目:小程序開發(fā)教程

微信小程序的日歷選擇,主要針對酒店選擇時間段的日歷,帶有公歷的節(jié)日。

主要函數(shù): 
通過選擇入住與離店時間,記錄對應(yīng)的時間段,判斷選擇的開始時間和結(jié)束時間,通過改變背影顏色連成對應(yīng)時間段。

  selectDataMarkLine: function () {
 let dateList = this.data.dateList;
 let { checkInDate, checkOutDate } = wx.getStorageSync("ROOM_SOURCE_DATE");
 let curreInid = checkInDate.substr(0, 4) + "-" + (checkInDate.substr(5, 2) < 10 ? checkInDate.substr(6, 1) : checkInDate.substr(5, 2));//選擇入住的id
 let curreOutid = checkOutDate.substr(0, 4) + "-" + (checkOutDate.substr(5, 2) < 10 ? checkOutDate.substr(6, 1) : checkOutDate.substr(5, 2));//選擇離店的id
 let dayIn = checkInDate.substr(8, 2) >= 10 ? checkInDate.substr(8, 2) : checkInDate.substr(9, 1);//選擇入住的天id
 let dayOut = checkOutDate.substr(8, 2) >= 10 ? checkOutDate.substr(8, 2) : checkOutDate.substr(9, 1);//選擇離店的天id
 let monthIn = checkInDate.substr(5, 2) >= 10 ? checkInDate.substr(5, 2) : checkInDate.substr(6, 1);//選擇入店的月id
 let monthOut = checkOutDate.substr(5, 2) >= 10 ? checkOutDate.substr(5, 2) : checkOutDate.substr(6, 1);//選擇離店的月id
 if (curreInid == curreOutid) {//入住與離店是當(dāng)月的情況
 for (let i = 0; i < dateList.length; i++) {
 if (dateList[i].id == curreInid) {
 let days = dateList[i].days;
 for (let k = 0; k < days.length; k++) {
 if (days[k].day >= dayIn && days[k].day <= dayOut) {
              days[k].class = days[k].class + ' bgitem';
 }
 if (days[k].day == dayIn) {
              days[k].class = days[k].class + ' active';
              days[k].inday = true;
 }
 if (days[k].day == dayOut) {
              days[k].class = days[k].class + ' active';
              days[k].outday = true;
 }
 }
 }
 }
 } else {//跨月
 for (let j = 0; j < dateList.length; j++) {
 if (dateList[j].month == monthIn) {//入住的開始月份
 let days = dateList[j].days;
 for (let k = 0; k < days.length; k++) {
 if (days[k].day >= dayIn) {
              days[k].class = days[k].class + ' bgitem';
 }
 if (days[k].day == dayIn) {
              days[k].class = days[k].class + ' active';
              days[k].inday = true;
 }
 }
 } else {//入住跨月月份
 if (dateList[j].month < monthOut) {//離店中間的月份
 let days = dateList[j].days;
 for (let k = 0; k < days.length; k++) {
              days[k].class = days[k].class + ' bgitem';
 }
 } else if (dateList[j].month == monthOut) {//離店最后的月份
 let days = dateList[j].days;
 for (let k = 0; k < days.length; k++) {
 if (days[k].day <= dayOut) {
                days[k].class = days[k].class + ' bgitem';
 }
 if (days[k].day == dayOut) {
                days[k].class = days[k].class + ' active';
                days[k].outday = true;
 }
 }
 }
 }
 }
 }
 this.setData({
      dateList: dateList
 })
 },

 

效果圖:

 


本文地址:http://22321a.com/wxmini/doc/course/24516.html 復(fù)制鏈接 如需定制請聯(lián)系易優(yōu)客服咨詢:800182392 點擊咨詢
QQ在線咨詢