微信小程序之底部弹框预约插件

news/2024/7/5 6:48:24

代码地址如下:
http://www.demodashi.com/demo/13982.html

一、前期准备工作:

软件环境:微信开发者工具
官方下载地址:https://mp.weixin.qq.com/debug/wxadoc/dev/devtools/download.html

1、基本需求。
  • 实现用户预约
  • 时间可选
  • 预约类型更具需求可自定义
2、案例目录结构

hHgYo71E5y7srJklsvq.png

二、程序实现步骤:

1.预约index.wxml代码
    <!--index.wxml-->
    <view class="modals modals-bottom-dialog" hidden="{{hideModal}}"> 
        <view class="modals-cancel" bindtap="hideModal"></view> 
        <view class="bottom-dialog-body bottom-pos" animation="{{animationData}}">
        <view class="swiper-tab">   
          <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 == currentTab ? "current":""}}' wx:key='' data-date="{{ item.date}}">
                <text class='name'>{{ item.week }}</text>
                <text class='date'>{{ item.date }}</text>
              </view>
            </view>
          </scroll-view>
        </view>  
        <swiper current="{{currentTab}}" class="swiper-box" duration="300" style="height:500rpx">  
          <swiper-item wx:for="{{ calendar }}" wx:key='' catchtouchmove="stopTouchMove"   >
            <!-- 作品 -->     
            <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>
          </swiper-item>    
        </swiper>
        </view> 
    </view> 
    <button bindtap="showModal">点我预约</button>
2.预约index.wxss代码
/**index.wxss**/
/*模态框*/ 
.modals{
    position:fixed; 
    z-index: 999; 
    top:0; 
    left: 0; 
    right:0; 
    bottom: 0;
} 
.modals-cancel{
    position:absolute; 
    z-index:1000; 
    top:0; left: 0; 
    right:0; 
    bottom: 0; 
    background-color: rgba(0,0,0,.5);
} 
.bottom-dialog-body{
    position:absolute; 
    z-index:10001; 
    bottom:0; 
    left:0; 
    right:0; 
    height:600rpx; 
    background-color: #fff;
} 
/*动画前初始位置*/ 
.bottom-pos{
    -webkit-transform:translateY(100%);
    transform:translateY(100%);
}
/* 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: 30%;
  height: 120rpx;
  text-align: center;
  box-sizing: border-box;
  background-color: #fff;
  padding-top: 20rpx;
  border: 1px solid #b9c1c8;
  border-radius: 50rpx;
  margin-left: 5%;
  margin-bottom: 20rpx;
}
.time .listItem:first-child{  
  margin-left: 0%;
}
.time .listItem:nth-child(4){  
  margin-left: 0%;
}
.time .listItem:nth-child(7){  
  margin-left: 0%;
}
.time .listItem text{
  display: block;
  font-size: 30rpx;
}
.time .current{
  border: 1px solid #76aef8;
}
.time .current text{
  color: #76aef8;
}
3.预约index.js逻辑代码

a.遮罩层的显示、隐藏

// 显示遮罩层 
  showModal: function () { 
    var that=this; 
    that.setData({ 
      hideModal:false 
    }) 
    var animation = wx.createAnimation({ 
      duration: 600,//动画的持续时间 默认400ms 数值越大,动画越慢 数值越小,动画越快 
      timingFunction: 'ease',//动画的效果 默认值是linear 
    }) 
    this.animation = animation 
    setTimeout(function(){ 
      that.fadeIn();//调用显示动画
    },200)
  },

  // 隐藏遮罩层 
  hideModal: function () {
    var that=this;
    var animation = wx.createAnimation({
      duration: 800,//动画的持续时间 默认400ms 数值越大,动画越慢 数值越小,动画越快 
      timingFunction: 'ease',//动画的效果 默认值是linear
    })
    this.animation = animation
    that.fadeDown();//调用隐藏动画
    setTimeout(function(){
      that.setData({ hideModal:true })
    },720)//先执行下滑动画,再隐藏模块
  },

b.底部弹出动画集

  //动画集
  fadeIn:function(){
    this.animation.translateY(0).step() 
    this.setData({
      animationData: this.animation.export()//动画实例的export方法导出动画数据传递给组件的animation属性
    })
  },
  fadeDown:function(){    this.animation.translateY(300).step()
    this.setData({
      animationData: this.animation.export(),
    })
  },

c.利用构造函数创建对象,限制要渲染的日历数据天数为7天以内(用户体验)

// 计算每月第一天是星期几
    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 = ['日', '一', '二', '三', '四', '五', '六'];
    //利用构造函数创建对象
    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;
      }
    }
    //当前月份的天数
    var monthLength= getThisMonthDays(cur_year, cur_month)
    //当前月份的第一天是星期几
    var week = getFirstDayOfWeek(cur_year, cur_month)
    var x = week;
    for(var i=1;i<=monthLength;i++){
      //当循环完一周后,初始化再次循环
      if(x>6){
        x=0;
      }
      //利用构造函数创建对象
      that.data.calendar[i] = new calendar(i, [weeks_ch[x]][0])
      x++;
    }
    //限制要渲染的日历数据天数为7天以内(用户体验)
    var flag = that.data.calendar.splice(cur_date, that.data.calendar.length - cur_date <= 7 ? that.data.calendar.length:7)
    that.setData({
      calendar: flag
    })

d.点击tab切换,禁止手动滑动底部日期

/** 
   * 点击tab切换 
   */  
  swichNav: function( e ) {  
    var that = this;  
    if( this.data.currentTab === e.target.dataset.current ) {  
      return false;  
    } else {  
      that.setData( {  
        currentTab: e.target.dataset.current  
      })  
    }  
  },
  // 禁止手动滑动
  stopTouchMove: function() {
    return false;
  }

