hotGoods.js 3.0 KB

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