classify_detail.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // pages/classify_detail/classify_detail.js
  2. // const { http } = require('../../utils/util')
  3. const { getClassifyGoods } = require('../../API/appraise')
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. classifyShow: [],
  10. page: 1,
  11. pageSize: 6,
  12. id: 3,
  13. title: "",
  14. //节流阀
  15. isLoading: false
  16. },
  17. /**
  18. * 生命周期函数--监听页面加载
  19. */
  20. onLoad(options) {
  21. //setData和getGoods的顺序也非常重要
  22. this.setData({
  23. // 传递点击的分类id
  24. id: options.classify_id,
  25. //传递点击的分类名称
  26. title: options.title
  27. }),
  28. wx.setNavigationBarTitle({
  29. title: this.data.title,
  30. })
  31. this.getGoods()
  32. },
  33. getGoods() {
  34. //加载的loading效果
  35. wx.showLoading({
  36. title: '数据获取中',
  37. })
  38. getClassifyGoods(this.data).then((res) => {
  39. console.log(this.data);
  40. const { data } = res.data;
  41. console.log(res);
  42. this.setData({
  43. classifyShow: [...this.data.classifyShow , ...data.data],
  44. isLoading: true
  45. })
  46. console.log(this.data.classifyShow);
  47. })
  48. this.setData({
  49. isLoading: false
  50. })
  51. },
  52. /**
  53. * 生命周期函数--监听页面初次渲染完成
  54. */
  55. onReady() {
  56. },
  57. /**
  58. * 生命周期函数--监听页面显示
  59. */
  60. onShow() {
  61. },
  62. /**
  63. * 生命周期函数--监听页面隐藏
  64. */
  65. onHide() {
  66. },
  67. /**
  68. * 生命周期函数--监听页面卸载
  69. */
  70. onUnload() {
  71. },
  72. /**
  73. * 页面相关事件处理函数--监听用户下拉动作
  74. */
  75. onPullDownRefresh() {
  76. },
  77. /**
  78. * 页面上拉触底事件的处理函数
  79. */
  80. onReachBottom() {
  81. if(this.data.isLoading) {
  82. this.setData({
  83. page: this.data.page + 1,
  84. })
  85. this.getGoods()
  86. }
  87. },
  88. /**
  89. * 用户点击右上角分享
  90. */
  91. onShareAppMessage() {
  92. }
  93. })