beerList.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // pages/beerList/beerList.js
  2. const request = require("../../utils/request.js");
  3. const login = require("../../utils/login.js");
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. breweryId: null,
  10. productDataList: []
  11. },
  12. toBeerDetail(event) {
  13. login.ifLogin('../beerDetail/beerDetail?productId=' + event.currentTarget.dataset.pid)
  14. },
  15. getProductList() {
  16. let that = this;
  17. let breweryId = Number(that.data.breweryId);
  18. request.getData(
  19. 'app/product/list',
  20. {breweryId: breweryId},
  21. res => {
  22. that.setData({
  23. productDataList: res.data.data
  24. })
  25. },
  26. res => {
  27. console.log(res)
  28. }
  29. )
  30. },
  31. /**
  32. * 生命周期函数--监听页面加载
  33. */
  34. onLoad(options) {
  35. let title = options.name;
  36. this.setData({
  37. breweryId: options.breweryId
  38. })
  39. wx.setNavigationBarTitle({
  40. title: title,
  41. })
  42. this.getProductList()
  43. },
  44. /**
  45. * 生命周期函数--监听页面初次渲染完成
  46. */
  47. onReady() {
  48. },
  49. /**
  50. * 生命周期函数--监听页面显示
  51. */
  52. onShow() {
  53. },
  54. /**
  55. * 生命周期函数--监听页面隐藏
  56. */
  57. onHide() {
  58. },
  59. /**
  60. * 生命周期函数--监听页面卸载
  61. */
  62. onUnload() {
  63. },
  64. /**
  65. * 页面相关事件处理函数--监听用户下拉动作
  66. */
  67. onPullDownRefresh() {
  68. },
  69. /**
  70. * 页面上拉触底事件的处理函数
  71. */
  72. onReachBottom() {
  73. let that = this;
  74. let breweryId = Number(that.data.breweryId);
  75. let lastProductId = Number(that.data.productDataList[that.data.productDataList.length-1].productId);
  76. request.getData(
  77. 'app/product/list',
  78. {breweryId: breweryId, lastProductId: lastProductId},
  79. res => {
  80. that.setData({
  81. productDataList: that.data.productDataList.concat(res.data.data)
  82. })
  83. },
  84. res => {
  85. console.log(res)
  86. }
  87. )
  88. },
  89. /**
  90. * 用户点击右上角分享
  91. */
  92. onShareAppMessage() {
  93. }
  94. })