当前位置:   article > 正文

如何快速制作微信小程序预约功能--在这里只要十分钟_做一个线上预约的小程序

做一个线上预约的小程序

2449059-15c88236f80fc6ba.jpg

0.jpg

1 .概述

我们在学习微信小程序或者做项目时,应该会遇到需要时间预约功能情况,那么这个时间预约功能我们应该怎么编写呢?于是就做了一个类似电商的时间预约功能,觉得有用,就独立出来成了个小插件,今天我们就分享这样的小教程。希望对大家有所帮助。

不多说了,二当家要上图来啦!

2449059-8c1f270f93621823

image

更多自ji关注下载

2. wxml

  1. <!--pages/orderTime/index.wxml-->
  2. <view class='containt'>
  3. <scroll-view class="scroll-view_H" scroll-x>
  4. <view class='list' style='width:{{ width }}rpx'>
  5. <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}}">
  6. <text class='name'>{{ item.week }}</text>
  7. <text class='date'>{{ item.date }}</text>
  8. </view>
  9. </view>
  10. </scroll-view>
  11. <view class='time'>
  12. <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=''>
  13. <text>{{ timeItem.time }}</text>
  14. <text>{{ timeItem.status }}</text>
  15. </view>
  16. </view>
  17. <view class='operate'>
  18. <button class='del'>删除</button>
  19. <button class='save'>保存</button>
  20. </view>
  21. </view>

3 . js

  1. // pages/orderTime/index.js
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. calendar:[],
  8. width:0,
  9. currentIndex:0,
  10. currentTime: 0,
  11. timeArr: [
  12. { "time": "8:00-10:00", "status": "约满" },
  13. { "time": "8:00-10:00", "status": "约满" },
  14. { "time": "8:00-10:00", "status": "约满" },
  15. { "time": "8:00-10:00", "status": "约满" },
  16. { "time": "8:00-10:00", "status": "约满" },
  17. { "time": "8:00-10:00", "status": "约满" },
  18. { "time": "8:00-10:00", "status": "约满" },
  19. { "time": "8:00-10:00", "status": "约满" },
  20. { "time": "8:00-10:00", "status": "约满" },
  21. { "time": "8:00-10:00", "status": "约满" },
  22. { "time": "8:00-10:00", "status": "约满" },
  23. { "time": "8:00-10:00", "status": "约满" },
  24. { "time": "8:00-22:00", "status": "约满" }
  25. ]
  26. },
  27. /**
  28. * 生命周期函数--监听页面加载
  29. */
  30. onLoad: function (options) {
  31. var that=this;
  32. function getThisMonthDays(year, month) {
  33. return new Date(year, month, 0).getDate();
  34. }
  35. // 计算每月第一天是星期几
  36. function getFirstDayOfWeek(year, month) {
  37. return new Date(Date.UTC(year, month - 1, 1)).getDay();
  38. }
  39. const date = new Date();
  40. const cur_year = date.getFullYear();
  41. const cur_month = date.getMonth() + 1;
  42. const cur_date=date.getDate();
  43. const weeks_ch = ['日', '一', '二', '三', '四', '五', '六'];
  44. //利用构造函数创建对象
  45. function calendar(date,week){
  46. this.date=cur_year+'-'+cur_month+'-'+date;
  47. if(date==cur_date){
  48. this.week = "今天";
  49. }else if(date==cur_date+1){
  50. this.week = "明天";
  51. }else{
  52. this.week = '星期' + week;
  53. }
  54. }
  55. //当前月份的天数
  56. var monthLength= getThisMonthDays(cur_year, cur_month)
  57. //当前月份的第一天是星期几
  58. var week = getFirstDayOfWeek(cur_year, cur_month)
  59. var x = week;
  60. for(var i=1;i<=monthLength;i++){
  61. //当循环完一周后,初始化再次循环
  62. if(x>6){
  63. x=0;
  64. }
  65. //利用构造函数创建对象
  66. that.data.calendar[i] = new calendar(i, [weeks_ch[x]][0])
  67. x++;
  68. }
  69. //限制要渲染的日历数据天数为7天以内(用户体验)
  70. var flag = that.data.calendar.splice(cur_date, that.data.calendar.length - cur_date <= 7 ? that.data.calendar.length:7)
  71. that.setData({
  72. calendar: flag
  73. })
  74. //设置scroll-view的子容器的宽度
  75. that.setData({
  76. width: 186 * parseInt(that.data.calendar.length - cur_date <= 7 ? that.data.calendar.length : 7)
  77. })
  78. },
  79. /**
  80. * 生命周期函数--监听页面初次渲染完成
  81. */
  82. onReady: function () {
  83. },
  84. /**
  85. * 生命周期函数--监听页面显示
  86. */
  87. onShow: function () {
  88. },
  89. /**
  90. * 生命周期函数--监听页面隐藏
  91. */
  92. onHide: function () {
  93. },
  94. /**
  95. * 生命周期函数--监听页面卸载
  96. */
  97. onUnload: function () {
  98. },
  99. /**
  100. * 页面相关事件处理函数--监听用户下拉动作
  101. */
  102. onPullDownRefresh: function () {
  103. },
  104. /**
  105. * 页面上拉触底事件的处理函数
  106. */
  107. onReachBottom: function () {
  108. },
  109. /**
  110. * 用户点击右上角分享
  111. */
  112. onShareAppMessage: function () {
  113. },
  114. select:function(event){
  115. //为上半部分的点击事件
  116. this.setData({
  117. currentIndex: event.currentTarget.dataset.index
  118. })
  119. console.log(event.currentTarget.dataset.date)
  120. },
  121. selectTime:function(event){
  122. //为下半部分的点击事件
  123. this.setData({
  124. currentTime: event.currentTarget.dataset.tindex
  125. })
  126. console.log(event.currentTarget.dataset.time)
  127. }
  128. })

