sub-category.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. // pages/sub-category/sub-category.js
  2. var http = require("../../utils/http.js");
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. subCategoryList: [],
  9. categoryId: 0,
  10. prodList: [],
  11. categoryName:'',
  12. current: 1,
  13. pages: 0,
  14. shopId:0
  15. },
  16. // 获取顶栏子分类数据
  17. getSubCategory() {
  18. var params = {
  19. url: "/category/categoryInfo",
  20. method: "GET",
  21. data: {
  22. shopId:this.data.shopId||'',
  23. parentId: this.data.parentId||0
  24. },
  25. callBack: (res) => {
  26. this.setData({
  27. subCategoryList: res,
  28. });
  29. }
  30. };
  31. http.request(params);
  32. },
  33. // 根据分类id获取商品数据
  34. getProdList() {
  35. var params = {
  36. url: "/search/searchProdPage",
  37. method: "GET",
  38. data: {
  39. categoryId: this.data.categoryId,
  40. current: this.data.current,
  41. size: 10,
  42. sort: 0,
  43. isAllProdType: true,
  44. platform:1
  45. // lat: wx.getStorageSync('LATITUDE'),
  46. // lon: wx.getStorageSync('LONGITUDE'),
  47. // distance: wx.getStorageSync('DISTANCE') || 0
  48. },
  49. callBack: (res) => {
  50. let img = ''
  51. res.records.forEach(e => {
  52. img = e.pic.split(',')
  53. e.pic = img[0]
  54. })
  55. this.setData({
  56. prodList: res.current == 1 ? res.records : this.data.prodList.concat(res.records),
  57. pages: res.pages
  58. });
  59. }
  60. };
  61. http.request(params);
  62. },
  63. // 切换子分类tab
  64. onSubCategoryTap(e) {
  65. this.setData({
  66. categoryId: e.currentTarget.dataset.id,
  67. current: 1,
  68. pages: 0,
  69. intoView: 'sw' + e.currentTarget.dataset.id,
  70. })
  71. this.getProdList()
  72. },
  73. /**
  74. * 生命周期函数--监听页面加载
  75. */
  76. onLoad: function (options) {
  77. console.log(options);
  78. this.setData({
  79. parentId: options.parentId,
  80. categoryId: options.categoryId,
  81. intoView: 'sw' + options.categoryId,
  82. categoryName:options.categoryName,
  83. shopId:options.shopId
  84. })
  85. this.getSubCategory()
  86. setTimeout(()=>{
  87. this.getProdList()
  88. },500)
  89. },
  90. /**
  91. * 生命周期函数--监听页面初次渲染完成
  92. */
  93. onReady: function () {
  94. },
  95. /**
  96. * 生命周期函数--监听页面显示
  97. */
  98. onShow: function () {
  99. },
  100. /**
  101. * 生命周期函数--监听页面隐藏
  102. */
  103. onHide: function () {
  104. },
  105. /**
  106. * 生命周期函数--监听页面卸载
  107. */
  108. onUnload: function () {
  109. },
  110. /**
  111. * 页面相关事件处理函数--监听用户下拉动作
  112. */
  113. onPullDownRefresh: function () {
  114. },
  115. /**
  116. * 页面上拉触底事件的处理函数
  117. */
  118. onReachBottom: function () {
  119. if (this.data.current < this.data.pages) {
  120. this.setData({
  121. current: this.data.current + 1,
  122. })
  123. this.getProdList()
  124. }
  125. },
  126. /**
  127. * 用户点击右上角分享
  128. */
  129. onShareAppMessage: function () {
  130. }
  131. })