partnerShare.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. // pages/partnerShare/partnerShare.js
  2. var that;
  3. var Util = require('../../utils/util.js');
  4. var app = getApp();
  5. Page({
  6. data: {
  7. urlHttp: '',
  8. hiddenmodal: true, //提示弹窗
  9. userPhoto: '', //用户头像
  10. userName: '', //用户昵称
  11. fromUserId: '', //分享人的un_id
  12. fromUserPhoto : '',
  13. fromUserName : '',
  14. fromUserRole : '',
  15. userRole :0, //用户身份【默认普通用户】
  16. un_id : '', //当前用户un_id
  17. },
  18. onLoad: function (options) {
  19. var that = this;
  20. var host = getApp().globalData.servsers;
  21. var un_id = getApp().globalData.un_id;
  22. var openid = getApp().globalData.openid;
  23. var fromUserId = options.fromUserId;//分享人的un_id
  24. var fromUserPhoto = options.fromUserPhoto;
  25. var fromUserName = options.fromUserName;
  26. var fromUserRole = options.fromUserRole;
  27. that.setData({
  28. urlHttp: host,
  29. fromUserId: fromUserId,
  30. fromUserPhoto: fromUserPhoto,
  31. fromUserName: fromUserName,
  32. fromUserRole: fromUserRole
  33. })
  34. },
  35. //返回首页
  36. backIndex: function (e) {
  37. wx.switchTab({
  38. url: '/pages/index/index',
  39. })
  40. },
  41. //立即加入
  42. addPartner:function(e){
  43. var that = this;
  44. var host = getApp().globalData.servsers;
  45. var un_id = getApp().globalData.un_id;
  46. var openid = getApp().globalData.openid;
  47. var isNewUser = getApp().globalData.isNewUser; //新用户标识
  48. var fromUserId = that.data.fromUserId;//分享人的un_id
  49. var userRole = that.data.fromUserRole;//分享人的角色
  50. console.log("shae1-un_id:" + un_id);
  51. console.log("shae1-openid:" + openid);
  52. console.log("shae1-isNewUser:" + isNewUser);
  53. console.log("shae1-userRole:" + userRole);
  54. if ((un_id == undefined || un_id == '' || un_id == null) || (openid == undefined || openid == '' || openid == null)){//最原始用户【模板消息前的用户】
  55. wx.navigateTo({
  56. url: '/pages/authorize/authorize?link=partnerShare',
  57. })
  58. } else if (isNewUser == true){
  59. //创建分销关系-当被分享用户通过分享进入客户端时进行关系确立
  60. wx.request({
  61. url: host + "api/distributeSell/createRelation",
  62. data: {
  63. shareUserId: fromUserId,//分享用户userId
  64. currentUserId: un_id,//当前操作用户userId
  65. userRole: userRole,//分销人 - 用户角色 0:普通用户 1:商务用户
  66. },
  67. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  68. header: {
  69. 'Accept': 'application/json'
  70. },
  71. success: function (res) {
  72. if (res.data.code == '200') {
  73. // 转发成功
  74. that.setData({
  75. hiddenmodal: false,
  76. modalCont: '加入成功'
  77. })
  78. setTimeout(function () {
  79. that.setData({
  80. hiddenmodal: true
  81. })
  82. wx.navigateTo({
  83. url: '/pages/midAutumn/midAutumn',
  84. })
  85. }, 800)
  86. } else {//请求失败
  87. that.setData({
  88. hiddenmodal: false,
  89. modalCont: '网络异常,请重新操作!'
  90. })
  91. setTimeout(function () {
  92. that.setData({
  93. hiddenmodal: true
  94. })
  95. }, 800)
  96. }
  97. if (res == null) {
  98. that.setData({
  99. hiddenmodal: false,
  100. modalCont: '网络异常,请重新操作!'
  101. })
  102. setTimeout(function () {
  103. that.setData({
  104. hiddenmodal: true
  105. })
  106. }, 800)
  107. return;
  108. }
  109. }
  110. })
  111. }else{
  112. that.setData({
  113. hiddenmodal: false,
  114. modalCont: '仅限新用户,快去分享好友开始赚钱吧!'
  115. })
  116. setTimeout(function () {
  117. that.setData({
  118. hiddenmodal: true
  119. })
  120. wx.navigateTo({
  121. url: '/pages/midAutumn/midAutumn',
  122. })
  123. }, 800)
  124. return false;
  125. }
  126. },
  127. onHide: function () {
  128. var that = this;
  129. that.setData({
  130. fromUserId: '',
  131. fromUserPhoto: '',
  132. fromUserName: '',
  133. fromUserRole: ''
  134. })
  135. },
  136. //页面卸载[完全关闭]
  137. onUnload: function () {
  138. var that = this;
  139. that.setData({
  140. fromUserId: '',
  141. fromUserPhoto: '',
  142. fromUserName: '',
  143. fromUserRole: ''
  144. })
  145. },
  146. })