home.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. // pages/home/home.js
  2. const { getCategoryAPI } = require('../../API/categories')
  3. const { getClassifyGoods } = require('../../API/classifyGoods')
  4. Page({
  5. /**
  6. * 页面初始数据
  7. */
  8. data: {
  9. //存放分类列表
  10. classifyList: [],
  11. //用于存放页面上划高度
  12. scrollTop: 0,
  13. },
  14. userTo() {
  15. wx.switchTab({
  16. url: '/pages/user/user',
  17. })
  18. },
  19. classifyTo() {
  20. wx.switchTab({//tabBar页面跳转要用wx.switchTab
  21. url: '/pages/classify/classify',
  22. })
  23. },
  24. searchTo() {
  25. wx.navigateTo({
  26. url: '/pages/search/search',
  27. })
  28. },
  29. //获取点击分类的id
  30. detailClassifyTo({ currentTarget }) {
  31. const id = currentTarget.dataset.num;
  32. wx.navigateTo({
  33. url: '/pages/classify_detail/classify_detail?classify_id=' + id,
  34. })
  35. },
  36. /**
  37. * 生命周期函数--监听页面加载
  38. */
  39. onLoad(options) {
  40. this.getClassifyList();
  41. },
  42. getClassifyList() {
  43. getCategoryAPI(this.data).then((data) => {
  44. this.setData({
  45. classifyList: data
  46. })
  47. })
  48. },
  49. getGoodsList() {
  50. getClassifyGoods(this.data).then((data) => {
  51. console.log(data);
  52. })
  53. },
  54. /**
  55. * 生命周期函数--监听页面初次渲染完成
  56. */
  57. onReady() {
  58. },
  59. /**
  60. * 生命周期函数--监听页面显示
  61. */
  62. onShow() {
  63. },
  64. /**
  65. * 生命周期函数--监听页面隐藏
  66. */
  67. onHide() {
  68. },
  69. /**
  70. * 生命周期函数--监听页面卸载
  71. */
  72. onUnload() {
  73. },
  74. /**
  75. * 页面相关事件处理函数--监听用户下拉动作
  76. */
  77. onPullDownRefresh() {
  78. },
  79. /**
  80. * 页面上拉触底事件的处理函数
  81. */
  82. onReachBottom() {
  83. },
  84. /**
  85. * 用户点击右上角分享
  86. */
  87. onShareAppMessage() {
  88. },
  89. /**
  90. * 监听页面滑动
  91. */
  92. onPageScroll(data) {
  93. // console.log(data.scrollTop);
  94. this.setData({
  95. scrollTop: data.scrollTop
  96. })
  97. }
  98. })