cate.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. const app = getApp()
  2. Page({
  3. data: {
  4. loading: true,
  5. curIndex: 0,
  6. page: 0,
  7. cate: [],
  8. cate_sub: [],
  9. item:[]
  10. },
  11. //载入
  12. onLoad: function () {
  13. this.selectNav();
  14. },
  15. onShow: function () {
  16. app.setTabBarCartNumber();
  17. },
  18. //上拉加载
  19. onReachBottom: function () {
  20. var that = this;
  21. that.setData({
  22. loading: true,
  23. });
  24. that.geItem();
  25. },
  26. //读取目录
  27. selectNav: function (callback) {
  28. let that = this;
  29. wx.showLoading({ title: '正在加载' })
  30. app.api().Get('api/v3/fastshop/shop/cate', function (result) {
  31. that.setData({
  32. cate: result.data.root_data,
  33. cate_sub: result.data.subs_data,
  34. curIndex: result.data.root_data[0]['id'],
  35. });
  36. wx.hideLoading();
  37. })
  38. },
  39. //读取子目录
  40. selectCate: function (e) {
  41. let that = this;
  42. var id = parseInt(e.currentTarget.dataset.id);
  43. that.setData({
  44. curIndex: id,
  45. });
  46. },
  47. //搜索
  48. onSearch: function (event) {
  49. let that = this;
  50. if (!app.util().isNull(event.detail)) {
  51. var keyword = event.detail;
  52. wx.navigateTo({
  53. url: '../shop/search?keyword=' + keyword,
  54. })
  55. }
  56. }
  57. })