三、案例运行效果图:

Ts5wVFe3lf1VkeW6a5f.gif微信小程序之底部弹框预约插件

代码地址如下:
http://www.demodashi.com/demo/13982.html

注:本文著作权归作者,由demo大师代发,拒绝转载,转载需要作者授权


http://www.niftyadmin.cn/n/3367143.html

相关文章

web test flow

web 测试相关工具 http://www.51testing.com/?uid-94273-action-spacelist-type-blog-itemtypeid-1730 Rational Compuware Mercury TeleLogic 华为 其他 测试管理 Test Manager QA Director TestDirector Doors G…

SylixOS SPI 总线框架浅析

修订历史版本 日期 原因V1.00 2018/8/18 创建文档 目 录1 SPI总线关键结构体 11.1 总线传输控制消息块 11.2 SPI总线适配器 21.3 SPI设备 32 SPI各个结构体之间的联系 32.1 总线链表 32.2 总线与设备 33 参考资料 4 1 SPI总线关键结构体1.1 总线传输控制消息块传输控制消息包括…

OS + Linux/Unix download tools curl / wget

s 用wget下载整个网站 http://zhangyafeikimi.iteye.com/blog/385353 wget下载整个网站 可以使用下面的命令 wget -r -p -k -np http://hi.baidu.com/phps , -r 表示递归下载,会下载所有的链接,不过要注意的是,不要单独使用这个参数,因为如果你要下载的网站也有别的网站的链接…

JVM源码分析之一个Java进程究竟能创建多少线程

JVM源码分析之一个Java进程究竟能创建多少线程 原创&#xff1a; 寒泉子 你假笨 2016-12-06概述 虽然这篇文章的标题打着JVM源码分析的旗号&#xff0c;不过本文不仅仅从JVM源码角度来分析&#xff0c;更多的来自于Linux Kernel的源码分析&#xff0c;今天要说的是JVM里比较常见…

web test LoadRunner error list / error log

http://bbs.51testing.com/thread-8644-1-1.html sckOutOfMemory 7 内存不足   sckInvalidPropertyValue 380 属性值不效   sckGetNotSupported 394 属性不可读   sckGetNotSupported 383 属性是只读的   sckBadState 40006 所请求的事务或请求本身的错误协议或者错…

数组的拷贝 浅拷贝和深拷贝

1这些都是浅拷贝 Objec.assign([],obj) Array.slice(0) var data2 data.concat()&#xff1b;var arr [1,2,3,4,5] var [ ...arr2 ] arr arr[2] 5 console.log(arr) console.log(arr2) 运行结构如下&#xff1a; 2正确深拷贝姿势 for循环实现深拷贝 var obj {name: FungL…

web test LoadRunner tomcat / websphere

loadrunner监控tomcat解决方案 http://bbs.51testing.com/viewthread.php?tid142255&extra&page1 loadrunner 测试tomcatapachemysql http://auuppp.bokee.com/6935513.html loadrunner8.0监控tomcat7 JVM参数&#xff1a; loadrunner lr_decrypt() 函数加密参考 h…

双散列和再散列暨散列表总结

先说明一下&#xff0c;她们两个属于不同的范畴&#xff0c;双散列属于开放定址法&#xff0c;仍是一种解决冲突的策略。而再散列是为了解决插入操作运行时间过长、插入失败问题的策略。简而言之&#xff0c;她们的区别在于&#xff1a;前者让散列表做的“对”&#xff08;把冲…