share.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. var util = require('../../utils/util.js');
  2. var app = getApp();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. poster: '',
  9. imageSize: {
  10. imageWidth: "100%",
  11. imageHeight: 600
  12. },
  13. is_share_html: true,
  14. member_info: {}
  15. },
  16. /**
  17. * 生命周期函数--监听页面加载
  18. */
  19. onLoad: function (options) {
  20. let that = this;
  21. wx.setNavigationBarTitle({
  22. title: '我的二维码'
  23. })
  24. util.check_login_new().then((res) => {
  25. if (!res) {
  26. wx.showModal({
  27. title: '提示',
  28. content: '您还未登录',
  29. showCancel: false,
  30. success(res) {
  31. if (res.confirm) {
  32. wx.switchTab({
  33. url: '/lionfish_comshop/pages/user/me',
  34. })
  35. }
  36. }
  37. })
  38. } else {
  39. that.getMemberInfo();
  40. that.getData();
  41. }
  42. })
  43. },
  44. /**
  45. * 授权成功回调
  46. */
  47. authSuccess: function () {
  48. let that = this;
  49. this.setData({
  50. needAuth: false
  51. }, () => {
  52. that.getMemberInfo();
  53. that.getData();
  54. })
  55. },
  56. /**
  57. * 图片信息
  58. */
  59. imageLoad: function (e) {
  60. var imageSize = util.imageUtil(e)
  61. this.setData({
  62. imageSize
  63. })
  64. },
  65. getMemberInfo: function () {
  66. var token = wx.getStorageSync('token');
  67. let that = this;
  68. app.util.request({
  69. 'url': 'entry/wxapp/user',
  70. 'data': {
  71. controller: 'user.get_user_info',
  72. token: token
  73. },
  74. dataType: 'json',
  75. success: function (res) {
  76. if (res.data.code == 0) {
  77. let member_info = res.data.data;
  78. //开启分销
  79. if (res.data.commiss_level > 0) {
  80. //还差多少人升级
  81. let commiss_share_member_update = res.data.commiss_share_member_update * 1;
  82. let share_member_count = res.data.share_member_count * 1;
  83. let need_num_update = res.data.commiss_share_member_update * 1 - res.data.share_member_count * 1;
  84. let commiss_diy_name = res.data.commiss_diy_name || '分销';
  85. // wx.setNavigationBarTitle({
  86. // title: '会员' + commiss_diy_name,
  87. // })
  88. that.setData({
  89. member_info,
  90. commiss_level: res.data.commiss_level,
  91. commiss_sharemember_need: res.data.commiss_sharemember_need,
  92. commiss_share_member_update,
  93. share_member_count,
  94. need_num_update,
  95. commiss_diy_name
  96. });
  97. } else {
  98. wx.showModal({
  99. title: '提示',
  100. content: '未开启分销',
  101. showCancel: false,
  102. success(res) {
  103. if (res.confirm) {
  104. console.log('用户点击确定')
  105. wx.reLaunch({
  106. url: '/lionfish_comshop/pages/user/me',
  107. })
  108. }
  109. }
  110. })
  111. }
  112. } else {
  113. //is_login
  114. that.setData({
  115. is_login: false
  116. })
  117. wx.setStorage({
  118. key: "member_id",
  119. data: null
  120. })
  121. }
  122. }
  123. })
  124. },
  125. /**
  126. * 生命周期函数--监听页面显示
  127. */
  128. onShow: function () {
  129. },
  130. getData: function(){
  131. wx.showLoading();
  132. var token = wx.getStorageSync('token');
  133. let that = this;
  134. app.util.request({
  135. url: 'entry/wxapp/user',
  136. data: {
  137. controller: 'distribution.get_haibao',
  138. token: token
  139. },
  140. dataType: 'json',
  141. success: function (res) {
  142. wx.hideLoading();
  143. if (res.data.code == 0) {
  144. that.setData({ poster: res.data.commiss_qrcode })
  145. } else {
  146. that.setData({
  147. needAuth: true
  148. })
  149. }
  150. }
  151. })
  152. },
  153. toggleShare: function(){
  154. let is_share_html = this.data.is_share_html;
  155. this.setData({ is_share_html: !is_share_html })
  156. },
  157. prevImg: function(e){
  158. let image_path = e.currentTarget.dataset.src;
  159. wx.previewImage({
  160. current: image_path, // 当前显示图片的http链接
  161. urls: [image_path] // 需要预览的图片http链接列表
  162. })
  163. },
  164. /**
  165. * 用户点击右上角分享
  166. */
  167. onShareAppMessage: function () {
  168. this.setData({ is_share_html: true })
  169. var community = wx.getStorageSync('community');
  170. var community_id = community.communityId;
  171. var member_id = wx.getStorageSync('member_id');
  172. console.log(community_id, member_id);
  173. return {
  174. title: '',
  175. path: "lionfish_comshop/pages/index/index?community_id=" + community_id + '&share_id=' + member_id,
  176. imageUrl: '',
  177. success: function () { },
  178. fail: function () { }
  179. };
  180. }
  181. })