index.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. const util = require('../../utils/util.js');
  2. const app = getApp();
  3. Page({
  4. data: {
  5. info:{
  6. sharerInfo:{}
  7. },
  8. sharerLevelInfo:{},
  9. shareStatus:0,
  10. showPopup:false,
  11. swipeList:[],
  12. organStatus:0
  13. },
  14. onLoad(options){
  15. console.log(options)
  16. if (options) {
  17. if (options.shareStatus) {
  18. this.userInfo()
  19. this.onShareAppMessage()
  20. this.setData({shareStatus:options.organStatus})
  21. }else{
  22. this.userInfo()
  23. this.onShareAppMessage()
  24. this.setData({organStatus:options.organStatus})
  25. }
  26. }
  27. },
  28. onShow: function () {
  29. this.userInfo()
  30. this.onShareAppMessage()
  31. },
  32. // 获取提现轮播
  33. getPriceSwipe(){
  34. let that=this;
  35. util.ajax({
  36. func:'v2/user/coin/message',
  37. data:{type:this.data.info.roleType=='sharer'?1:(this.data.info.roleType=='organ'?2:0)},
  38. load:false
  39. },function (res) {
  40. if (res.code==0) {
  41. if (res.data&&res.data.length>0) {
  42. that.setData({swipeList:res.data})
  43. }
  44. } else {
  45. util.showTips(res.reason);
  46. }
  47. })
  48. },
  49. //右上角分享功能
  50. onShareAppMessage: function (res) {
  51. var that = this;
  52. let flag=0
  53. let imgurl=""
  54. let path=""
  55. // 0代表普通用户 1代表是机构 2代表是分享家
  56. console.log(that.data.organStatus);
  57. if(that.data.organStatus){
  58. flag=1
  59. }else{
  60. flag=2
  61. }
  62. if(this.data.type=="organ"){
  63. imgurl="https://img.bbztx.com/image_test/upload/thumbs/20221024/logo/1666598262608021902.jpg"
  64. path=`pages/sharingHome/index?organStatus=${1}`
  65. }else if(this.data.type=="sharer"){
  66. imgurl="https://img.bbztx.com/image_test/upload/thumbs/20221024/logo/1666598584892027021.jpg"
  67. path=`pages/sharingHome/index?organStatus=${2}`
  68. }
  69. let flags=false
  70. return {
  71. title: `${that.data.organStatus?'机构提现中心':'分享家提现中心'}`,
  72. // path: path, //要跳转的路径
  73. path:`/pages/home/account?flags=`+flags,
  74. imageUrl:imgurl, //自定义图片路径
  75. success: function (res) {
  76. console.log(res);
  77. // 转发成功
  78. },
  79. fail: function (res) {
  80. // 转发失败
  81. }
  82. }
  83. },
  84. // 显示分享家停用弹窗
  85. showInstract(){
  86. this.setData({showPopup:true})
  87. },
  88. closePopup(){
  89. this.setData({showPopup:false})
  90. },
  91. userInfo(){
  92. let that = this;
  93. util.ajax({
  94. func: "v2/user/info",
  95. load: false
  96. }, function (res) {
  97. console.log(res);
  98. if (res.code == 0 && res.data) {
  99. that.setData({info:res.data})
  100. that.coinStat();
  101. if (res.data.roleType=='organ'||res.data.roleType=='sharer') {
  102. that.getPriceSwipe()
  103. }
  104. if (res.data.roleType=='sharer') {
  105. that.sharerLevelInfo()
  106. }
  107. // if(res.data.roleType=="normal"){
  108. // wx.navigateTo({
  109. // url: '/pages/public/swiper/web?url=https://mp.weixin.qq.com/s/H8WuXW_VeCeWtxQXFBGu2Q&title=宝贝走天下',
  110. // })
  111. // }
  112. // 普通用户进行跳转
  113. // if(res.data.roleType=="normal"){
  114. // }
  115. that.setData({
  116. type:res.data.roleType
  117. })
  118. that.inviteeStat(res.data.roleType);
  119. that.activityStat(res.data.roleType);
  120. }
  121. });
  122. },
  123. // 用户登录
  124. getUserProfile(){
  125. let that = this;
  126. this.setData({clickTimes:true})
  127. wx.login({
  128. success: res => {
  129. that.setData({code:res.code})
  130. }
  131. });
  132. that.userProfile();
  133. },
  134. userProfile(){
  135. let that=this;
  136. wx.getUserProfile({
  137. desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中
  138. success: (res) => {
  139. console.log(res);
  140. let it = {};
  141. if (!res.encryptedData && !res.iv) {
  142. it.version="applet_v1.0.0";
  143. it.code=that.data.code;
  144. it.target='challengerhome';
  145. it.avatarUrl=res.userInfo.avatarUrl;
  146. it.nickName=res.userInfo.nickName
  147. }else{
  148. it.version="applet_v1.0.0";
  149. it.code=that.data.code;
  150. it.target='challengerhome';
  151. it.encryptedData=res.encryptedData;
  152. it.iv=res.iv;
  153. }
  154. util.ajax({
  155. func: "applet_login",
  156. data: it
  157. }, function (data) {
  158. if (data.code == 0) {
  159. if (data.data.firstLogin == 1) {
  160. that.setData({ tempUser: data.data, firstLogin: 1 });
  161. } else {
  162. data.data.role = util.userRole(Math.round(data.data.score));
  163. app.globalData.userInfo = data.data;
  164. wx.setStorageSync("WXuserInfo", data.data);
  165. if (that.data.type == "share") {
  166. wx.reLaunch({
  167. url: '/pages/home/index',
  168. });
  169. } else {
  170. wx.navigateBack();
  171. }
  172. }
  173. } else{util.showTips(data.reason);}
  174. that.setData({clickTimes:false})
  175. });
  176. }
  177. });
  178. },
  179. // 获取佣金
  180. coinStat(){
  181. let that = this;
  182. util.ajax({
  183. func: "v2/user/coin/stat",
  184. data:{type:0},
  185. load: false
  186. }, function (res) {
  187. if (res.code == 0 && res.data) {
  188. that.setData({coin: res.data})
  189. }
  190. });
  191. },
  192. // 直接会员、直接分享家、间接会员
  193. inviteeStat(roleType){
  194. let that = this;
  195. util.ajax({
  196. func: `v2/${roleType}/invitee/stat`,
  197. load: false
  198. }, function (res) {
  199. if (res.code == 0 && res.data) {
  200. that.setData({invitee: res.data})
  201. }
  202. });
  203. },
  204. // 获取分享家等级信息
  205. sharerLevelInfo(){
  206. let that = this;
  207. util.ajax({
  208. func: "v2/user/coin/sharerLevel",
  209. data:{levelMax:that.data.info.sharerInfo.levelMax},
  210. load: false
  211. }, function (res) {
  212. console.log(res);
  213. if (res.code == 0) {
  214. let data=res.data;
  215. if (that.data.info.sharerInfo.levelMax<5) {
  216. data.percent1=(data.level_exp1/data.levelPlan1)*100==100?'calc(100% - 14rpx)':(data.level_exp1/data.levelPlan1)*100 +'%';
  217. data.percent2=(data.level_exp2/data.levelPlan2)*100==100?'calc(100% - 14rpx)':(data.level_exp2/data.levelPlan2)*100 +'%';
  218. } else {
  219. data.percent1=0;
  220. data.percent2=0;
  221. }
  222. data.scaleCurrent=(data.scaleCurrent*100).toFixed()
  223. data.scaleNext=(data.scaleNext*100).toFixed()
  224. that.setData({sharerLevelInfo:data})
  225. }
  226. });
  227. },
  228. // 分销产品
  229. activityStat(roleType){
  230. let that = this;
  231. util.ajax({
  232. func: `v2/${roleType}/product/stat`,
  233. load: false
  234. }, function (res) {
  235. if (res.code == 0 && res.data) {
  236. that.setData({product: res.data})
  237. }
  238. });
  239. },
  240. // 跳转规则说明页
  241. jumptoIns(e){
  242. let url1='https://mp.weixin.qq.com/s?__biz=MzkzNjE5NTU3Nw==&mid=2247490779&idx=1&sn=0a3ae0e62986c5e21f62892df8058a0e&chksm=c2a3384df5d4b15b3ddce0bea8d877fb04c4e94dc0f1721e2b311943cf0137b3c781dc980bbd&token=458771444&lang=zh_CN#rd',
  243. url2="https://mp.weixin.qq.com/s?__biz=MzkzNjE5NTU3Nw==&mid=2247490766&idx=1&sn=cca6ce9fd52dd9182d37831a551bac67&chksm=c2a33858f5d4b14ea52efb062b4dbab17adbc29307f67e74792d44d1d7369b43bb30e6a5829d#rd",
  244. type=e.currentTarget.dataset.type;
  245. wx.navigateTo({
  246. url: '/pages/public/swiper/web?url='+encodeURIComponent(this.data.info.roleType=='sharer'?url1:url2)+'&title='+(this.data.info.roleType=='sharer'?(type==0?'分享家规则说明':'分享家晋级说明'):'机构规则说明'),
  247. })
  248. },
  249. navigatorURl(e){
  250. util.navigator(e.currentTarget.dataset.url);
  251. },
  252. })