index.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. import GoodApi from '../../../services/good'
  2. import Navi from '../../../utils/navi'
  3. // pages/goods/category/index.ts
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. pageTitle: '栏目',
  10. data: [] as any[],
  11. scrollMaxHeight: 0,
  12. active: 0,
  13. advs: [],
  14. albums: [],
  15. columnSize: '',
  16. loading: true,
  17. isText: false,
  18. },
  19. /**
  20. * 生命周期函数--监听页面加载
  21. */
  22. onLoad() {
  23. GoodApi.GetCateList().then((rsp) => {
  24. if (rsp.result && rsp.result.length > 0) {
  25. const tab = rsp.result[this.data.active]
  26. this.setData({
  27. data: rsp.result,
  28. isText: tab.isText,
  29. advs: tab.advs || [],
  30. albums: tab.children || [],
  31. columnSize: tab.columns,
  32. loading: false,
  33. })
  34. }
  35. })
  36. wx.createSelectorQuery()
  37. .in(this)
  38. .select('.scroll-wrap')
  39. .boundingClientRect((rect) => {
  40. this.setData({
  41. scrollMaxHeight: rect.height - 48,
  42. })
  43. })
  44. .exec()
  45. },
  46. /**
  47. * 生命周期函数--监听页面初次渲染完成
  48. */
  49. onReady() {},
  50. /**
  51. * 生命周期函数--监听页面显示
  52. */
  53. onShow() {
  54. this.getTabBar().init()
  55. },
  56. /**
  57. * 生命周期函数--监听页面隐藏
  58. */
  59. onHide() {},
  60. /**
  61. * 生命周期函数--监听页面卸载
  62. */
  63. onUnload() {},
  64. /**
  65. * 页面相关事件处理函数--监听用户下拉动作
  66. */
  67. onPullDownRefresh() {},
  68. /**
  69. * 页面上拉触底事件的处理函数
  70. */
  71. onReachBottom() {},
  72. /**
  73. * 用户点击右上角分享
  74. */
  75. onShareAppMessage() {},
  76. onGoBack() {
  77. Navi.switchTab({
  78. url: '/pages/index/index',
  79. })
  80. },
  81. onGoSearch() {
  82. Navi.navigateTo({
  83. url: '/pages/search/search?from=cate',
  84. })
  85. },
  86. onSidebarChange(e: SidebarChangeEvent) {
  87. const tab = this.data.data[e.detail.current]
  88. this.setData({
  89. active: e.detail.current,
  90. advs: tab.advs || [],
  91. albums: tab.children || [],
  92. columnSize: tab.columns,
  93. isText: tab.isText,
  94. })
  95. console.log(
  96. `repeat(${tab.columns}, calc(${100 / tab.columns}%${tab.columns > 1 ? '- 15rpx' : ''}))`,
  97. )
  98. },
  99. gotoDetail(e: WechatMiniprogram.CustomEvent<{}, {}, { value: number }>) {
  100. const cateid = e.target.dataset.value
  101. Navi.navigateTo({
  102. url: `/pages/goods/list/index?cate=${cateid}`,
  103. })
  104. },
  105. gotoAdvtag(e: WechatMiniprogram.CustomEvent<{}, {}, { tagid: string }>) {
  106. Navi.navigateTo({
  107. url: '/pages/advtag/index?tag=' + e.currentTarget.dataset.tagid,
  108. })
  109. },
  110. })