catalog.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. util.request(api.GoodsCount).then(function (res) {
  30. that.setData({
  31. goodsCount: res.data.goodsCount
  32. });
  33. });
  34. },
  35. getCurrentCategory: function (id) {
  36. let that = this;
  37. util.request(api.CatalogCurrent, { id: id })
  38. .then(function (res) {
  39. that.setData({
  40. currentCategory: res.data.currentCategory
  41. });
  42. });
  43. },
  44. onReady: function () {
  45. // 页面渲染完成
  46. },
  47. onShow: function () {
  48. // 页面显示
  49. },
  50. onHide: function () {
  51. // 页面隐藏
  52. },
  53. onUnload: function () {
  54. // 页面关闭
  55. },
  56. getList: function () {
  57. var that = this;
  58. util.request(api.ApiRootUrl + 'api/catalog/' + that.data.currentCategory.cat_id)
  59. .then(function (res) {
  60. that.setData({
  61. categoryList: res.data,
  62. });
  63. });
  64. },
  65. switchCate: function (event) {
  66. var that = this;
  67. var currentTarget = event.currentTarget;
  68. if (this.data.currentCategory.id == event.currentTarget.dataset.id) {
  69. return false;
  70. }
  71. this.getCurrentCategory(event.currentTarget.dataset.id);
  72. }
  73. })