master
			
			
		
		
							parent
							
								
									c9c3a20268
								
							
						
					
					
						commit
						e88999738c
					
				| @ -0,0 +1,109 @@ | |||||||
|  | // pages/select1/select1.js
 | ||||||
|  | Page({ | ||||||
|  |   data: { | ||||||
|  |     foodlist:[], | ||||||
|  |     tabs: ['主食','小吃'], | ||||||
|  |     index:null, | ||||||
|  |    current:'', | ||||||
|  |     re:[], | ||||||
|  |     selectlist:[] | ||||||
|  |   }, | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |   tabSelect:function(e){ | ||||||
|  |     var foodlist=[] | ||||||
|  |     var current = e.currentTarget.dataset.tab | ||||||
|  |     this.setData({ | ||||||
|  |       current:current | ||||||
|  |     }) | ||||||
|  | 
 | ||||||
|  |     const _ = wx.cloud.database().command | ||||||
|  |     console.log(current) | ||||||
|  |     wx.cloud.database().collection('food').where(_.or([ | ||||||
|  |       { | ||||||
|  |         tab: wx.cloud.database().RegExp({ | ||||||
|  |           regexp: this.data.current, | ||||||
|  |           options: 'i', | ||||||
|  |       }) | ||||||
|  |     } | ||||||
|  |     ]) | ||||||
|  |     ) | ||||||
|  |     .get() | ||||||
|  |     .then(res => { | ||||||
|  |             this.setData({ | ||||||
|  |                 foodlist: res.data, | ||||||
|  |             }) | ||||||
|  |             wx.hideLoading({ | ||||||
|  |               }) | ||||||
|  |             wx.setStorageSync('foodlist', res.data) | ||||||
|  |             let foodlist= wx.getStorageSync('foodlist') | ||||||
|  |             console.log(foodlist) | ||||||
|  |              | ||||||
|  |           | ||||||
|  |   }), | ||||||
|  |      | ||||||
|  |    wx.navigateTo({ | ||||||
|  |     url: '/pages/select2/select2?info='+JSON.stringify(this.data.foodlist) | ||||||
|  |   }) | ||||||
|  | }, | ||||||
|  |   /** | ||||||
|  |    * 页面的初始数据 | ||||||
|  |    */ | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |   /** | ||||||
|  |    * 生命周期函数--监听页面加载 | ||||||
|  |    */ | ||||||
|  |   onLoad(options) { | ||||||
|  | 
 | ||||||
|  |   }, | ||||||
|  | 
 | ||||||
|  |   /** | ||||||
|  |    * 生命周期函数--监听页面初次渲染完成 | ||||||
|  |    */ | ||||||
|  |   onReady() { | ||||||
|  | 
 | ||||||
|  |   }, | ||||||
|  | 
 | ||||||
|  |   /** | ||||||
|  |    * 生命周期函数--监听页面显示 | ||||||
|  |    */ | ||||||
|  |   onShow() { | ||||||
|  | 
 | ||||||
|  |   }, | ||||||
|  | 
 | ||||||
|  |   /** | ||||||
|  |    * 生命周期函数--监听页面隐藏 | ||||||
|  |    */ | ||||||
|  |   onHide() { | ||||||
|  | 
 | ||||||
|  |   }, | ||||||
|  | 
 | ||||||
|  |   /** | ||||||
|  |    * 生命周期函数--监听页面卸载 | ||||||
|  |    */ | ||||||
|  |   onUnload() { | ||||||
|  | 
 | ||||||
|  |   }, | ||||||
|  | 
 | ||||||
|  |   /** | ||||||
|  |    * 页面相关事件处理函数--监听用户下拉动作 | ||||||
|  |    */ | ||||||
|  |   onPullDownRefresh() { | ||||||
|  | 
 | ||||||
|  |   }, | ||||||
|  | 
 | ||||||
|  |   /** | ||||||
|  |    * 页面上拉触底事件的处理函数 | ||||||
|  |    */ | ||||||
|  |   onReachBottom() { | ||||||
|  | 
 | ||||||
|  |   }, | ||||||
|  | 
 | ||||||
|  |   /** | ||||||
|  |    * 用户点击右上角分享 | ||||||
|  |    */ | ||||||
|  |   onShareAppMessage() { | ||||||
|  | 
 | ||||||
|  |   } | ||||||
|  | }) | ||||||
| @ -0,0 +1,3 @@ | |||||||
|  | { | ||||||
|  |   "usingComponents": {} | ||||||
|  | } | ||||||
| @ -0,0 +1,7 @@ | |||||||
|  | <!--pages/select1/select1.wxml--> | ||||||
|  | <view > | ||||||
|  | <text class="title">选择您需要的食物类型</text> | ||||||
|  | </view> | ||||||
|  | <view wx:for="{{tabs}}"> | ||||||
|  |   <view class="button" hover-class="button_hover" bindtap="tabSelect" data-tab="{{item}}">{{item}}</view> | ||||||
|  | </view> | ||||||
| @ -0,0 +1,30 @@ | |||||||
|  | /* pages/select1/select1.wxss */ | ||||||
|  | .title{ | ||||||
|  |   font-family:fantasy; | ||||||
|  |   font-size: larger; | ||||||
|  |   font-style:italic; | ||||||
|  |   text-align: center; | ||||||
|  |   font: weight 700; | ||||||
|  |    | ||||||
|  | } | ||||||
|  | .button{ | ||||||
|  |   font-family:fantasy; | ||||||
|  |   font-size: larger; | ||||||
|  |   width: 80%; | ||||||
|  |   height: 100rpx; | ||||||
|  |   margin: 100rpx; | ||||||
|  |   background-color: rgb(137, 186, 192); | ||||||
|  |   color: rgb(57, 65, 71); | ||||||
|  |   border-radius: 98rpx;  | ||||||
|  |   text-align: center; | ||||||
|  |   vertical-align: center; | ||||||
|  |   line-height: 100rpx; | ||||||
|  |   margin: 0 auto; | ||||||
|  |   font-weight: bolder; | ||||||
|  | 
 | ||||||
|  | } | ||||||
|  | .button_hover{ | ||||||
|  |   position: relative; | ||||||
|  |   top: 3rpx; | ||||||
|  |   box-shadow:0px 0px 8px #999 inset;  | ||||||
|  | } | ||||||
| @ -0,0 +1,137 @@ | |||||||
|  | // pages/select1/select1.js
 | ||||||
