home.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. this.setData({
  41. avatarUrl:wx.getStorageSync('avatarUrl'),
  42. nickName:wx.getStorageSync('nickName')
  43. })
  44. },
  45. getClassifyList() {
  46. getCategoryAPI(this.data)
  47. .then((data) => {
  48. this.setData({
  49. classifyList: data
  50. })
  51. })
  52. },
  53. getGoodsList() {
  54. getClassifyGoods(this.data).then((data) => {
  55. console.log(data);
  56. })
  57. },
  58. /**
  59. * 生命周期函数--监听页面初次渲染完成
  60. */
  61. onReady() {
  62. },
  63. /**
  64. * 生命周期函数--监听页面显示
  65. */
  66. onShow() {
  67. },
  68. /**
  69. * 生命周期函数--监听页面隐藏
  70. */
  71. onHide() {
  72. },
  73. /**
  74. * 生命周期函数--监听页面卸载
  75. */
  76. onUnload() {
  77. },
  78. /**
  79. * 页面相关事件处理函数--监听用户下拉动作
  80. */
  81. onPullDownRefresh() {
  82. },
  83. /**
  84. * 页面上拉触底事件的处理函数
  85. */
  86. onReachBottom() {
  87. },
  88. /**
  89. * 用户点击右上角分享
  90. */
  91. onShareAppMessage() {
  92. },
  93. /**
  94. * 监听页面滑动
  95. */
  96. onPageScroll(data) {
  97. // console.log(data.scrollTop);
  98. this.setData({
  99. scrollTop: data.scrollTop
  100. })
  101. }
  102. })