C端小程序
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

173 行
5.4 KiB

  1. const Http = require("../../utils/HttpBasics");
  2. const imgurl = require("../../utils/imgurl");
  3. const config = require("../../config/config");
  4. const QR = require("../../utils/memberqrcode.js");
  5. let app = getApp();
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. },
  12. /**
  13. * 生命周期函数--监听页面加载
  14. */
  15. onLoad: function(options) {
  16. console.log(options)
  17. let that = this;
  18. wx.showToast({
  19. title: '加载中',
  20. icon: "loading",
  21. duration: 2000
  22. })
  23. wx.setStorageSync('options', JSON.stringify(options))
  24. wx.setStorageSync('imgurl', imgurl)
  25. if (decodeURIComponent(options.scene) == "undefined") {
  26. that.setData({
  27. scene: 0
  28. });
  29. } else {
  30. that.setData({
  31. scene: decodeURIComponent(options.scene)
  32. });
  33. }
  34. app.getLocation();
  35. if (options.couponChannelId && options.couponId || options.orderId) {
  36. if (options.cuserId){
  37. /**
  38. * 转赠判断
  39. */
  40. that.userLogin(options.couponChannelId, options.couponId, null, options.cuserId, options.coverImg, options.userName, options.avatarUrl, options.couponOrderId);
  41. }else{
  42. that.userLogin(options.couponChannelId, options.couponId, options.orderId);
  43. }
  44. } else {
  45. that.userLogin()
  46. }
  47. },
  48. checkuerstatus(couponChannelId, couponId, orderId, cuserId, coverImg, userName, avatarUrl, couponOrderId) {
  49. let that = this;
  50. Http.post({
  51. url: config.api.checkUserStatus,
  52. data: {}
  53. })
  54. .then(res => {
  55. if (couponChannelId && couponId && !cuserId) {
  56. wx.redirectTo({
  57. url: `/pages/coupon/detail/index?couponChannelId=${couponChannelId}&couponId=${couponId}`,
  58. })
  59. } else if (couponChannelId && couponId && cuserId){
  60. /**
  61. * 转赠判断
  62. */
  63. wx.redirectTo({
  64. url: `/pages/coupon/detail/index?couponChannelId=${couponChannelId}&couponId=${couponId}&cuserId=${cuserId}&coverImg=${coverImg}&userName=${userName}&avatarUrl=${avatarUrl}&couponOrderId=${couponOrderId}`,
  65. })
  66. } else if (orderId) {
  67. wx.redirectTo({
  68. url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${orderId}&from='${"discount"}`,
  69. })
  70. }else{
  71. wx.switchTab({
  72. url: '/pages/login/index'
  73. });
  74. }
  75. })
  76. .catch(err => {
  77. if (err.code == 11004) {
  78. // 用户昵称未授权
  79. if (couponChannelId && couponId && !cuserId) {
  80. wx.redirectTo({
  81. url: `/pages/getuserinfo/index?couponChannelId=${couponChannelId}&couponId=${couponId}`
  82. });
  83. } else if (couponChannelId && couponId && cuserId){
  84. /**
  85. * 转赠判断
  86. */
  87. wx.redirectTo({
  88. url: `/pages/getuserinfo/index?couponChannelId=${couponChannelId}&couponId=${couponId}&cuserId=${cuserId}&coverImg=${coverImg}&userName=${userName}&avatarUrl=${avatarUrl}&couponOrderId=${couponOrderId}`
  89. });
  90. } else if (orderId) {
  91. wx.redirectTo({
  92. url: `/pages/getuserinfo/index?orderId=${orderId}&from='${"discount"}`
  93. });
  94. } else {
  95. wx.redirectTo({
  96. url: `/pages/getuserinfo/index`
  97. });
  98. }
  99. }
  100. });
  101. },
  102. /**
  103. * 用户登录
  104. */
  105. userLogin: function (couponChannelId, couponId, orderId, cuserId, coverImg, userName, avatarUrl, couponOrderId) {
  106. var that = this;
  107. // 登录
  108. wx.login({
  109. success: ({
  110. code
  111. }) => {
  112. wx.getSystemInfo({
  113. success: function(res) {
  114. that.setData({
  115. systemInfo: JSON.stringify(res)
  116. })
  117. }
  118. })
  119. var usrdata = {
  120. appId: config.weapp.AppId,
  121. code: code,
  122. sceneAddress: app.globalData.sceneAddress,
  123. scene: that.data.scene,
  124. systemInfo: that.data.systemInfo
  125. };
  126. if (app.globalData.locationInfo) {
  127. usrdata = {
  128. appId: config.weapp.AppId,
  129. code: code,
  130. sceneAddress: app.globalData.sceneAddress,
  131. latitude: "" + app.globalData.locationInfo.latitude,
  132. longitude: "" + app.globalData.locationInfo.longitude,
  133. scene: that.data.scene,
  134. systemInfo: that.data.systemInfo
  135. };
  136. }
  137. Http.post({
  138. url: config.api.login,
  139. data: usrdata
  140. })
  141. .then(res => {
  142. that.setData({
  143. showPages: true
  144. })
  145. app.globalData.token = res.data.token;
  146. Http.setToken(res.data.token);
  147. if (couponChannelId&&couponId || orderId){
  148. that.checkuerstatus(couponChannelId, couponId, orderId, cuserId, coverImg, userName, avatarUrl, couponOrderId);
  149. }else{
  150. that.checkuerstatus();
  151. }
  152. })
  153. .catch(err => {
  154. wx.showModal({
  155. title: '提示',
  156. showCancel: false,
  157. content: '登录失败,请重新尝试',
  158. success:function(res){
  159. if (res.cancel) {
  160. //点击取消,默认隐藏弹框
  161. } else {
  162. //点击确定
  163. wx.reLaunch({
  164. url: '/pages/index/index',
  165. })
  166. }
  167. }
  168. })
  169. });
  170. }
  171. });
  172. },
  173. })