C端小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

151 lines
4.2 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. let that = this;
  17. wx.showToast({
  18. title: '加载中',
  19. icon: "loading",
  20. duration: 2000
  21. })
  22. wx.setStorageSync('options', JSON.stringify(options))
  23. wx.setStorageSync('imgurl', imgurl)
  24. if (decodeURIComponent(options.scene) == "undefined") {
  25. that.setData({
  26. scene: 0
  27. });
  28. } else {
  29. that.setData({
  30. scene: decodeURIComponent(options.scene)
  31. });
  32. }
  33. app.getLocation();
  34. if (options.couponChannelId && options.couponId || options.orderId) {
  35. that.userLogin(options.couponChannelId, options.couponId, options.orderId);
  36. } else {
  37. that.userLogin()
  38. }
  39. },
  40. checkuerstatus(couponChannelId, couponId, orderId) {
  41. let that = this;
  42. Http.post({
  43. url: config.api.checkUserStatus,
  44. data: {}
  45. })
  46. .then(res => {
  47. if (couponChannelId && couponId) {
  48. wx.redirectTo({
  49. url: `/pages/coupon/detail/index?couponChannelId=${couponChannelId}&couponId=${couponId}`,
  50. })
  51. } else if (orderId) {
  52. wx.redirectTo({
  53. url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${orderId}&from='${"discount"}`,
  54. })
  55. }else{
  56. wx.switchTab({
  57. url: '/pages/main/index'
  58. });
  59. }
  60. })
  61. .catch(err => {
  62. if (err.code == 11004) {
  63. // 用户昵称未授权
  64. if (couponChannelId && couponId) {
  65. wx.redirectTo({
  66. url: `/pages/getuserinfo/index?couponChannelId=${couponChannelId}&couponId=${couponId}`
  67. });
  68. } else if (orderId) {
  69. wx.redirectTo({
  70. url: `/pages/getuserinfo/index?orderId=${orderId}&from='${"discount"}`
  71. });
  72. } else {
  73. wx.redirectTo({
  74. url: `/pages/getuserinfo/index`
  75. });
  76. }
  77. }
  78. });
  79. },
  80. /**
  81. * 用户登录
  82. */
  83. userLogin: function(couponChannelId, couponId, orderId) {
  84. var that = this;
  85. // 登录
  86. wx.login({
  87. success: ({
  88. code
  89. }) => {
  90. wx.getSystemInfo({
  91. success: function(res) {
  92. that.setData({
  93. systemInfo: JSON.stringify(res)
  94. })
  95. }
  96. })
  97. var usrdata = {
  98. appId: config.weapp.AppId,
  99. code: code,
  100. sceneAddress: app.globalData.sceneAddress,
  101. scene: that.data.scene,
  102. systemInfo: that.data.systemInfo
  103. };
  104. if (app.globalData.locationInfo) {
  105. usrdata = {
  106. appId: config.weapp.AppId,
  107. code: code,
  108. sceneAddress: app.globalData.sceneAddress,
  109. latitude: "" + app.globalData.locationInfo.latitude,
  110. longitude: "" + app.globalData.locationInfo.longitude,
  111. scene: that.data.scene,
  112. systemInfo: that.data.systemInfo
  113. };
  114. }
  115. Http.post({
  116. url: config.api.login,
  117. data: usrdata
  118. })
  119. .then(res => {
  120. that.setData({
  121. showPages: true
  122. })
  123. app.globalData.token = res.data.token;
  124. Http.setToken(res.data.token);
  125. if (couponChannelId&&couponId || orderId){
  126. that.checkuerstatus(couponChannelId, couponId, orderId);
  127. }else{
  128. that.checkuerstatus();
  129. }
  130. })
  131. .catch(err => {
  132. wx.showModal({
  133. title: '提示',
  134. showCancel: false,
  135. content: '登录失败,请重新尝试',
  136. success:function(res){
  137. if (res.cancel) {
  138. //点击取消,默认隐藏弹框
  139. } else {
  140. //点击确定
  141. wx.reLaunch({
  142. url: '/pages/index/index',
  143. })
  144. }
  145. }
  146. })
  147. });
  148. }
  149. });
  150. },
  151. })