hotGoods.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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': '/static/images/hot.png',
  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. limit: 10
  19. },
  20. getCategoryList: function() {
  21. var that = this;
  22. util.request(api.GoodsFilter, {
  23. isHot: 1
  24. })
  25. .then(function(res) {
  26. if (res.errno === 0) {
  27. that.setData({
  28. filterCategory: res.data.filterCategoryList,
  29. });
  30. }
  31. });
  32. },
  33. getGoodsList: function() {
  34. var that = this;
  35. util.request(api.GoodsList, {
  36. isHot: true,
  37. page: that.data.page,
  38. limit: that.data.limit,
  39. order: that.data.currentSortOrder,
  40. sort: that.data.currentSort,
  41. categoryId: that.data.categoryId
  42. })
  43. .then(function(res) {
  44. if (res.errno === 0) {
  45. that.setData({
  46. goodsList: res.data.list,
  47. filterCategory: res.data.filterCategoryList
  48. });
  49. }
  50. });
  51. },
  52. onLoad: function(options) {
  53. // 页面初始化 options为页面跳转所带来的参数
  54. this.getGoodsList();
  55. },
  56. onReady: function() {
  57. // 页面渲染完成
  58. },
  59. onShow: function() {
  60. // 页面显示
  61. },
  62. onHide: function() {
  63. // 页面隐藏
  64. },
  65. onUnload: function() {
  66. // 页面关闭
  67. },
  68. openSortFilter: function(event) {
  69. let currentId = event.currentTarget.id;
  70. switch (currentId) {
  71. case 'categoryFilter':
  72. this.setData({
  73. categoryFilter: !this.data.categoryFilter,
  74. currentSortType: 'category',
  75. currentSort: 'add_time',
  76. currentSortOrder: 'desc'
  77. });
  78. break;
  79. case 'priceSort':
  80. let tmpSortOrder = 'asc';
  81. if (this.data.currentSortOrder == 'asc') {
  82. tmpSortOrder = 'desc';
  83. }
  84. this.setData({
  85. currentSortType: 'price',
  86. currentSort: 'retail_price',
  87. currentSortOrder: tmpSortOrder,
  88. categoryFilter: false
  89. });
  90. this.getGoodsList();
  91. break;
  92. default:
  93. //综合排序
  94. this.setData({
  95. currentSortType: 'default',
  96. currentSort: 'add_time',
  97. currentSortOrder: 'desc',
  98. categoryFilter: false,
  99. categoryId: 0,
  100. });
  101. this.getGoodsList();
  102. }
  103. },
  104. selectCategory: function(event) {
  105. let currentIndex = event.target.dataset.categoryIndex;
  106. this.setData({
  107. 'categoryFilter': false,
  108. 'categoryId': this.data.filterCategory[currentIndex].id
  109. });
  110. this.getGoodsList();
  111. }
  112. })