home.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. // pages/home/home.js
  2. const { getCategoryAPI,getClassifyGoods} = require('../../API/appraise')
  3. Page({
  4. /**
  5. * 页面初始数据
  6. */
  7. data: {
  8. //存放分类列表
  9. classifyList: [],
  10. //用于存放页面上划高度
  11. scrollTop: 0,
  12. },
  13. userTo() {
  14. wx.switchTab({
  15. url: '/pages/user/user',
  16. })
  17. },
  18. classifyTo() {
  19. wx.switchTab({//tabBar页面跳转要用wx.switchTab
  20. url: '/pages/classify/classify',
  21. })
  22. },
  23. searchTo() {
  24. wx.navigateTo({
  25. url: '/pages/search/search',
  26. })
  27. },
  28. //获取点击分类的id
  29. detailClassifyTo({ currentTarget }) {
  30. const id = currentTarget.dataset.num;
  31. wx.navigateTo({
  32. url: '/pages/classify_detail/classify_detail?classify_id=' + id,
  33. })
  34. },
  35. /**
  36. * 生命周期函数--监听页面加载
  37. */
  38. onLoad(options) {
  39. this.getClassifyList();
  40. },
  41. getClassifyList() {
  42. getCategoryAPI(this.data)
  43. .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. })