list.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. const util = require('../../../utils/util.js');
  2. const app = getApp();
  3. Page({
  4. data: {
  5. id:"",
  6. list:{},
  7. imgPath: util.config.imgPath,
  8. isLoadMore: true,
  9. pageIndex: 1,
  10. pageSize: 10
  11. },
  12. onLoad: function (options) {
  13. if(options.roomid) {
  14. // wx.navigateTo({
  15. // url: `plugin-private://wx2b03c6e691cd7370/pages/live-player-plugin?room_id=${options.roomid}`
  16. // })
  17. }
  18. this.getList(false);
  19. },
  20. getList(load){
  21. let self = this;
  22. util.ajax({
  23. func: "v2/live/room/applet/live/list",
  24. data: {"pageIndex": self.data.pageIndex }
  25. }, function (res) {
  26. if (res.code == 0) {
  27. let isLoadMore = true;
  28. let newData = res.data ? res.data : [];
  29. let oldData = !load ? newData : [...self.data.list, ...newData];
  30. if (newData.length < self.data.pageSize || oldData.length > self.data.pageSize) {
  31. isLoadMore = false;
  32. }
  33. self.setData({ list: oldData, isLoadMore: isLoadMore });
  34. }else
  35. util.showTips(res.reason);
  36. });
  37. },
  38. onPullDownRefresh: function () {
  39. var self = this;
  40. wx.showNavigationBarLoading();
  41. setTimeout(function () {
  42. self.getList(false);
  43. wx.hideNavigationBarLoading();
  44. wx.stopPullDownRefresh();
  45. }, 1500);
  46. },
  47. onReachBottom: function () {
  48. var self = this;
  49. if (self.data.isLoadMore == false) {
  50. return false;
  51. }
  52. setTimeout(function () {
  53. self.setData({ pageIndex: self.data.pageIndex + 1 });
  54. self.getList(true);
  55. }, 1000);
  56. },
  57. onShareAppMessage(e) {
  58. if (e.from == "button") {
  59. return {
  60. title: `好友邀请您一起参与《${e.target.dataset.title}》`,
  61. path: '/pages/public/live/list?roomid='+e.target.dataset.roomid,
  62. imageUrl:e.target.dataset.img
  63. }
  64. } else {
  65. return {
  66. title: '好友邀请您一起参与直播',
  67. path: '/pages/public/live/list'
  68. }
  69. }
  70. }
  71. })