创建微服务:microservice-provider-shop-8003;小程序商品列表筛选、商品详情完成
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
// pages/shop/shop.js
|
||||
|
||||
const goodService = require("../../services/good")
|
||||
|
||||
Page({
|
||||
|
||||
/**
|
||||
@@ -6,48 +9,49 @@ Page({
|
||||
*/
|
||||
data: {
|
||||
sidebarActiveId: -1,
|
||||
searchText: '',
|
||||
sidebarList: [
|
||||
{
|
||||
id: -1,
|
||||
title: "全部分类",
|
||||
},
|
||||
{
|
||||
id: 1,
|
||||
title: "1",
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
title: "防疫物资",
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
title: "111",
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
title: "111",
|
||||
},
|
||||
{
|
||||
id: 5,
|
||||
title: "111",
|
||||
categoryName: "全部分类",
|
||||
},
|
||||
// {
|
||||
// id: 1,
|
||||
// title: "1",
|
||||
// },
|
||||
// {
|
||||
// id: 2,
|
||||
// title: "防疫物资",
|
||||
// },
|
||||
// {
|
||||
// id: 3,
|
||||
// title: "111",
|
||||
// },
|
||||
// {
|
||||
// id: 4,
|
||||
// title: "111",
|
||||
// },
|
||||
// {
|
||||
// id: 5,
|
||||
// title: "111",
|
||||
// },
|
||||
],
|
||||
|
||||
tabbarList: [
|
||||
{
|
||||
id: 1,
|
||||
goodsName: "温度计",
|
||||
counterPrice: "10.00",
|
||||
retailPrice: "12.00",
|
||||
picUrl: "https://cdn-we-retail.ym.tencent.com/tsr/goods/gh-2b.png?imageMogr2/thumbnail/320x320/quality/70/strip/format/webp",
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
goodsName: "医用口罩",
|
||||
counterPrice: "100.00",
|
||||
retailPrice: "12.50",
|
||||
picUrl: "https://cdn-we-retail.ym.tencent.com/tsr/goods/muy-3a.png?imageMogr2/thumbnail/320x320/quality/70/strip/format/webp",
|
||||
}
|
||||
// {
|
||||
// id: 1,
|
||||
// goodsName: "温度计",
|
||||
// counterPrice: "10.00",
|
||||
// retailPrice: "12.00",
|
||||
// picUrl: "https://cdn-we-retail.ym.tencent.com/tsr/goods/gh-2b.png?imageMogr2/thumbnail/320x320/quality/70/strip/format/webp",
|
||||
// },
|
||||
// {
|
||||
// id: 2,
|
||||
// goodsName: "医用口罩",
|
||||
// counterPrice: "100.00",
|
||||
// retailPrice: "12.50",
|
||||
// picUrl: "https://cdn-we-retail.ym.tencent.com/tsr/goods/muy-3a.png?imageMogr2/thumbnail/320x320/quality/70/strip/format/webp",
|
||||
// }
|
||||
]
|
||||
},
|
||||
|
||||
@@ -55,7 +59,7 @@ Page({
|
||||
* 生命周期函数--监听页面加载
|
||||
*/
|
||||
onLoad(options) {
|
||||
|
||||
this.loadPageData();
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -90,7 +94,8 @@ Page({
|
||||
* 页面相关事件处理函数--监听用户下拉动作
|
||||
*/
|
||||
onPullDownRefresh() {
|
||||
|
||||
console.log('sidebarActiveId', this.data.sidebarActiveId)
|
||||
this.updatePageData()
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -108,6 +113,20 @@ Page({
|
||||
},
|
||||
|
||||
|
||||
bindSearchInput(e) {
|
||||
this.setData({
|
||||
searchText: e.detail.value,
|
||||
})
|
||||
this.updatePageData()
|
||||
},
|
||||
clearSearchInput() {
|
||||
this.setData({
|
||||
searchText: '',
|
||||
sidebarActiveId: -1,
|
||||
})
|
||||
this.updatePageData()
|
||||
},
|
||||
|
||||
sidebarItemTap(event) {
|
||||
// 清除原来的选中项,并设置新的选中项
|
||||
// console.log("event.target", event.target)
|
||||
@@ -117,6 +136,51 @@ Page({
|
||||
this.setData({
|
||||
sidebarActiveId: dataset.item.id,
|
||||
})
|
||||
this.loadPageData()
|
||||
return
|
||||
},
|
||||
|
||||
loadPageData() {
|
||||
(async () => {
|
||||
let goodCategoryListPromise = goodService.getGoodCategoryList()
|
||||
let goodListPromise = goodService.getGoodList(this.data.sidebarActiveId, this.data.searchText)
|
||||
Promise.all([
|
||||
goodCategoryListPromise,
|
||||
goodListPromise,
|
||||
]).then(data => {
|
||||
let goodCategoryList = data[0]
|
||||
let goodList = data[1]
|
||||
console.log("goodCategoryList", goodCategoryList)
|
||||
console.log("goodList", goodList)
|
||||
goodCategoryList.unshift({
|
||||
id: -1,
|
||||
categoryName: "全部分类",
|
||||
order: 0
|
||||
})
|
||||
console.log("goodCategoryList", goodCategoryList)
|
||||
this.setData({
|
||||
sidebarList: goodCategoryList,
|
||||
tabbarList: goodList,
|
||||
})
|
||||
})
|
||||
})();
|
||||
},
|
||||
|
||||
updatePageData() {
|
||||
(async () => {
|
||||
this.setData({
|
||||
tabbarList: [],
|
||||
})
|
||||
let goodListPromise = goodService.getGoodList(this.data.sidebarActiveId, this.data.searchText)
|
||||
Promise.all([
|
||||
goodListPromise,
|
||||
]).then(data => {
|
||||
let goodList = data[0]
|
||||
console.log("goodList", goodList)
|
||||
this.setData({
|
||||
tabbarList: goodList,
|
||||
})
|
||||
})
|
||||
})();
|
||||
}
|
||||
})
|
Reference in New Issue
Block a user