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.
|
|
|
|
const db = wx.cloud.database({});
|
|
|
|
|
const cont = db.collection('food');
|
|
|
|
|
const $ = db.command.aggregate
|
|
|
|
|
Page({
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 页面的初始数据
|
|
|
|
|
*/
|
|
|
|
|
data: {
|
|
|
|
|
foodlist:[],
|
|
|
|
|
tabs: ['主食', '甜品', '小吃','吃得快','辣味','甜味','清淡'],
|
|
|
|
|
cateList:[],
|
|
|
|
|
index:null
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tabSelect:function(e){
|
|
|
|
|
var current = e.currentTarget.dataset.id
|
|
|
|
|
this.setData({
|
|
|
|
|
current:current
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
//分类
|
|
|
|
|
geCateListe(){
|
|
|
|
|
db.collection('food').aggregate()
|
|
|
|
|
.group({
|
|
|
|
|
_id: '$tab'
|
|
|
|
|
})
|
|
|
|
|
.end()
|
|
|
|
|
.then(res => {
|
|
|
|
|
console.log('食物列表', res)
|
|
|
|
|
this.setData({
|
|
|
|
|
foodList: res.list
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
//跳转详情页
|
|
|
|
|
toDetail: function (event) {
|
|
|
|
|
// 获取 event 事件对象
|
|
|
|
|
// 获取点击对应的下标
|
|
|
|
|
var index = event.currentTarget.dataset.foodid;
|
|
|
|
|
console.log(index);
|
|
|
|
|
//抓取id进行赋
|
|
|
|
|
//wx.navigateTo 会触发页面隐藏onHide
|
|
|
|
|
console.log('11111')
|
|
|
|
|
wx.navigateTo({
|
|
|
|
|
url:'/pages/detail/detail?id='+ index,
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
/**
|
|
|
|
|
* 生命周期函数--监听页面加载
|
|
|
|
|
*/
|
|
|
|
|
onLoad: function (options) {
|
|
|
|
|
var _this = this;
|
|
|
|
|
const db = wx.cloud.database({
|
|
|
|
|
//这个是环境ID不是环境名称
|
|
|
|
|
env: 'cloud1-8g5wmepxce8a3b8a'
|
|
|
|
|
})
|
|
|
|
|
//2、开始查询数据了 news对应的是集合的名称
|
|
|
|
|
db.collection('food').get({
|
|
|
|
|
//如果查询成功的话
|
|
|
|
|
success: res => {
|
|
|
|
|
console.log(res.data)
|
|
|
|
|
//这一步很重要,给ne赋值,没有这一步的话,前台就不会显示值
|
|
|
|
|
this.setData({
|
|
|
|
|
foodlist: res.data
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
|
|
|
*/
|
|
|
|
|
onReady: function () {
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 生命周期函数--监听页面显示
|
|
|
|
|
*/
|
|
|
|
|
onShow: function () {
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 生命周期函数--监听页面隐藏
|
|
|
|
|
*/
|
|
|
|
|
onHide: function () {
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 生命周期函数--监听页面卸载
|
|
|
|
|
*/
|
|
|
|
|
onUnload: function () {
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
|
|
|
*/
|
|
|
|
|
onPullDownRefresh: function () {
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 页面上拉触底事件的处理函数
|
|
|
|
|
*/
|
|
|
|
|
onReachBottom: function () {
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 用户点击右上角分享
|
|
|
|
|
*/
|
|
|
|
|
onShareAppMessage: function () {
|
|
|
|
|
},
|
|
|
|
|
toturning: function(){
|
|
|
|
|
wx.navigateTo({
|
|
|
|
|
url:'/pages/turning/turning',
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
})
|