shopCategory.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. // pages/shopCategory/shopCategory.js
  2. var http = require('../../utils/http.js')
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. shopInfo: {},
  9. shopCategoryList: [],
  10. selIndex: 0,
  11. prodList:[],
  12. shopCategoryId: 0,
  13. pages: 0,
  14. current: 1,
  15. },
  16. // 跳转店内搜索页
  17. toShopSearchPage: function(e) {
  18. wx.navigateTo({
  19. url: '/pages/shopSearch/shopSearch?shopId=' + e.currentTarget.dataset.shopid,
  20. })
  21. },
  22. // 分类点击事件
  23. onMenuTab: function(e) {
  24. let categoryId = e.currentTarget.dataset.categoryid;
  25. const { index } = e.currentTarget.dataset;
  26. this.setData({
  27. selIndex: index,
  28. shopCategoryId: categoryId,
  29. current: 1,
  30. pages: 0
  31. });
  32. this.getProdListByCategoryId()
  33. },
  34. // 获取店内分类列表
  35. getShopCategory: function() {
  36. let shopId = this.data.shopInfo.shopId
  37. var params = {
  38. url: '/category/categoryInfo',
  39. method: 'GET',
  40. data: {
  41. shopId
  42. },
  43. callBack: (res) => {
  44. this.setData({
  45. shopCategoryList:res,
  46. shopCategoryId: res[0].categoryId
  47. })
  48. this.getProdListByCategoryId()
  49. }
  50. }
  51. http.request(params)
  52. },
  53. // 根据店铺分类id获取商品
  54. getProdListByCategoryId(){
  55. var params = {
  56. url:'/search/searchProdPage',
  57. method:'GET',
  58. data:{
  59. shopCategoryId: this.data.shopCategoryId,
  60. shopId: this.data.shopInfo.shopId,
  61. current: this.data.current,
  62. size:10,
  63. sort:0,
  64. isAllProdType: true,
  65. platform:1
  66. },
  67. callBack:res=>{
  68. this.setData({
  69. prodList: res.current == 1 ? res.records : this.data.prodList.concat(res.records),
  70. current: res.current,
  71. pages: res.pages
  72. })
  73. }
  74. }
  75. http.request(params)
  76. },
  77. // scroll-view 触底事件
  78. getNextPage () {
  79. if (this.data.current < this.data.pages) {
  80. this.setData({
  81. current: this.data.current + 1
  82. })
  83. this.getProdListByCategoryId()
  84. }
  85. },
  86. // 跳转商品详情页
  87. toProdPage: function(e) {
  88. var prodid = e.currentTarget.dataset.prodid;
  89. wx.navigateTo({
  90. url: '/pages/prod/prod?prodid=' + prodid,
  91. })
  92. },
  93. /**
  94. * 跳转店铺详情
  95. */
  96. toShopInfo() {
  97. wx.navigateTo({
  98. url: '/pages/shopInfo/shopInfo?shopId=' + this.data.shopInfo.shopId,
  99. })
  100. },
  101. /**
  102. * 生命周期函数--监听页面加载
  103. */
  104. onLoad: function(options) {
  105. this.setData({
  106. shopInfo: wx.getStorageSync("shopInfo")
  107. })
  108. this.getShopCategory()
  109. this.getProdListByCategoryId()
  110. },
  111. /**
  112. * 生命周期函数--监听页面初次渲染完成
  113. */
  114. onReady: function() {
  115. },
  116. /**
  117. * 生命周期函数--监听页面显示
  118. */
  119. onShow: function() {
  120. },
  121. /**
  122. * 生命周期函数--监听页面隐藏
  123. */
  124. onHide: function() {
  125. },
  126. /**
  127. * 生命周期函数--监听页面卸载
  128. */
  129. onUnload: function() {
  130. },
  131. /**
  132. * 页面相关事件处理函数--监听用户下拉动作
  133. */
  134. onPullDownRefresh: function() {
  135. },
  136. /**
  137. * 页面上拉触底事件的处理函数
  138. */
  139. onReachBottom: function() {
  140. },
  141. /**
  142. * 用户点击右上角分享
  143. */
  144. onShareAppMessage: function() {
  145. }
  146. })