pianoList.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. // pages/pianoList/pianoList.js
  2. const app = getApp()
  3. const util = require("../../utils/util")
  4. const urlDef = require("../../utils/urls")
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. list: [
  11. ],
  12. loading: '上拉加载',
  13. flag: 0,
  14. pageNum: 0,
  15. hasNextPage: true,
  16. },
  17. getCard: function (e) {
  18. let item = this.data.list[e.currentTarget.dataset.index]
  19. wx.navigateTo({
  20. url: '/pages/pianoDetail/pianoDetail?data=' + JSON.stringify(item),
  21. })
  22. },
  23. /**
  24. * 生命周期函数--监听页面加载
  25. */
  26. onLoad: function (options) {
  27. this.queryList();
  28. },
  29. /**
  30. * 生命周期函数--监听页面初次渲染完成
  31. */
  32. onReady: function () {
  33. },
  34. /**
  35. * 生命周期函数--监听页面显示
  36. */
  37. onShow: function () {
  38. },
  39. /**
  40. * 生命周期函数--监听页面隐藏
  41. */
  42. onHide: function () {
  43. },
  44. /**
  45. * 生命周期函数--监听页面卸载
  46. */
  47. onUnload: function () {
  48. },
  49. /**
  50. * 页面相关事件处理函数--监听用户下拉动作
  51. */
  52. onPullDownRefresh: function () {
  53. if (this.data.hasNextPage) {
  54. let pn = this.data.pageNum
  55. this.setData({ loading: '加载中', 'pageNum': ++pn })
  56. this.queryList()
  57. }
  58. },
  59. /**
  60. * 页面上拉触底事件的处理函数
  61. */
  62. onReachBottom: function () {
  63. },
  64. /**
  65. * 用户点击右上角分享
  66. */
  67. onShareAppMessage: function () {
  68. },
  69. queryList: function () {
  70. const urls = urlDef.urls;
  71. let stu = wx.getStorageSync('student');
  72. if (stu) {
  73. let params = {'q.status':1}
  74. params.pageNum = this.data.pageNum
  75. util.apiPost(urls.get_piano_card_list, params).then(rs => {
  76. let list = rs.list
  77. list.map(o => {
  78. if (o.imgUrl == null || o.imgUrl == undefined) {
  79. o.imgUrl = urls.oss_file + 'image/0e02f9fc-1d41-4551-a150-b1be8196b49d.jpg'
  80. }
  81. })
  82. this.setData({
  83. 'hasNextPage': rs.hasNextPage,
  84. 'loading': rs.hasNextPage ? '下拉刷新' : '没有更多数据',
  85. 'list': this.data.list.concat(list)
  86. })
  87. })
  88. }
  89. }
  90. })