From cd8590d259d66343d167e1ea82dabf53f59ee198 Mon Sep 17 00:00:00 2001 From: lwh <2679599887@qq.com> Date: Thu, 20 Jul 2023 21:34:01 +0800 Subject: [PATCH] =?UTF-8?q?feat=20=E6=B7=BB=E5=8A=A0=E5=BA=97=E9=93=BA?= =?UTF-8?q?=E5=95=86=E5=93=81=E7=B1=BB=E7=9B=AE=E6=8E=A5=E5=8F=A3=E5=AF=B9?= =?UTF-8?q?=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/goods-card/index.wxss | 4 + components/goods-list/index.js | 5 +- pages/shop/all-goods/index.js | 104 +++++++++--------------- pages/shop/all-goods/index.wxml | 21 ++--- services/shop/fetchShopGoodsCategory.js | 22 +++++ 5 files changed, 80 insertions(+), 76 deletions(-) create mode 100644 services/shop/fetchShopGoodsCategory.js diff --git a/components/goods-card/index.wxss b/components/goods-card/index.wxss index afe50a8..830e623 100644 --- a/components/goods-card/index.wxss +++ b/components/goods-card/index.wxss @@ -173,4 +173,8 @@ margin-top: 10rpx; font-size: 23rpx; color: #7e7e7e; +} + +.custom-tab-bar { + --td-tab-bar-active-bg: #ff0000; /* 设置选中状态的背景颜色为红色 */ } \ No newline at end of file diff --git a/components/goods-list/index.js b/components/goods-list/index.js index f3fe768..5c8ee92 100644 --- a/components/goods-list/index.js +++ b/components/goods-list/index.js @@ -1,3 +1,5 @@ +import { goodsList } from "~/model/goods"; + Component({ externalClasses: ['wr-class'], @@ -38,7 +40,7 @@ Component({ const { index } = e.currentTarget.dataset; this.triggerEvent('click', { ...e.detail, index }); }, - + onAddCart(e) { const { index } = e.currentTarget.dataset; this.triggerEvent('addcart', { ...e.detail, index }); @@ -50,6 +52,7 @@ Component({ }, init() { + console.log(this.properties.goodsList); this.genIndependentID(this.id || ''); this.setData({ type: this.properties.type }); }, diff --git a/pages/shop/all-goods/index.js b/pages/shop/all-goods/index.js index 45cda4b..e661cd3 100644 --- a/pages/shop/all-goods/index.js +++ b/pages/shop/all-goods/index.js @@ -4,13 +4,11 @@ import { import { fetchShop } from '~/services/shop/fetchShop'; +import { + fetchShopGoodsCategory +} from '~/services/shop/fetchShopGoodsCategory'; import Toast from 'tdesign-miniprogram/toast/index'; -const image = 'https://tdesign.gtimg.com/miniprogram/images/example2.png'; -const items = new Array(12).fill({ - label: '标题文字', - image -}, 0, 12); const initFilters = { overall: 1, @@ -22,6 +20,7 @@ const initFilters = { Page({ data: { goodsList: [], + shopCategoryGoodsList: [], layout: 0, priceSorts: '', soldSorts: '', @@ -51,48 +50,9 @@ Page({ }, ], - sideBarIndex: 1, + sideBarIndex: 0, scrollTop: 0, - categories: [{ - label: '选项一', - title: '标题一', - icon: 'app', - badgeProps: {}, - items, - }, - { - label: '选项二', - title: '标题二', - icon: 'app', - badgeProps: { - dot: true, - }, - items: items.slice(0, 9), - }, - { - label: '选项三', - title: '标题三', - icon: 'app', - badgeProps: {}, - items: items.slice(0, 9), - }, - { - label: '选项四', - title: '标题四', - icon: 'app', - badgeProps: { - count: 6, - }, - items: items.slice(0, 6), - }, - { - label: '选项五', - title: '标题五', - icon: 'app', - badgeProps: {}, - items: items.slice(0, 3), - }, - ], + categories: [], }, offsetTopList: [], @@ -138,7 +98,7 @@ Page({ goodsSort: 0, // 0 综合,1 价格 pageNum: 1, pageSize: 6, - shopGuid: shopGuid + shopGuid: shopGuid, // keyword: keywords, }; @@ -232,6 +192,8 @@ Page({ hasLoaded: true, loading: false, }); + + return Promise.resolve(); }, onLoad(query) { @@ -242,23 +204,7 @@ Page({ shopGuid: shopGuid, }); - this.init(true); - - const query2 = wx.createSelectorQuery().in(this); - const { - sideBarIndex - } = this.data; - - query2 - .selectAll('.title') - .boundingClientRect((rects) => { - this.offsetTopList = rects.map((item) => item.top); - console.log(this.offsetTopList, '123123123'); - this.setData({ - scrollTop: rects[sideBarIndex].top - }); - }) - .exec(); + this.init(true) }, onReachBottom() { @@ -378,10 +324,38 @@ Page({ ); }, - onChange(e) { + async onChange(e) { this.setData({ value: e.detail.value, }); + if (this.data.value == "category") { + // 获取店铺商品类目 + const { + shopGuid + } = this.data + const shopGoodsCategoryResult = await fetchShopGoodsCategory({ + shopGuid: shopGuid + }); + this.setData({ + categories: shopGoodsCategoryResult + }) + + const query2 = wx.createSelectorQuery().in(this); + const { + sideBarIndex + } = this.data; + + query2 + .selectAll('.title') + .boundingClientRect((rects) => { + console.log(rects, '123123123'); + this.offsetTopList = rects.map((item) => item.top); + this.setData({ + scrollTop: rects[sideBarIndex].top + }); + }) + .exec(); + } }, diff --git a/pages/shop/all-goods/index.wxml b/pages/shop/all-goods/index.wxml index 6901920..a6895e0 100644 --- a/pages/shop/all-goods/index.wxml +++ b/pages/shop/all-goods/index.wxml @@ -1,7 +1,8 @@ - + + @@ -45,19 +46,19 @@ - + - - + - {{item.title || item.label}} + {{item.label}} - + - - + + @@ -69,8 +70,8 @@ - - + + {{item.label}} diff --git a/services/shop/fetchShopGoodsCategory.js b/services/shop/fetchShopGoodsCategory.js new file mode 100644 index 0000000..33b6376 --- /dev/null +++ b/services/shop/fetchShopGoodsCategory.js @@ -0,0 +1,22 @@ +import { + request +} from '../_utils/request'; + +/** 获取店铺详情 */ +export function fetchShopGoodsCategory(parm) { + return new Promise((resolve, reject) => { + request({ + url: `ShopGoodsCategoryApi/getShopGoodsCategoryTreeList`, + data: parm, + method: 'GET', + success: function (res) { + let data = res.data; + + resolve(data); + }, + fail: function (error) { + reject(error); + } + }); + }); +}