// pages/shop/shop.js const goodService = require("../../services/good") Page({ /** * 页面的初始数据 */ data: { sidebarActiveId: -1, searchText: '', sidebarList: [ { id: -1, 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", // } ] }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { this.loadPageData(); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { console.log('sidebarActiveId', this.data.sidebarActiveId) this.updatePageData() }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { }, 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) // console.log("event.currentTarget", event.currentTarget) let dataset = event.currentTarget.dataset console.log("dataset", dataset) 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, }) }) })(); } })