You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
137 lines
2.2 KiB
137 lines
2.2 KiB
2 years ago
|
// 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() {
|
||
|
|
||
|
}
|
||
|
})
|