newGoods.js 2.5 KB

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