4. css

  1. /* pages/orderTime/index.wxss */
  2. scroll-view{
  3. height: 128rpx;
  4. width: 100%;
  5. }
  6. scroll-view .list{
  7. display: flex;
  8. flex-wrap: nowrap;
  9. justify-content: flex-start;
  10. width: 1302rpx;
  11. }
  12. scroll-view .listItem{
  13. text-align: center;
  14. width: 186rpx;
  15. height: 128rpx;
  16. background-color: #f1f2f6;
  17. padding-top: 30rpx;
  18. box-sizing: border-box;
  19. /* float: left; */
  20. display: inline-block;
  21. }
  22. scroll-view .listItem text{
  23. display: block;
  24. }
  25. scroll-view .listItem .name{
  26. font-size: 30rpx;
  27. }
  28. scroll-view .listItem .date{
  29. font-size: 30rpx;
  30. }
  31. scroll-view .current{
  32. background-color: #76aef8;
  33. }
  34. scroll-view .current text{
  35. color: #fff;
  36. }
  37. .time{
  38. width: 95%;
  39. display: flex;
  40. flex-wrap: wrap;
  41. justify-content: flex-start;
  42. margin: 0 auto;
  43. margin-top: 30rpx;
  44. }
  45. .time .listItem{
  46. width: 25%;
  47. height: 135rpx;
  48. text-align: center;
  49. box-sizing: border-box;
  50. background-color: #fff;
  51. padding-top: 35rpx;
  52. border: 1px solid #b9c1c8;
  53. }
  54. .time .listItem text{
  55. display: block;
  56. font-size: 30rpx;
  57. }
  58. .time .current{
  59. border: 1px solid #76aef8;
  60. }
  61. .time .current text{
  62. color: #76aef8;
  63. }
  64. .operate button{
  65. width:300rpx;
  66. height: 88rpx;
  67. background-color: #fff;
  68. }
  69. .operate .del{
  70. color: #e54449;
  71. }
  72. .operate button::after{
  73. border: 2px solid #e54449;
  74. }
  75. .operate{
  76. display: flex;
  77. flex-wrap: nowrap;
  78. justify-content: space-around;
  79. }
  80. .operate button:nth-child(2):after{
  81. border: 2px solid #e54449;
  82. }
  83. .operate .save{
  84. color: #fff;
  85. background-color: #e54449;
  86. }
  87. .operate{
  88. width: 100%;
  89. padding: 30rpx 0;
  90. background-color: #fff;
  91. position: fixed;
  92. bottom: 0;
  93. }

5 . 总结

注:如未能获取成功,或者遇到其他问题,本人微信:geekxz 。

如果需要更多动画,欢迎关注 【极客小寨】微信公众号,回复微信小程序预约下载链接!或者回复资源,获取更多有用技术干货、文档资料。所有文档会持续更新,欢迎关注一起成长!

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/307017
推荐阅读
相关标签
  

闽ICP备14008679号