|
|
|
|
const db = wx.cloud.database({});
|
|
|
|
|
const cont = db.collection('food');
|
|
|
|
|
const $ = db.command.aggregate
|
|
|
|
|
Page({
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 页面的初始数据
|
|
|
|
|
*/
|
|
|
|
|
data: {
|
|
|
|
|
foodlist:[],
|
|
|
|
|
tabs: ['全部','主食', '甜品', '小吃','吃得快','辣味','甜味','清淡'],
|
|
|
|
|
cateList:[],
|
|
|
|
|
index:null,
|
|
|
|
|
current:'',
|
|
|
|
|
re:[],
|
|
|
|
|
selectlist:[]
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 搜索
|
|
|
|
|
*/
|
|
|
|
|
GetSearchInput: function(e) {
|
|
|
|
|
this.setData({
|
|
|
|
|
search: e.detail.value
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
ToSearch: function(e) {
|
|
|
|
|
//let search = e.detail.value;
|
|
|
|
|
|
|
|
|
|
if(this.data.search == '') {
|
|
|
|
|
wx.showToast({
|
|
|
|
|
title: '请输入',
|
|
|
|
|
icon: 'none'
|
|
|
|
|
})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
wx.showLoading({
|
|
|
|
|
title: '搜索中',
|
|
|
|
|
})
|
|
|
|
|
const _ = wx.cloud.database().command
|
|
|
|
|
wx.cloud.database().collection('food').where(_.or([
|
|
|
|
|
{
|
|
|
|
|
food_shop: wx.cloud.database().RegExp({
|
|
|
|
|
regexp: this.data.search,
|
|
|
|
|
options: 'i',
|
|
|
|
|
}),
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
food_name: wx.cloud.database().RegExp({
|
|
|
|
|
regexp: this.data.search,
|
|
|
|
|
options: 'i',
|
|
|
|
|
}),
|
|
|
|
|
}
|
|
|
|
|
]))
|
|
|
|
|
|
|
|
|
|
.get()
|
|
|
|
|
.then(res => {
|
|
|
|
|
if (res.data.length != 0) {
|
|
|
|
|
this.setData({
|
|
|
|
|
re: res.data,
|
|
|
|
|
})
|
|
|
|
|
wx.setStorageSync('re', res.data)
|
|
|
|
|
let re= wx.getStorageSync('re')
|
|
|
|
|
console.log(re)
|
|
|
|
|
let that = this;
|
|
|
|
|
wx.hideLoading({
|
|
|
|
|
success: (res) => {
|
|
|
|
|
that.setData({
|
|
|
|
|
search: '',
|
|
|
|
|
})
|
|
|
|
|
}})
|
|
|
|
|
console.log(re)
|
|
|
|
|
wx.navigateTo({
|
|
|
|
|
url: '/pages/searchfood/searchfood?re='+JSON.stringify(re),//要跳转到的页面路径
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
}})
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
tabSelect:function(e){
|
|
|
|
|
var current = e.currentTarget.dataset.tab
|
|
|
|
|
this.setData({
|
|
|
|
|
current:current
|
|
|
|
|
})
|
|
|
|
|
if(current=='全部'){ //如果是全部则获取所有数据
|
|
|
|
|
db.collection('food').get({
|
|
|
|
|
//如果查询成功的话
|
|
|
|
|
success: res => {
|
|
|
|
|
console.log(res.data)
|
|
|
|
|
//这一步很重要,给ne赋值,没有这一步的话,前台就不会显示值
|
|
|
|
|
this.setData({
|
|
|
|
|
foodlist: res.data
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}else{//如果不是全部进行筛选
|
|
|
|
|
wx.showLoading({
|
|
|
|
|
title: '分类中',
|
|
|
|
|
})
|
|
|
|
|
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',
|
|
|
|
|
}),
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
taste: 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)
|
|
|
|
|
|
|
|
|
|
})}
|
|
|
|
|
},
|
|
|
|
|
//分类
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//跳转详情页
|
|
|
|
|
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',
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
})
|