|  | Page({ | ||||||
|  |   data: { | ||||||
|  |     foodlist:[], | ||||||
|  |     tastes: ['香辣','香咸','酸甜','椒麻'], | ||||||
|  |     index:null, | ||||||
|  |     current:'', | ||||||
|  |     re:[], | ||||||
|  |     selectlist:[] | ||||||
|  |   }, | ||||||
|  |    | ||||||
|  | 
 | ||||||
|  | tasteSelect:function(e){ | ||||||
|  | var taste=e.currentTarget.dataset.taste | ||||||
|  | console.log(taste) | ||||||
|  | var foodlist=this.data.foodlist | ||||||
|  | console.log(foodlist) | ||||||
|  | var foodlistselect=[] | ||||||
|  | console.log(foodlist[1].taste) | ||||||
|  | //对食物进行筛选
 | ||||||
|  | for(var i=0;i<foodlist.length;i++){ | ||||||
|  |   if(foodlist[i].taste==taste){ | ||||||
|  |     foodlistselect.push(foodlist[i]) | ||||||
|  |     continue; | ||||||
|  |   } | ||||||
|  |   else{ | ||||||
|  |     continue; | ||||||
|  |   } | ||||||
|  | } | ||||||
|  | console.log(foodlistselect); | ||||||
|  | //确定食物
 | ||||||
|  |   var select=Math.floor(Math.random()*foodlistselect.length-1 ) | ||||||
|  |   if(select<0){ | ||||||
|  |     select="0" | ||||||
|  |   } | ||||||
|  |   console.log(select) | ||||||
|  |   var selection=foodlistselect[select] | ||||||
|  |   console.log(selection) | ||||||
|  |   var name=selection.food_name | ||||||
|  |   console.log(selection.food_name) | ||||||
|  |  var total=selection.price | ||||||
|  |  selection.num="1" | ||||||
|  |  selection.checks="false" | ||||||
|  |   var selection2=[] | ||||||
|  |   selection2.push(selection) | ||||||
|  |   wx.showModal({ | ||||||
|  |     title:'提示', | ||||||
|  |     content:'今天吃'+name, | ||||||
|  |     confirmColor: "#f00", | ||||||
|  |     complete: (res) => { | ||||||
|  |       if (res.confirm) { | ||||||
|  |         wx.navigateTo({ | ||||||
|  |           url: '/pages/paying/paying?info='+JSON.stringify(selection2)+'&totalprice='+total | ||||||
|  |         }) | ||||||
|  |       } | ||||||
|  |    | ||||||
|  |      | ||||||
|  |        | ||||||
|  |     } | ||||||
|  |   }) | ||||||
|  |   | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | }, | ||||||
|  | 
 | ||||||
|  |    | ||||||
|  |   // wx.navigateTo({
 | ||||||
|  |   //   url: '/pages/fuzzy/fuzzy?list='+JSON.stringify(list),
 | ||||||
|  |   // })
 | ||||||
|  |   /** | ||||||
|  |    * 页面的初始数据 | ||||||
|  |    */ | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |   /** | ||||||
|  |    * 生命周期函数--监听页面加载 | ||||||
|  |    */ | ||||||
|  |   onLoad:function(options) { | ||||||
|  |      | ||||||
|  |   var foodlist=JSON.parse(options.info) | ||||||
|  |   console.log(foodlist) | ||||||
|  |   this.setData({ | ||||||
|  |     foodlist:foodlist | ||||||
|  |   }) | ||||||
|  |   | ||||||
|  |    | ||||||
|  |   }, | ||||||
|  | 
 | ||||||
|  |   /** | ||||||
|  |    * 生命周期函数--监听页面初次渲染完成 | ||||||
|  |    */ | ||||||
|  |   onReady() { | ||||||
|  | 
 | ||||||
|  |   }, | ||||||
|  | 
 | ||||||
|  |   /** | ||||||
|  |    * 生命周期函数--监听页面显示 | ||||||
|  |    */ | ||||||
|  |   onShow() { | ||||||
|  | 
 | ||||||
|  |   }, | ||||||
|  | 
 | ||||||
|  |   /** | ||||||
|  |    * 生命周期函数--监听页面隐藏 | ||||||
|  |    */ | ||||||
|  |   onHide() { | ||||||
|  | 
 | ||||||
|  |   }, | ||||||
|  | 
 | ||||||
|  |   /** | ||||||
|  |    * 生命周期函数--监听页面卸载 | ||||||
|  |    */ | ||||||
|  |   onUnload() { | ||||||
|  | 
 | ||||||
|  |   }, | ||||||
|  | 
 | ||||||
|  |   /** | ||||||
|  |    * 页面相关事件处理函数--监听用户下拉动作 | ||||||
|  |    */ | ||||||
|  |   onPullDownRefresh() { | ||||||
|  | 
 | ||||||
|  |   }, | ||||||
|  | 
 | ||||||
|  |   /** | ||||||
|  |    * 页面上拉触底事件的处理函数 | ||||||
|  |    */ | ||||||
|  |   onReachBottom() { | ||||||
|  | 
 | ||||||
|  |   }, | ||||||
|  | 
 | ||||||
|  |   /** | ||||||
|  |    * 用户点击右上角分享 | ||||||
|  |    */ | ||||||
|  |   onShareAppMessage() { | ||||||
|  | 
 | ||||||
|  |   } | ||||||
|  | }) | ||||||
| @ -0,0 +1,3 @@ | |||||||
|  | { | ||||||
|  |   "usingComponents": {} | ||||||
|  | } | ||||||
| @ -0,0 +1,7 @@ | |||||||
|  | <!--pages/select2/select2.wxml--> | ||||||
|  | <view class='choose'> | ||||||
|  | <view wx:for="{{tastes}}"> | ||||||
|  | <view class="button" hover-class="button_hover"> | ||||||
|  |   <text bindtap="tasteSelect" data-taste="{{item}}">{{item}}</text> | ||||||
|  | </view></view> | ||||||
|  | </view> | ||||||
| @ -0,0 +1,22 @@ | |||||||
|  | /* pages/select2/select2.wxss */ | ||||||
|  | .button{ | ||||||
|  |   font-family:fantasy; | ||||||
|  |   font-size: larger; | ||||||
|  |   width: 80%; | ||||||
|  |   height: 100rpx; | ||||||
|  |   margin: 100rpx; | ||||||
|  |   background-color: rgb(137, 186, 192); | ||||||
|  |   color: rgb(57, 65, 71); | ||||||
|  |   border-radius: 98rpx;  | ||||||
|  |   text-align: center; | ||||||
|  |   vertical-align: center; | ||||||
|  |   line-height: 100rpx; | ||||||
|  |   margin: 0 auto; | ||||||
|  |   font-weight: bolder; | ||||||
|  | 
 | ||||||
|  | } | ||||||
|  | .button_hover{ | ||||||
|  |   position: relative; | ||||||
|  |   top: 3rpx; | ||||||
|  |   box-shadow:0px 0px 8px #999 inset;  | ||||||
|  | } | ||||||
					Loading…
					
					
				
		Reference in new issue