home.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // pages/home/home.js
  2. const { http } = require('../../utils/util')
  3. const { getGoods } = require('../../utils/util')
  4. const API = {
  5. getCategoryURL: '/category',
  6. getGoodsMessage: '/goods/recommend'
  7. }
  8. Page({
  9. /**
  10. * 页面初始数据
  11. */
  12. data: {
  13. //存放分类列表
  14. classifyList: []
  15. },
  16. classifyTo() {
  17. wx.switchTab({//tabBar页面跳转要用wx.switchTab
  18. url: '/pages/classify/classify',
  19. })
  20. },
  21. searchTo() {
  22. wx.navigateTo({
  23. url: '/pages/search/search',
  24. })
  25. },
  26. /**
  27. * 生命周期函数--监听页面加载
  28. */
  29. onLoad(options) {
  30. this.getClassifyList(),
  31. this.getGoodsList()
  32. },
  33. getClassifyList() {
  34. http({url: API.getCategoryURL, data: this.data}).then((res) => {
  35. wx.setStorageSync('classifyList',res);
  36. let classifyList = wx.getStorageSync('classifyList')
  37. this.setData({
  38. classifyList: [...res],
  39. imgUrl: classifyList[0].Pic,
  40. classifyName: classifyList[0].Name
  41. })
  42. })
  43. },
  44. getGoodsList() {
  45. getGoods({url: API.getGoodsMessage, data: this.data}).then((res) => {
  46. console.log(res);
  47. })
  48. },
  49. /**
  50. * 生命周期函数--监听页面初次渲染完成
  51. */
  52. onReady() {
  53. },
  54. /**
  55. * 生命周期函数--监听页面显示
  56. */
  57. onShow() {
  58. },
  59. /**
  60. * 生命周期函数--监听页面隐藏
  61. */
  62. onHide() {
  63. },
  64. /**
  65. * 生命周期函数--监听页面卸载
  66. */
  67. onUnload() {
  68. },
  69. /**
  70. * 页面相关事件处理函数--监听用户下拉动作
  71. */
  72. onPullDownRefresh() {
  73. },
  74. /**
  75. * 页面上拉触底事件的处理函数
  76. */
  77. onReachBottom() {
  78. },
  79. /**
  80. * 用户点击右上角分享
  81. */
  82. onShareAppMessage() {
  83. },
  84. })