• 微信小程序酒店选择日期和入住人数(有效果图)


    效果图

    请添加图片描述

    请添加图片描述
    在这里插入图片描述

    app.vue

    	onLaunch:function(options){
    		this.defaultcache()
    	}
    	defaultcache(){
    		// 入住信息缓存
    		var arr = this.getDateTime();
    		var ReserVation = {
    			reservType:0,//1  人数  2日期
    			InCheckin:{},//入离日期
    			peopleArr:[
    				{title:'成人',num:2},
    				{title:'儿童',num:0},
    				{title:'宝子',num:1},
    				{title:'房间数',num:1},
    			],//入住人数
    			IntimeCur:[
    				{len:0,str:0},
    				{len:0,str:0}
    			],//选择日期
    			timeDataArr:[],//日期数组
    		}
    		ReserVation.timeDataArr = arr[0]
    		ReserVation.IntimeCur = arr[1]
    		ReserVation.InCheckin = arr[2][0]
    		uni.setStorageSync('ReserVation',ReserVation)
    	},
    	// 获取日期
    	getDateTime(){
    		var that = this
    		var showY = 3;//显示几个月
    		var timeData = [];//日期数组
    		var timestamp = Date.parse(new Date());
    		var date = new Date(timestamp);
    		//年
    		var Y = date.getFullYear();
    		//月  
    		var M = date.getMonth() + 1;
    		//日
    		var D = date.getDate();
    		// 周几和月份天数
    		var time = {};
    		var Yday = 0,Mday = 0,data = {},param = {},toDays = 2;//toDays	默认住几天
    		for(let i = 0;i < showY;i++){
    			if(12 < (M + i)){
    				Yday = Y + 1
    				Mday = (M + i) - 12
    			}else{
    				Yday = Y
    				Mday = M + i
    			}
    			time = that.getDaysInMonth(Yday,Mday)
    			data = {year:Yday,moon:Mday,arr:[],days:time.days,Z:time.Z}
    			for(let k = 0;k < time.Z;k++){
    				data.arr.push({date:''});
    			}
    			for(let j = 0;j < time.days;j++){
    				param = {};
    				param.date = j + 1;
    				param.Z = that.getDaysInMonth(Yday,Mday,param.date)
    				param.price = 0;
    				if(i == 0 && (j + 1) < D){
    					param.status = 1
    				}else if(i == 0 && (j + 1) == D){
    					param.status = 2
    				}
    				data.arr.push(param)
    			}
    			timeData.push(data)
    		}
    		var start = {
    			len:0,str:D
    		};
    		// if(that.timeData[start.len].days < (D + 1)){
    		// 	start.len = 1
    		// 	start.str = 0
    		// }
    		var end = {
    			len:0,str:D + toDays - 1
    		}
    		if(timeData[end.len].days < end.str){
    			end.str = end.str - timeData[end.len].days
    			end.len = 1
    		}
    		start.str = start.str + parseInt(timeData[start.len].Z) - 1
    		end.str = end.str + parseInt(timeData[end.len].Z) - 1
    		var timeCur = [
    			start,
    			end
    		]
    		var Checkin = {
    			start_Y:timeData[timeCur[0].len].year,
    			start_M:timeData[timeCur[0].len].moon,
    			start_D:timeData[timeCur[0].len].arr[timeCur[0].str].date,
    			start_Z:timeData[timeCur[0].len].arr[timeCur[0].str].Z,
    			end_Y:timeData[timeCur[1].len].year,
    			end_M:timeData[timeCur[1].len].moon,
    			end_D:timeData[timeCur[1].len].arr[timeCur[1].str].date,
    			end_Z:timeData[timeCur[1].len].arr[timeCur[1].str].Z,
    			days:toDays,
    		}
    		return [timeData,timeCur,[Checkin]];
    	},
    	// 获取周几和月份天数
    	getDaysInMonth(Y,M,D){
    		if(D){
    			return this.getWeekByDate(`${Y}-${M}-${D}`,true)
    		}
    		//一号周几
    		var Z = this.getWeekByDate(`${Y}-${M}-1`);
    		// 月份天数
    		var days = new Date(Y, M, 0).getDate();
    		return {Z,days}
    	},
    	// 返回周几
    	getWeekByDate(dates,status){
    	  let show_day = status?['周日', '周一', '周二', '周三', '周四', '周五', '周六']:['0', '1', '2', '3', '4', '5', '6'];
    	  let date = new Date(dates);
    	  date.setDate(date.getDate());
    	  let day = date.getDay();
    	  return show_day[day];
    	},
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121

    page-reservation.vue

    
    
    
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 170
    • 171
    • 172
    • 173
    • 174
    • 175
    • 176
    • 177
    • 178
    • 179
    • 180
    • 181
    • 182
    • 183
    • 184
    • 185
    • 186
    • 187
    • 188
    • 189
    • 190
    • 191
    • 192
    • 193
    • 194
    • 195
    • 196
    • 197
    • 198
    • 199
    • 200
    • 201
    • 202
    • 203
    • 204
    • 205
    • 206
    • 207
    • 208
    • 209
    • 210
    • 211
    • 212
    • 213
    • 214
    • 215
    • 216
    • 217
    • 218
    • 219
    • 220
    • 221
    • 222
    • 223
    • 224
    • 225
    • 226
    • 227
    • 228
    • 229
    • 230
    • 231
    • 232
    • 233
    • 234
    • 235
    • 236
    • 237
    • 238
    • 239
    • 240
    • 241
    • 242
    • 243
    • 244
    • 245
    • 246
    • 247
    • 248
    • 249
    • 250
    • 251
    • 252
    • 253
    • 254
    • 255
    • 256
    • 257
    • 258
    • 259
    • 260
    • 261
    • 262
    • 263
    • 264
    • 265
    • 266
    • 267
    • 268
    • 269
    • 270
    • 271
    • 272
    • 273
    • 274
    • 275
    • 276
    • 277
    • 278
    • 279
    • 280
    • 281
    • 282
    • 283
    • 284
    • 285
    • 286
    • 287
    • 288
    • 289
    • 290
    • 291
    • 292
    • 293
    • 294
    • 295
    • 296
    • 297
    • 298
    • 299
    • 300
    • 301
    • 302
    • 303
    • 304
    • 305
    • 306
    • 307
    • 308
    • 309
    • 310
    • 311
    • 312
    • 313
    • 314
    • 315
    • 316
    • 317
    • 318
    • 319
    • 320
    • 321
    • 322
    • 323
    • 324
    • 325
    • 326

    需要引入的.vue

    
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40

    默认选择当天和明天
    入住一次性最多选择三十天
    默认获取三个月日期数组

    存储信息
    InCheckin 选择的日期信息
    IntimeCur 组件选择的日期
    peopleArr 入住人数信息
    timeDataArr 显示的日历

    引入的组件库ColorUI组件库

    用的是uni-app

    遇到问题可以看我主页加我Q,很少看博客,对你有帮助别忘记点赞收藏。

  • 相关阅读:
    报错 - Junit 单元测试@Before没有执行
    SQL还是NoSQL?架构师必备选型技能
    postgresql源码学习(49)—— MVCC⑤-cmin与cmax 同事务内的可见性判断
    pytorch:常见的pytorch参数初始化方法总结
    Kafka多维度调优
    2024年pmp考试还有多久啊?怎么备考?
    第二部分:聚合根
    CentOS下对安装不同ModSecurity版本的Nginx的并发性能测试
    Docker 链接sqlserver时出现en-us is an invalid culture错误解决方案
    深入理解强化学习——强化学习的例子
  • 原文地址:https://blog.csdn.net/qq_43764578/article/details/137972813