index.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. rushList: [],
  10. loadText: "加载中...",
  11. noData: 0,
  12. loadMore: true,
  13. shareInfo: ''
  14. },
  15. pageNum: 1,
  16. /**
  17. * 生命周期函数--监听页面加载
  18. */
  19. onLoad: function(options) {
  20. app.setShareConfig();
  21. status.setNavBgColor();
  22. this.getData();
  23. this.getInfo();
  24. },
  25. /**
  26. * 生命周期函数--监听页面显示
  27. */
  28. onShow: function() {
  29. const that = this;
  30. util.check_login_new().then((res) => {
  31. let needAuth = !res;
  32. that.setData({ needAuth })
  33. if (res) {
  34. (0, status.cartNum)('', true).then((res) => {
  35. res.code == 0 && that.setData({
  36. cartNum: res.data
  37. })
  38. });
  39. }
  40. })
  41. },
  42. getInfo: function() {
  43. let that = this;
  44. app.util.request({
  45. url: 'entry/wxapp/index',
  46. data: {
  47. controller: 'goods.get_video_list_share'
  48. },
  49. dataType: 'json',
  50. success: function(res) {
  51. if (res.data.code == 0) {
  52. wx.setNavigationBarTitle({
  53. title: res.data.data.nav_title || '详情',
  54. })
  55. that.setData({ shareInfo: res.data.data })
  56. }
  57. }
  58. })
  59. },
  60. /**
  61. * 获取商品列表
  62. */
  63. getData: function() {
  64. var token = wx.getStorageSync('token');
  65. var that = this;
  66. var cur_community = wx.getStorageSync('community');
  67. wx.showLoading();
  68. app.util.request({
  69. url: 'entry/wxapp/index',
  70. data: {
  71. controller: 'index.load_gps_goodslist',
  72. token: token,
  73. pageNum: that.pageNum,
  74. head_id: cur_community.communityId,
  75. per_page: 12,
  76. is_video: 1
  77. },
  78. dataType: 'json',
  79. success: function(res) {
  80. if (res.data.code == 0) {
  81. let rushList = '';
  82. let h = {};
  83. let rdata = res.data;
  84. if (rdata.list.length < 12) h.noMore = true;
  85. let oldRushList = that.data.rushList;
  86. rushList = oldRushList.concat(rdata.list);
  87. that.pageNum++;
  88. that.setData({
  89. rushList: rushList,
  90. tip: '',
  91. ...h
  92. });
  93. } else if (res.data.code == 1) {
  94. if (that.pageNum == 1) that.setData({ noData: 1 })
  95. that.setData({ loadMore: false, noMore: false, loadText: "没有更多记录了~" })
  96. } else if (res.data.code == 2) {
  97. //no login
  98. that.setData({
  99. needAuth: true
  100. })
  101. }
  102. },
  103. complete: function() {
  104. wx.hideLoading();
  105. }
  106. })
  107. },
  108. /**
  109. * 页面上拉触底事件的处理函数
  110. */
  111. onReachBottom: function() {
  112. if (!this.data.loadMore) return false;
  113. this.getData();
  114. },
  115. /**
  116. * 用户点击右上角分享
  117. */
  118. onShareAppMessage: function() {
  119. let shareInfo = this.data.shareInfo;
  120. let share_title = shareInfo.share_title || '视频';
  121. let shareImg = shareInfo.share_poster || '';
  122. var share_id = wx.getStorageSync('member_id');
  123. var share_path = `lionfish_comshop/moduleA/video/index?share_id=${share_id}`;
  124. return {
  125. title: share_title,
  126. path: share_path,
  127. imageUrl: shareImg,
  128. success: function (res) {
  129. // 转发成功
  130. },
  131. fail: function (res) {
  132. // 转发失败
  133. }
  134. }
  135. },
  136. onShareTimeline: function(res) {
  137. let shareInfo = this.data.shareInfo;
  138. let title = shareInfo.share_title || '视频';
  139. let imageUrl = shareInfo.share_poster || '';
  140. var share_id = wx.getStorageSync('member_id');
  141. var query= `share_id=${share_id}`;
  142. return {
  143. title,
  144. query,
  145. imageUrl,
  146. success: function() {},
  147. fail: function() {}
  148. };
  149. }
  150. })