catalog.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. allList: {},
  9. scrollLeft: 0,
  10. scrollTop: 0,
  11. goodsCount: 0,
  12. scrollHeight: 0
  13. },
  14. onLoad: function(options) {
  15. this.getCatalog();
  16. },
  17. onPullDownRefresh() {
  18. wx.showNavigationBarLoading() //在标题栏中显示加载
  19. this.getCatalog();
  20. wx.hideNavigationBarLoading() //完成停止加载
  21. wx.stopPullDownRefresh() //停止下拉刷新
  22. },
  23. getCatalog: function() {
  24. //CatalogList
  25. let that = this;
  26. wx.showLoading({
  27. title: '加载中...',
  28. });
  29. util.request(api.CatalogAll).then(function(res) {
  30. that.setData({
  31. allList: res.data.allList,
  32. categoryList: res.data.categoryList,
  33. currentCategory: res.data.currentCategory,
  34. currentSubCategoryList: res.data.currentSubCategory
  35. });
  36. });
  37. wx.hideLoading();
  38. },
  39. getCurrentCategory: function(item) {
  40. let that = this;
  41. for (var key in that.data.allList) {
  42. if (key == item.id) {
  43. that.setData({
  44. currentCategory: item,
  45. currentSubCategoryList: that.data.allList[key]
  46. });
  47. }
  48. }
  49. },
  50. onReady: function() {
  51. // 页面渲染完成
  52. },
  53. onShow: function() {
  54. // 页面显示
  55. },
  56. onHide: function() {
  57. // 页面隐藏
  58. },
  59. onUnload: function() {
  60. // 页面关闭
  61. },
  62. switchCate: function(event) {
  63. if (this.data.currentCategory.id == event.currentTarget.dataset.id) {
  64. return false;
  65. }
  66. this.getCurrentCategory(event.currentTarget.dataset.id);
  67. },
  68. levelClick: function(e) {
  69. console.log(e.currentTarget.dataset.id)
  70. wx.navigateTo({
  71. url: "/pages/category/category?id=" + e.currentTarget.dataset.id
  72. })
  73. }
  74. })