微信小程序?qū)崿F(xiàn)時(shí)間預(yù)約功能
一個(gè)類似電商的時(shí)間預(yù)約功能,供大家參考,具體內(nèi)容如下
1 .概述
我們?cè)趯W(xué)習(xí)微信小程序或者做項(xiàng)目時(shí),應(yīng)該會(huì)遇到需要時(shí)間預(yù)約功能情況,那么這個(gè)時(shí)間預(yù)約功能我們應(yīng)該怎么編寫呢?于是就做了一個(gè)類似電商的時(shí)間預(yù)約功能,覺(jué)得有用,就獨(dú)立出來(lái)成了個(gè)小插件,今天我們就分享這樣的小教程。希望對(duì)大家有所幫助。
不多說(shuō)了,上圖來(lái)啦!

2. wxml
<!--pages/orderTime/index.wxml-->
<view class='containt'>
<scroll-view class="scroll-view_H" scroll-x>
<view class='list' style='width:{{ width }}rpx'>
<view bindtap="select" wx:for="{{ calendar }}" wx:for-item="item" wx:for-index="index" data-index="{{ index }}" class='listItem {{index==currentIndex? "current":""}}' wx:key='' data-date="{{ item.date}}">
<text class='name'>{{ item.week }}</text>
<text class='date'>{{ item.date }}</text>
</view>
</view>
</scroll-view>
<view class='time'>
<view wx:for="{{ timeArr }}" wx:for-item="timeItem" wx:for-index="timeIndex" data-Tindex="{{ timeIndex }}" data-time="{{ timeItem.time}}" bindtap='selectTime' class='listItem {{ currentTime==timeIndex? "current":"" }}' wx:key=''>
<text>{{ timeItem.time }}</text>
<text>{{ timeItem.status }}</text>
</view>
</view>
<view class='operate'>
<button class='del'>刪除</button>
<button class='save'>保存</button>
</view>
</view>
3 . js
// pages/orderTime/index.js
Page({
/**
* 頁(yè)面的初始數(shù)據(jù)
*/
data: {
calendar:[],
width:0,
currentIndex:0,
currentTime: 0,
timeArr: [
{ "time": "8:00-10:00", "status": "約滿" },
{ "time": "8:00-10:00", "status": "約滿" },
{ "time": "8:00-10:00", "status": "約滿" },
{ "time": "8:00-10:00", "status": "約滿" },
{ "time": "8:00-10:00", "status": "約滿" },
{ "time": "8:00-10:00", "status": "約滿" },
{ "time": "8:00-10:00", "status": "約滿" },
{ "time": "8:00-10:00", "status": "約滿" },
{ "time": "8:00-10:00", "status": "約滿" },
{ "time": "8:00-10:00", "status": "約滿" },
{ "time": "8:00-10:00", "status": "約滿" },
{ "time": "8:00-10:00", "status": "約滿" },
{ "time": "8:00-22:00", "status": "約滿" }
]
},
/**
* 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面加載
*/
onLoad: function (options) {
var that=this;
function getThisMonthDays(year, month) {
return new Date(year, month, 0).getDate();
}
// 計(jì)算每月第一天是星期幾
function getFirstDayOfWeek(year, month) {
return new Date(Date.UTC(year, month - 1, 1)).getDay();
}
const date = new Date();
const cur_year = date.getFullYear();
const cur_month = date.getMonth() + 1;
const cur_date=date.getDate();
const weeks_ch = ['日', '一', '二', '三', '四', '五', '六'];
//利用構(gòu)造函數(shù)創(chuàng)建對(duì)象
function calendar(date,week){
this.date=cur_year+'-'+cur_month+'-'+date;
if(date==cur_date){
this.week = "今天";
}else if(date==cur_date+1){
this.week = "明天";
}else{
this.week = '星期' + week;
}
}
//當(dāng)前月份的天數(shù)
var monthLength= getThisMonthDays(cur_year, cur_month)
//當(dāng)前月份的第一天是星期幾
var week = getFirstDayOfWeek(cur_year, cur_month)
var x = week;
for(var i=1;i<=monthLength;i++){
//當(dāng)循環(huán)完一周后,初始化再次循環(huán)
if(x>6){
x=0;
}
//利用構(gòu)造函數(shù)創(chuàng)建對(duì)象
that.data.calendar[i] = new calendar(i, [weeks_ch[x]][0])
x++;
}
//限制要渲染的日歷數(shù)據(jù)天數(shù)為7天以內(nèi)(用戶體驗(yàn))
var flag = that.data.calendar.splice(cur_date, that.data.calendar.length - cur_date <= 7 ? that.data.calendar.length:7)
that.setData({
calendar: flag
})
//設(shè)置scroll-view的子容器的寬度
that.setData({
width: 186 * parseInt(that.data.calendar.length - cur_date <= 7 ? that.data.calendar.length : 7)
})
},
/**
* 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面顯示
*/
onShow: function () {
},
/**
* 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面隱藏
*/
onHide: function () {
},
/**
* 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面卸載
*/
onUnload: function () {
},
/**
* 頁(yè)面相關(guān)事件處理函數(shù)--監(jiān)聽(tīng)用戶下拉動(dòng)作
*/
onPullDownRefresh: function () {
},
/**
* 頁(yè)面上拉觸底事件的處理函數(shù)
*/
onReachBottom: function () {
},
/**
* 用戶點(diǎn)擊右上角分享
*/
onShareAppMessage: function () {
},
select:function(event){
//為上半部分的點(diǎn)擊事件
this.setData({
currentIndex: event.currentTarget.dataset.index
})
console.log(event.currentTarget.dataset.date)
},
selectTime:function(event){
//為下半部分的點(diǎn)擊事件
this.setData({
currentTime: event.currentTarget.dataset.tindex
})
console.log(event.currentTarget.dataset.time)
}
})
4. css
/* pages/orderTime/index.wxss */
scroll-view{
height: 128rpx;
width: 100%;
}
scroll-view .list{
display: flex;
flex-wrap: nowrap;
justify-content: flex-start;
width: 1302rpx;
}
scroll-view .listItem{
text-align: center;
width: 186rpx;
height: 128rpx;
background-color: #f1f2f6;
padding-top: 30rpx;
box-sizing: border-box;
/* float: left; */
display: inline-block;
}
scroll-view .listItem text{
display: block;
}
scroll-view .listItem .name{
font-size: 30rpx;
}
scroll-view .listItem .date{
font-size: 30rpx;
}
scroll-view .current{
background-color: #76aef8;
}
scroll-view .current text{
color: #fff;
}
.time{
width: 95%;
display: flex;
flex-wrap: wrap;
justify-content: flex-start;
margin: 0 auto;
margin-top: 30rpx;
}
.time .listItem{
width: 25%;
height: 135rpx;
text-align: center;
box-sizing: border-box;
background-color: #fff;
padding-top: 35rpx;
border: 1px solid #b9c1c8;
}
.time .listItem text{
display: block;
font-size: 30rpx;
}
.time .current{
border: 1px solid #76aef8;
}
.time .current text{
color: #76aef8;
}
.operate button{
width:300rpx;
height: 88rpx;
background-color: #fff;
}
.operate .del{
color: #e54449;
}
.operate button::after{
border: 2px solid #e54449;
}
.operate{
display: flex;
flex-wrap: nowrap;
justify-content: space-around;
}
.operate button:nth-child(2):after{
border: 2px solid #e54449;
}
.operate .save{
color: #fff;
background-color: #e54449;
}
.operate{
width: 100%;
padding: 30rpx 0;
background-color: #fff;
position: fixed;
bottom: 0;
}
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
javaScript實(shí)現(xiàn)復(fù)選框全選反選事件詳解
這篇文章主要為大家詳細(xì)介紹了javaScript實(shí)現(xiàn)復(fù)選框全選反選事件,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-09-09
微信小程序?qū)崿F(xiàn)動(dòng)態(tài)驗(yàn)證碼
這篇文章主要為大家詳細(xì)介紹了微信小程序?qū)崿F(xiàn)動(dòng)態(tài)驗(yàn)證碼,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-05-05
OpenLayer3自定義測(cè)量控件MeasureTool
這篇文章主要為大家詳細(xì)介紹了OpenLayer3自定義測(cè)量控件MeasureTool,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-09-09
動(dòng)態(tài)更新highcharts數(shù)據(jù)的實(shí)現(xiàn)方法
下面小編就為大家?guī)?lái)一篇?jiǎng)討B(tài)更新highcharts數(shù)據(jù)的實(shí)現(xiàn)方法。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-05-05
JS二叉樹的簡(jiǎn)單實(shí)現(xiàn)方法示例
這篇文章主要介紹了JS二叉樹的簡(jiǎn)單實(shí)現(xiàn)方法,結(jié)合具體實(shí)例形式分析了基于javascript定義二叉樹及二叉樹節(jié)點(diǎn)的遍歷、查找、添加、刪除及運(yùn)算相關(guān)操作技巧,需要的朋友可以參考下2017-04-04
JavaScript網(wǎng)頁(yè)禁用屏蔽常用操作小結(jié)
這篇文章主要為大家詳細(xì)介紹了網(wǎng)頁(yè)前端常用的JavaScript屏蔽操作,包括網(wǎng)絡(luò)劫持、禁止復(fù)制、禁止按鍵、清除緩存記錄等,有需要的可以了解下2024-11-11
Window.Open如何在同一個(gè)標(biāo)簽頁(yè)打開(kāi)
這篇文章主要介紹了Window.Open如何在同一個(gè)標(biāo)簽頁(yè)打開(kāi),需要的朋友可以參考下2014-06-06

