import GoodApi from '../../services/good' import { share } from '../../utils/http' import Navi from '../../utils/navi' // pages/search/result.ts Page({ /** * 页面的初始数据 */ data: { filterText: '', loadMoreStatus: 0, albumTotal: 0, albumInput: { filterText: '', sortkey: 'default', cateId: -1, skipCount: 0, maxResultCount: 10, }, albums: [], }, load(rest = false) { this.setData({ loadMoreStatus: 1, }) GoodApi.GetCateAlbum(this.data.albumInput).then((rsp) => { if (rsp.result) { const result = rsp.result as any const { items = [] } = result const nowItems = rest ? items : this.data.albums.concat(items) this.setData({ albums: nowItems as any, albumTotal: result.totalCount || 0, loadMoreStatus: nowItems.length === result.totalCount ? 2 : 0, }) if (result.name && result.name.length > 0) { wx.setNavigationBarTitle({ title: `${result.name}挂画`, }) } } }) }, gotoGoodsDetail(e: WechatMiniprogram.CustomEvent<{ goods: WxCateAlbumItemDto; index: number }>) { const { goods } = e.detail Navi.navigateTo({ url: '/pages/goods/detail/index?id=' + goods.id + '&cateid=' + this.data.albumInput.cateId, }) console.log('click', e) }, /** * 生命周期函数--监听页面加载 */ onLoad(query: { keyword: string }) { this.setData( { 'albumInput.filterText': query.keyword, }, () => { console.log(this.data.albumInput) this.load(false) }, ) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() {}, /** * 生命周期函数--监听页面显示 */ onShow() {}, /** * 生命周期函数--监听页面隐藏 */ onHide() {}, /** * 生命周期函数--监听页面卸载 */ onUnload() {}, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() {}, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { console.log(this.data.albums.length, this.data.albumTotal) if (this.data.loadMoreStatus === 0 && this.data.albums.length < this.data.albumTotal) { this.setData( { albumInput: { ...this.data.albumInput, skipCount: this.data.albumInput.skipCount + 10, }, }, () => { this.load() }, ) } }, /** * 用户点击右上角分享 */ onShareAppMessage() { let pages = getCurrentPages(); //获取所有页面栈实例列表 let nowPage = pages[pages.length - 1]; //当前页页面实例 return { title: share.title, path: `/${nowPage.route}`, imageUrl: share.imageUrl, success(res) { console.log('success(res)==', res); }, fail(res) { console.log('fail(res)==', res); } } }, })