newGoods.js 2.6 KB

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