beerFactory.js 1.7 KB

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