From 67244568ad62eb2b0bedd6d6fe3d0c3de358cd47 Mon Sep 17 00:00:00 2001 From: wbb <1975655432@qq.com> Date: Thu, 10 Nov 2022 18:25:33 +0800 Subject: [PATCH] 2022.11.10 --- scr/food/pages/detail/detail.js | 52 ++++++++++--------------------- scr/food/pages/detail/detail.wxml | 18 ++++++++++- scr/food/pages/detail/detail.wxss | 24 +++++++++++++- scr/food/pages/index/index.js | 8 ++--- scr/food/pages/index/index.wxml | 2 +- 5 files changed, 61 insertions(+), 43 deletions(-) diff --git a/scr/food/pages/detail/detail.js b/scr/food/pages/detail/detail.js index 64aaf22..728336f 100644 --- a/scr/food/pages/detail/detail.js +++ b/scr/food/pages/detail/detail.js @@ -8,7 +8,7 @@ Page({ */ data: { detailObj: {}, - index: null, + list:[], clockresult:[], @@ -18,43 +18,23 @@ Page({ * 生命周期函数--监听页面加载 */ onLoad: function (options) { - this.clockData() - let id =options.id - cont.doc(id).get() - .then(res => { - console.log('22') - console.log('食物详情页', res) - this.setData({ - detailObj: res.data - }) - }) + + let foodid =options.id + cont.doc(foodid).get({ + success: res => { + console.log(res.data) + //这一步很重要,给ne赋值,没有这一步的话,前台就不会显示值 + this.setData({ + detailObj: res.data + }) + } + }) + }, // 渲染数据 - clockData() { - var _this = this - wx.request({ - url:'/pages/index/index'+ this.data.index, //url this.data.index是id - method: 'GET', //请求方式 - header: { - 'content-type': 'application/json' - }, // 设置请求的 header - success: function (res) { - let list = []; - let box = (res.data.obj.assignDates === null) ? [] : res.data.obj.assignDates.substring(0, res.data.obj.assignDates.length - 1).replace(/,/g, " ") - //这里的效果跟上面的是一样的效果,就是不用foeEach循环了,就是另一种方法,这个较麻烦一点 - list.push((box.length <= 0) ? [] : box.split(' ')) - _this.setData({ - list, - clockresult: res.data.obj, - }) - }, - fail: function () { - app.consoleLog("请求数据失败"); - }, - complete: function () { - } - }) - }, + + + /** * 生命周期函数--监听页面初次渲染完成 */ diff --git a/scr/food/pages/detail/detail.wxml b/scr/food/pages/detail/detail.wxml index cdae942..d221130 100644 --- a/scr/food/pages/detail/detail.wxml +++ b/scr/food/pages/detail/detail.wxml @@ -1,3 +1,19 @@ -{{clockresult.food_name}} + + + +{{detailObj.food_name}} +{{detailObj.food_shop}} +¥{{detailObj.price}} + + + + 请选择购买数量 + + 商品评价 + 东西还可以,好评~ + + + + \ No newline at end of file diff --git a/scr/food/pages/detail/detail.wxss b/scr/food/pages/detail/detail.wxss index 91973ea..7b457d0 100644 --- a/scr/food/pages/detail/detail.wxss +++ b/scr/food/pages/detail/detail.wxss @@ -1 +1,23 @@ -/* pages/detail/detail.wxss */ \ No newline at end of file +/* pages/detail/detail.wxss */ +page { + display: flex; + flex-direction: column; + height: 100%; +} +.detail { + display: flex; + flex-direction: column; + margin-top: 15rpx; + margin-bottom: 0rpx; +} +.detail .title { + font-size: 40rpx; + margin: 10rpx; + color: black; + text-align: justify; +} +.detail .price { + color: red; + font-size: 40rpx; + margin: 10rpx; +} \ No newline at end of file diff --git a/scr/food/pages/index/index.js b/scr/food/pages/index/index.js index cadc3a2..03af7af 100644 --- a/scr/food/pages/index/index.js +++ b/scr/food/pages/index/index.js @@ -9,7 +9,8 @@ Page({ data: { foodlist:[], tabs: ['主食', '甜品', '小吃','吃得快','辣','甜','清淡'], - cateList:[] + cateList:[], + index:null }, @@ -36,10 +37,9 @@ Page({ //跳转详情页 toDetail: function (event) { // 获取 event 事件对象 - // 获取点击对应的下标 - const index = event.currentTarget.dataset.id - console.log(event) + var index = event.currentTarget.dataset.foodid; + console.log(index); //抓取id进行赋 //wx.navigateTo 会触发页面隐藏onHide console.log('11111') diff --git a/scr/food/pages/index/index.wxml b/scr/food/pages/index/index.wxml index 91dd220..a7a37e3 100644 --- a/scr/food/pages/index/index.wxml +++ b/scr/food/pages/index/index.wxml @@ -23,7 +23,7 @@ - +