123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- import GoodApi from '../../../services/good'
- import { share } from '../../../utils/http'
- import Navi from '../../../utils/navi'
- const app = getApp<IAppOption>()
- // pages/goods/category/index.ts
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- pageTitle: '栏目',
- data: [] as any[],
- scrollMaxHeight: 0,
- active: 0,
- advs: [],
- albums: [],
- columnSize: '',
- loading: true,
- isText: false,
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad() {
- GoodApi.GetCateList().then((rsp) => {
- if (rsp.result && rsp.result.length > 0) {
- const nowid = app.globalData.showcateid
- let idx = this.data.active
- if (Number(nowid) > 0) {
- idx = rsp.result.findIndex((v) => v.value === nowid)
- }
- const tab = rsp.result[idx]
- this.setData({
- active: idx,
- data: rsp.result,
- isText: tab.isText,
- advs: tab.advs || [],
- albums: tab.children || [],
- columnSize: tab.columns,
- loading: false,
- })
- }
- })
- wx.createSelectorQuery()
- .in(this)
- .select('.scroll-wrap')
- .boundingClientRect((rect) => {
- this.setData({
- scrollMaxHeight: rect.height - 48,
- })
- })
- .exec()
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {},
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- this.getTabBar().init()
- const nowid = app.globalData.showcateid
- if (Number(nowid) > 0 && this.data.data.length > 0) {
- const idx = this.data.data.findIndex((v) => v.value === nowid)
- this.onSidebarChange({
- detail: {
- current: idx,
- },
- } as any)
- }
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {},
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {},
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {},
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {},
- /**
- * 用户点击右上角分享
- */
- 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);
- }
- }
- },
- onGoBack() {
- Navi.switchTab({
- url: '/pages/index/index',
- })
- },
- onGoSearch() {
- Navi.navigateTo({
- url: '/pages/search/search?from=cate',
- })
- },
- onSidebarChange(e: SidebarChangeEvent) {
- console.log(e.detail.current, this.data.data)
- const tab = this.data.data[e.detail.current]
- this.setData({
- active: e.detail.current,
- advs: tab.advs || [],
- albums: tab.children || [],
- columnSize: tab.columns,
- isText: tab.isText,
- })
- console.log(
- `repeat(${tab.columns}, calc(${100 / tab.columns}%${tab.columns > 1 ? '- 15rpx' : ''}))`,
- )
- },
- gotoDetail(e: WechatMiniprogram.CustomEvent<{}, {}, { value: number }>) {
- const cateid = e.target.dataset.value
- Navi.navigateTo({
- url: `/pages/goods/list/index?cate=${cateid}`,
- })
- },
- gotoAdvtag(e: WechatMiniprogram.CustomEvent<{}, {}, { tagid: string }>) {
- const { tagid } = e.currentTarget.dataset
- if (Number(tagid) > 0) {
- Navi.navigateTo({
- url: '/pages/advtag/index?tag=' + tagid,
- })
- }
- },
- })
|