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.
git/scr/food/pages/turning/turning.js

120 lines
3.7 KiB

This file contains invisible Unicode characters!

This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

//turning.js
//获取应用实例
let animation = wx.createAnimation({
duration: 2000,
timingFunction: 'linear'
})
const app=getApp()
const userid=app.globalData.openid
Page({
data: {
rotate: 0, //度数
list:[],
turning: false ,//是否点击
detailObj:{},
total:''
},
//事件处理函数
start: function() {
const _this = this;
let cat = 60;
if (!this.data.turning) {
let rdm = 0; //随机度数
rdm = Math.floor(Math.random() * 3600); //最大10圈
//rdm = 1200;//直接确定转的度数
animation.rotate(rdm).step();
this.setData({
rotate: animation.export(),
turning: true
});
setTimeout(() => {
this.setData({
turning: false
});
let num = rdm % 360; //转了多少度
//console.log(num);
function showModal(str) {
wx.showModal({
title: '提示',
content: str,
success: function() { //点击确定后还原到0度
let animation = wx.createAnimation({
duration: 100,
timingFunction: 'linear'
});
animation.rotate(0).step();
_this.setData({
rotate: animation.export(),
turning: false
})
var Selection=[]
var detailObj=_this.data.detailObj
var total=detailObj.price
console.log(detailObj)
console.log(total)
Selection.push(detailObj)
 wx.redirectTo({
url:'/pages/paying/paying?info='+JSON.stringify(Selection)+'&totalprice='+total,
})
},
fail: function(res) {
console.log(res)
}
})
}
/* if (num <= cat * 0.5 && num>=cat*0 || num>=cat*5.5 ) {
showModal('今天就吃自选餐吧不要再想了GOGO');
}else if (num <= cat * 1.5 && num >= cat * 0.5) {
showModal('今天就吃麻辣烫吧不要再想了GOGO');
} else if (num <= cat * 2.5 && num >= cat * 1.5) {
showModal('今天就吃汉堡炸鸡吧不要再想了GOGO');
} else if (num <= cat * 3.5 && num >= cat * 2.5) {
showModal('今天就吃面食吧不要再想了GOGO');
} else if (num <= cat * 4.5 && num >= cat * 3.5) {
showModal('今天就吃烤盘饭吧不要再想了GOGO');
} else if (num <= cat * 5.5 && num >= cat * 4.5) {
showModal('今天就吃煎饼果子吧不要再想了GOGO');
} */
// console.log(num)
var a= wx.getStorageSync('i')
console.log(a)
showModal('今天吃'+a)
}, 2000)
}
},
onLoad: function() {
const db=wx.cloud.database()
var that=this
db.collection("user")
.where({
"_openid":userid
})
.get({
success: (res) => {
console.log('请求成功',res);
//cartlist长度
var o=res.data[0].cartlist.length-1
//console.log(o)
//随机在购物车里选择一件商品
var p=Math.round(Math.random()*o)
console.log(p)
that.setData({
list:res.data[0].cartlist[p].food_name,
detailObj:res.data[0].cartlist[p]
})
var detailObj=this.data.detailObj
console.log(detailObj)
// console.log('请求成功2',res.data[0].cartlist[p].food_name);
wx.setStorageSync('i', res.data[0].cartlist[p].food_name)
},
fail(err) {
console.log("请求失败", err)
}
})
},
})