From d37a5229052c4f152d9169b10177f252aa87b3ad Mon Sep 17 00:00:00 2001 From: wbb <1975655432@qq.com> Date: Wed, 23 Nov 2022 21:58:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E7=B1=BB=E5=92=8C=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scr/food/app.json | 3 +- scr/food/pages/detail/detail.js | 29 +---- scr/food/pages/index/index.js | 131 +++++++++++++++++++--- scr/food/pages/index/index.wxml | 18 ++- scr/food/pages/index/index.wxss | 59 ++++++++-- scr/food/pages/searchfood/searchfood.js | 84 ++++++++++++++ scr/food/pages/searchfood/searchfood.json | 3 + scr/food/pages/searchfood/searchfood.wxml | 18 +++ scr/food/pages/searchfood/searchfood.wxss | 52 +++++++++ 9 files changed, 339 insertions(+), 58 deletions(-) create mode 100644 scr/food/pages/searchfood/searchfood.js create mode 100644 scr/food/pages/searchfood/searchfood.json create mode 100644 scr/food/pages/searchfood/searchfood.wxml create mode 100644 scr/food/pages/searchfood/searchfood.wxss diff --git a/scr/food/app.json b/scr/food/app.json index b0dbd9a..b74bfc5 100644 --- a/scr/food/app.json +++ b/scr/food/app.json @@ -16,7 +16,8 @@ "pages/turning/turning", "pages/addAddress/addAddress", "pages/myorder/myorder", - "pages/orderdetail/orderdetail" + "pages/orderdetail/orderdetail", + "pages/searchfood/searchfood" ], "tabBar": { "custom": false, diff --git a/scr/food/pages/detail/detail.js b/scr/food/pages/detail/detail.js index 178dbad..7c6c061 100644 --- a/scr/food/pages/detail/detail.js +++ b/scr/food/pages/detail/detail.js @@ -14,38 +14,17 @@ Page({ userid:null, num:null, commentlist:[ - { - name:"Exungsh", - comment:"傻逼微信小程序" - }, - { - name:"Wbb", - comment:"快两点半有点困" - }, - { - name:"Exungsh", - comment:"傻逼微信小程序" - }, - { - name:"Wbb", - comment:"快两点半有点困" - }, - { - name:"Exungsh", - comment:"傻逼微信小程序" - }, + { name:"Wbb", - comment:"快两点半有点困" - }, - { - name:"Exungsh", - comment:"傻逼微信小程序" + comment:"好吃,强推" }, + { name:"Wbb", comment:"快两点半有点困" }, + ] }, diff --git a/scr/food/pages/index/index.js b/scr/food/pages/index/index.js index b9e89a1..db586a7 100644 --- a/scr/food/pages/index/index.js +++ b/scr/food/pages/index/index.js @@ -8,32 +8,129 @@ Page({ */ data: { foodlist:[], - tabs: ['主食', '甜品', '小吃','吃得快','辣味','甜味','清淡'], + tabs: ['全部','主食', '甜品', '小吃','吃得快','辣味','甜味','清淡'], cateList:[], - index:null + index:null, + current:'', + re:[], + selectlist:[] }, - - tabSelect:function(e){ - var current = e.currentTarget.dataset.id + /** + * 搜索 + */ + GetSearchInput: function(e) { this.setData({ - current:current + search: e.detail.value }) + }, - //分类 - geCateListe(){ - db.collection('food').aggregate() - .group({ - _id: '$tab' - }) - .end() + 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 => { - console.log('食物列表', 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({ - foodList: res.list + 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 事件对象 diff --git a/scr/food/pages/index/index.wxml b/scr/food/pages/index/index.wxml index 0620f03..bdf6ab6 100644 --- a/scr/food/pages/index/index.wxml +++ b/scr/food/pages/index/index.wxml @@ -8,13 +8,23 @@ - - + + + + + + + + 搜索 + + + + - - {{item}} + + {{item}} diff --git a/scr/food/pages/index/index.wxss b/scr/food/pages/index/index.wxss index 667cd12..66256de 100644 --- a/scr/food/pages/index/index.wxss +++ b/scr/food/pages/index/index.wxss @@ -52,15 +52,6 @@ page { font-weight: 600; border-bottom: 4rpx solid #000080 !important; } - - - - - - - - - .P_input { position: relative; } @@ -88,7 +79,7 @@ page { display: flex; justify-content: center; align-items: center; - width: 400rpx; + width: 600rpx; margin: 0 auto; } @@ -171,4 +162,50 @@ navigator { .scroll-view-containner { display: flex; text-align: center; -} \ No newline at end of file +} + +/* 搜索框*/ +.search{ + width: 80%; +} + +.sousuokuang { + width: 100%; + height: 100rpx; + display: flex; + flex-direction: column; + align-items: center; + background-color: white; +} +.sousuo { + width: 92%; + height: 100rpx; + display: flex; + flex-direction: row; + align-items: center; + justify-items: center; +} +.shurukuang { + width: 80%; + height: 64rpx; + border-radius: 32rpx; + display: flex; + align-items: center; + justify-content: center; + background-color: #f6f6f6; +} +.shurukuang input { + width: 90%; + height: 100%; + font-size: 32rpx; +} +.sousuo_anniu { + width: 20%; + height: 64rpx; + display: flex; + align-items: center; + justify-content: center; +} +.sousuo_anniu text { + font-size: 30rpx; +} diff --git a/scr/food/pages/searchfood/searchfood.js b/scr/food/pages/searchfood/searchfood.js new file mode 100644 index 0000000..adae745 --- /dev/null +++ b/scr/food/pages/searchfood/searchfood.js @@ -0,0 +1,84 @@ +// pages/searchfood/searchfood.js +Page({ + + /** + * 页面的初始数据 + */ + data: { + re:[] + }, + + /** + * 生命周期函数--监听页面加载 + */ + onLoad(options) { + console.log(JSON.parse(options.re),"1") + let re = JSON.parse(options.re); + let that = this + that.setData({ + re: re + }) + console.log(re) + }, + + 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, + }) + }, + /** + * 生命周期函数--监听页面初次渲染完成 + */ + onReady() { + + }, + + /** + * 生命周期函数--监听页面显示 + */ + onShow() { + + }, + + /** + * 生命周期函数--监听页面隐藏 + */ + onHide() { + + }, + + /** + * 生命周期函数--监听页面卸载 + */ + onUnload() { + + }, + + /** + * 页面相关事件处理函数--监听用户下拉动作 + */ + onPullDownRefresh() { + + }, + + /** + * 页面上拉触底事件的处理函数 + */ + onReachBottom() { + + }, + + /** + * 用户点击右上角分享 + */ + onShareAppMessage() { + + } +}) \ No newline at end of file diff --git a/scr/food/pages/searchfood/searchfood.json b/scr/food/pages/searchfood/searchfood.json new file mode 100644 index 0000000..8835af0 --- /dev/null +++ b/scr/food/pages/searchfood/searchfood.json @@ -0,0 +1,3 @@ +{ + "usingComponents": {} +} \ No newline at end of file diff --git a/scr/food/pages/searchfood/searchfood.wxml b/scr/food/pages/searchfood/searchfood.wxml new file mode 100644 index 0000000..ccebe8d --- /dev/null +++ b/scr/food/pages/searchfood/searchfood.wxml @@ -0,0 +1,18 @@ + + + + + + + + + + + {{item.food_name}} + ¥{{item.price}} + {{item.food_shop}} + + + + + \ No newline at end of file diff --git a/scr/food/pages/searchfood/searchfood.wxss b/scr/food/pages/searchfood/searchfood.wxss new file mode 100644 index 0000000..f2a24a5 --- /dev/null +++ b/scr/food/pages/searchfood/searchfood.wxss @@ -0,0 +1,52 @@ +/* pages/searchfood/searchfood.wxss */ +.foodist { + margin-top: 10px; +} + +.foodlist .a { + padding: 20px; + border-bottom: #b4b3b3 solid 1px; + background-color: #fff9f9; +} + +.foodlist .a .img { + float: left; + margin-right: 20px; +} + +.foodlist .a .img image { + width: 200rpx; + height: 200rpx; +} + +.foodlist .a .info { + float: left; + height: 200rpx; + width: 60%; + position: relative; +} + +.foodlist .a .info .title { + margin-top: 5px; + color: black; + font-size: 16px; +} + +.foodlist .a .info .price { + color: #FF2727; + margin-top: 8px; + font-size: 15px; +} + +.foodlist .a .info .num { + position: absolute; + left: 0px; + bottom: 5px; + color: #747474; + font-size: 15px; +} + +.clear { + clear: both; + overflow: hidden; +}