hotGoods.js 2.5 KB

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