shopCategory.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. channelId:wx.getStorageSync('channelId'),
  67. },
  68. callBack:res=>{
  69. this.setData({
  70. prodList: res.current == 1 ? res.records : this.data.prodList.concat(res.records),
  71. current: res.current,
  72. pages: res.pages
  73. })
  74. }
  75. }
  76. http.request(params)
  77. },
  78. // scroll-view 触底事件
  79. getNextPage () {
  80. if (this.data.current < this.data.pages) {
  81. this.setData({
  82. current: this.data.current + 1
  83. })
  84. this.getProdListByCategoryId()
  85. }
  86. },
  87. // 跳转商品详情页
  88. toProdPage: function(e) {
  89. var prodid = e.currentTarget.dataset.prodid;
  90. wx.navigateTo({
  91. url: '/pages/prod/prod?prodid=' + prodid,
  92. })
  93. },
  94. /**
  95. * 跳转店铺详情
  96. */
  97. toShopInfo() {
  98. wx.navigateTo({
  99. url: '/pages/shopInfo/shopInfo?shopId=' + this.data.shopInfo.shopId,
  100. })
  101. },
  102. /**
  103. * 生命周期函数--监听页面加载
  104. */
  105. onLoad: function(options) {
  106. this.setData({
  107. shopInfo: wx.getStorageSync("shopInfo")
  108. })
  109. this.getShopCategory()
  110. this.getProdListByCategoryId()
  111. },
  112. /**
  113. * 生命周期函数--监听页面初次渲染完成
  114. */
  115. onReady: function() {
  116. },
  117. /**
  118. * 生命周期函数--监听页面显示
  119. */
  120. onShow: function() {
  121. },
  122. /**
  123. * 生命周期函数--监听页面隐藏
  124. */
  125. onHide: function() {
  126. },
  127. /**
  128. * 生命周期函数--监听页面卸载
  129. */
  130. onUnload: function() {
  131. },
  132. /**
  133. * 页面相关事件处理函数--监听用户下拉动作
  134. */
  135. onPullDownRefresh: function() {
  136. },
  137. /**
  138. * 页面上拉触底事件的处理函数
  139. */
  140. onReachBottom: function() {
  141. },
  142. /**
  143. * 用户点击右上角分享
  144. */
  145. onShareAppMessage: function() {
  146. }
  147. })