newGoods.js 2.7 KB

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