catalog.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. var util = require('../../utils/util.js');
  2. var api = require('../../config/api.js');
  3. Page({
  4. data: {
  5. navList: [],
  6. categoryList: [],
  7. currentCategory: {},
  8. scrollLeft: 0,
  9. scrollTop: 0,
  10. goodsCount: 0,
  11. scrollHeight: 0
  12. },
  13. onLoad: function(options) {
  14. this.getCatalog();
  15. },
  16. getCatalog: function() {
  17. //CatalogList
  18. let that = this;
  19. wx.showLoading({
  20. title: '加载中...',
  21. });
  22. util.request(api.CatalogList).then(function(res) {
  23. that.setData({
  24. navList: res.data.categoryList,
  25. currentCategory: res.data.currentCategory
  26. });
  27. wx.hideLoading();
  28. });
  29. },
  30. getCurrentCategory: function(id) {
  31. let that = this;
  32. util.request(api.CatalogCurrent + "/" + id)
  33. .then(function(res) {
  34. that.setData({
  35. currentCategory: res.data.currentCategory
  36. });
  37. });
  38. },
  39. onReady: function() {
  40. // 页面渲染完成
  41. },
  42. onShow: function() {
  43. // 页面显示
  44. },
  45. onHide: function() {
  46. // 页面隐藏
  47. },
  48. onUnload: function() {
  49. // 页面关闭
  50. },
  51. switchCate: function(event) {
  52. var that = this;
  53. var currentTarget = event.currentTarget;
  54. if (this.data.currentCategory.id == event.currentTarget.dataset.id) {
  55. return false;
  56. }
  57. this.getCurrentCategory(event.currentTarget.dataset.id);
  58. }
  59. })