catalog.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. var util = require('../../utils/util.js');
  2. var api = require('../../config/api.js');
  3. Page({
  4. data: {
  5. categoryList: [],
  6. currentCategory: {},
  7. currentSubCategoryList: {},
  8. scrollLeft: 0,
  9. scrollTop: 0,
  10. goodsCount: 0,
  11. scrollHeight: 0
  12. },
  13. onLoad: function(options) {
  14. this.getCatalog();
  15. },
  16. onPullDownRefresh() {
  17. wx.showNavigationBarLoading() //在标题栏中显示加载
  18. this.getCatalog();
  19. wx.hideNavigationBarLoading() //完成停止加载
  20. wx.stopPullDownRefresh() //停止下拉刷新
  21. },
  22. getCatalog: function() {
  23. //CatalogList
  24. let that = this;
  25. wx.showLoading({
  26. title: '加载中...',
  27. });
  28. util.request(api.CatalogList).then(function(res) {
  29. that.setData({
  30. categoryList: res.data.categoryList,
  31. currentCategory: res.data.currentCategory,
  32. currentSubCategoryList: res.data.currentSubCategory
  33. });
  34. wx.hideLoading();
  35. });
  36. util.request(api.GoodsCount).then(function(res) {
  37. that.setData({
  38. goodsCount: res.data
  39. });
  40. });
  41. },
  42. getCurrentCategory: function(id) {
  43. let that = this;
  44. util.request(api.CatalogCurrent, {
  45. id: id
  46. })
  47. .then(function(res) {
  48. that.setData({
  49. currentCategory: res.data.currentCategory,
  50. currentSubCategoryList: res.data.currentSubCategory
  51. });
  52. });
  53. },
  54. onReady: function() {
  55. // 页面渲染完成
  56. },
  57. onShow: function() {
  58. // 页面显示
  59. },
  60. onHide: function() {
  61. // 页面隐藏
  62. },
  63. onUnload: function() {
  64. // 页面关闭
  65. },
  66. switchCate: function(event) {
  67. var that = this;
  68. var currentTarget = event.currentTarget;
  69. if (this.data.currentCategory.id == event.currentTarget.dataset.id) {
  70. return false;
  71. }
  72. this.getCurrentCategory(event.currentTarget.dataset.id);
  73. }
  74. })