hotGoods.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. var util = require('../../../utils/util.js');
  2. var api = require('../../../config/api.js');
  3. var app = getApp();
  4. Page({
  5. data: {
  6. addressInfo:{},
  7. bannerInfo: {
  8. 'imgUrl': 'https://jzmall.lifejingzhi.com/file/jzmall/weixin/new/img-hot.png',
  9. 'name': '大家都在买的'
  10. },
  11. categoryFilter: false,
  12. filterCategory: [],
  13. goodsList: [],
  14. categoryId: 0,
  15. currentSortType: 'default',
  16. currentSort: 'create_time',
  17. currentSortOrder: 'desc',
  18. page: 1,
  19. limit: 10
  20. },
  21. getCategoryList: function() {
  22. var that = this;
  23. util.request(api.GoodsFilter, {
  24. isHot: 1
  25. })
  26. .then(function(res) {
  27. if (res.errno === 0) {
  28. that.setData({
  29. filterCategory: res.data.filterCategoryList,
  30. });
  31. }
  32. });
  33. },
  34. getGoodsList: function() {
  35. var that = this;
  36. util.request(api.GoodsList, {
  37. isHot: true,
  38. page: that.data.page,
  39. limit: that.data.limit,
  40. order: that.data.currentSortOrder,
  41. sort: that.data.currentSort,
  42. categoryId: that.data.categoryId,
  43. city:that.data.addressInfo.city,
  44. shopId:that.data.addressInfo.shopId
  45. })
  46. .then(function(res) {
  47. console.info(res)
  48. if (res.errno === 0) {
  49. that.setData({
  50. goodsList: res.data.list,
  51. filterCategory: res.data.filterCategoryList
  52. });
  53. }
  54. });
  55. },
  56. onLoad: function(options) {
  57. // 页面初始化 options为页面跳转所带来的参数
  58. var addressInfo=wx.getStorageSync('addressInfo');
  59. if(addressInfo){
  60. this.setData({
  61. addressInfo:addressInfo
  62. })
  63. }
  64. this.getGoodsList();
  65. },
  66. onReady: function() {
  67. // 页面渲染完成
  68. },
  69. onShow: function() {
  70. // 页面显示
  71. },
  72. onHide: function() {
  73. // 页面隐藏
  74. },
  75. onUnload: function() {
  76. // 页面关闭
  77. },
  78. openSortFilter: function(event) {
  79. let currentId = event.currentTarget.id;
  80. switch (currentId) {
  81. case 'categoryFilter':
  82. this.setData({
  83. categoryFilter: !this.data.categoryFilter,
  84. currentSortType: 'category',
  85. currentSort: 'create_time',
  86. currentSortOrder: 'desc'
  87. });
  88. break;
  89. case 'priceSort':
  90. let tmpSortOrder = 'asc';
  91. if (this.data.currentSortOrder == 'asc') {
  92. tmpSortOrder = 'desc';
  93. }
  94. this.setData({
  95. currentSortType: 'price',
  96. currentSort: 'retail_price',
  97. currentSortOrder: tmpSortOrder,
  98. categoryFilter: false
  99. });
  100. this.getGoodsList();
  101. break;
  102. default:
  103. //综合排序
  104. this.setData({
  105. currentSortType: 'default',
  106. currentSort: 'create_time',
  107. currentSortOrder: 'desc',
  108. categoryFilter: false,
  109. categoryId: 0,
  110. });
  111. this.getGoodsList();
  112. }
  113. },
  114. selectCategory: function(event) {
  115. let currentIndex = event.target.dataset.categoryIndex;
  116. this.setData({
  117. 'categoryFilter': false,
  118. 'categoryId': this.data.filterCategory[currentIndex].id
  119. });
  120. this.getGoodsList();
  121. }
  122. })