catalog.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. onPullDownRefresh() {
  17. this.getCatalog();
  18. },
  19. getCatalog: function () {
  20. //CatalogList
  21. let that = this;
  22. wx.showLoading({
  23. title: '加载中...',
  24. });
  25. util.request(api.CatalogList).then(function (res) {
  26. that.setData({
  27. navList: res.data.categoryList,
  28. currentCategory: res.data.currentCategory
  29. });
  30. wx.hideLoading();
  31. });
  32. util.request(api.GoodsCount).then(function (res) {
  33. that.setData({
  34. goodsCount: res.data.goodsCount
  35. });
  36. });
  37. },
  38. getCurrentCategory: function (id) {
  39. let that = this;
  40. util.request(api.CatalogCurrent, { id: id })
  41. .then(function (res) {
  42. that.setData({
  43. currentCategory: res.data.currentCategory
  44. });
  45. });
  46. },
  47. onReady: function () {
  48. // 页面渲染完成
  49. },
  50. onShow: function () {
  51. // 页面显示
  52. if (typeof this.getTabBar === 'function' && this.getTabBar()) {
  53. this.getTabBar().setData({
  54. selected: 1
  55. })
  56. }
  57. },
  58. onHide: function () {
  59. // 页面隐藏
  60. },
  61. onUnload: function () {
  62. // 页面关闭
  63. },
  64. getList: function () {
  65. var that = this;
  66. util.request(api.ApiRootUrl + 'api/catalog/' + that.data.currentCategory.cat_id)
  67. .then(function (res) {
  68. that.setData({
  69. categoryList: res.data,
  70. });
  71. });
  72. },
  73. switchCate: function (event) {
  74. var that = this;
  75. var currentTarget = event.currentTarget;
  76. if (this.data.currentCategory.id == event.currentTarget.dataset.id) {
  77. return false;
  78. }
  79. this.getCurrentCategory(event.currentTarget.dataset.id);
  80. }
  81. })