index.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. var app = getApp();
  2. var util = require('../../utils/util.js');
  3. var status = require('../../utils/index.js');
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. roomInfo: [],
  10. loadText: "加载中...",
  11. noData: false,
  12. loadMore: true,
  13. live_status_tip: {
  14. 101: '直播中',
  15. 102: '未开始',
  16. 103: '已结束',
  17. 104: '禁播',
  18. 105: '暂停中',
  19. 106: '异常',
  20. 107: '已过期'
  21. }
  22. },
  23. page: 1,
  24. /**
  25. * 生命周期函数--监听页面加载
  26. */
  27. onLoad: function (options) {
  28. app.setShareConfig();
  29. status.setNavBgColor();
  30. this.getData();
  31. },
  32. /**
  33. * 生命周期函数--监听页面显示
  34. */
  35. onShow: function () {
  36. let that = this;
  37. util.check_login_new().then((res) => {
  38. if (!res) {
  39. that.setData({
  40. needAuth: true
  41. })
  42. } else {
  43. (0, status.cartNum)('', true).then((res) => {
  44. that.setData({
  45. cartNum: res.data
  46. })
  47. });
  48. }
  49. })
  50. },
  51. getData: function(){
  52. let that = this;
  53. wx.showLoading();
  54. app.util.request({
  55. 'url': 'entry/wxapp/user',
  56. 'data': {
  57. controller: 'livevideo.get_roominfo',
  58. page: this.page
  59. },
  60. dataType: 'json',
  61. success: function(res) {
  62. wx.hideLoading();
  63. if (res.data.code == 0) {
  64. let list = res.data.data || [];
  65. let h = {};
  66. h.share = res.data.share;
  67. if(h.share && h.share.name) wx.setNavigationBarTitle({ title: h.share.name })
  68. h.showTabbar = res.data.showTabbar;
  69. if(list.length<5) h.noMore = true, h.loadMore = false;
  70. let roomInfo = that.data.roomInfo;
  71. roomInfo = roomInfo.concat(list);
  72. h.roomInfo = roomInfo;
  73. that.page++;
  74. that.setData(h);
  75. } else {
  76. let h = {};
  77. if(that.page==1) h.noData = true;
  78. h.showTabbar = res.data.showTabbar;
  79. h.loadMore = false;
  80. that.setData(h);
  81. }
  82. }
  83. })
  84. },
  85. goLive: function(e){
  86. let roomid = e.currentTarget.dataset.roomid;
  87. // let idx = e.currentTarget.dataset.idx;
  88. // let roomInfo = this.data.roomInfo;
  89. // if(idx>=0 && roomInfo && roomInfo[idx] && roomInfo[idx]['has_replay']) {
  90. // roomid && wx.navigateTo({
  91. // url: `/lionfish_comshop/moduleB/live/replay?room_id=${roomid}`,
  92. // })
  93. // return;
  94. // }
  95. roomid && wx.navigateTo({
  96. url: `plugin-private://wx2b03c6e691cd7370/pages/live-player-plugin?room_id=${roomid}`,
  97. })
  98. },
  99. /**
  100. * 页面上拉触底事件的处理函数
  101. */
  102. onReachBottom: function () {
  103. this.data.loadMore && this.getData();
  104. },
  105. /**
  106. * 用户点击右上角分享
  107. */
  108. onShareAppMessage: function () {
  109. let share = this.data.share || '';
  110. let title = share.title || '';
  111. let imageUrl = share.img || '';
  112. let share_path = 'lionfish_comshop/moduleB/live/index';
  113. return {
  114. title,
  115. imageUrl,
  116. path: share_path,
  117. success: function (res) {
  118. // 转发成功
  119. },
  120. fail: function (res) {
  121. // 转发失败
  122. }
  123. }
  124. },
  125. onShareTimeline: function () {
  126. let share = this.data.share || '';
  127. let title = share.title || '';
  128. let imageUrl = share.img || '';
  129. return {
  130. title,
  131. imageUrl,
  132. success: function (res) {
  133. // 转发成功
  134. },
  135. fail: function (res) {
  136. // 转发失败
  137. }
  138. }
  139. }
  140. })