feat: add resident miniapp MVP
This commit is contained in:
@@ -1 +1,46 @@
|
||||
Page({})
|
||||
const { listCategories, listProducts } = require('../../api/productApi')
|
||||
|
||||
Page({
|
||||
data: {
|
||||
loading: false,
|
||||
categories: [],
|
||||
activeCategoryId: null,
|
||||
products: []
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
this.load()
|
||||
},
|
||||
|
||||
load() {
|
||||
this.setData({ loading: true })
|
||||
Promise.all([listCategories(), listProducts()])
|
||||
.then(([categories, products]) => {
|
||||
this.setData({
|
||||
categories: categories || [],
|
||||
products: products || []
|
||||
})
|
||||
})
|
||||
.catch((error) => wx.showToast({ title: error.message, icon: 'none' }))
|
||||
.finally(() => this.setData({ loading: false }))
|
||||
},
|
||||
|
||||
chooseCategory(event) {
|
||||
const categoryId = event.currentTarget.dataset.id
|
||||
this.setData({ activeCategoryId: categoryId })
|
||||
listProducts(categoryId)
|
||||
.then((products) => this.setData({ products: products || [] }))
|
||||
.catch((error) => wx.showToast({ title: error.message, icon: 'none' }))
|
||||
},
|
||||
|
||||
clearCategory() {
|
||||
this.setData({ activeCategoryId: null })
|
||||
listProducts()
|
||||
.then((products) => this.setData({ products: products || [] }))
|
||||
.catch((error) => wx.showToast({ title: error.message, icon: 'none' }))
|
||||
},
|
||||
|
||||
goDetail(event) {
|
||||
wx.navigateTo({ url: '/pages/products/detail?id=' + event.currentTarget.dataset.id })
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user