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.

147 lines
4.1 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/login/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. }
  73. }
  74. });
  75. },
  76. /**
  77. * 用户登录
  78. */
  79. userLogin: function(couponChannelId, couponId, orderId) {
  80. var that = this;
  81. // 登录
  82. wx.login({
  83. success: ({
  84. code
  85. }) => {
  86. wx.getSystemInfo({
  87. success: function(res) {
  88. that.setData({
  89. systemInfo: JSON.stringify(res)
  90. })
  91. }
  92. })
  93. var usrdata = {
  94. appId: config.weapp.AppId,
  95. code: code,
  96. sceneAddress: app.globalData.sceneAddress,
  97. scene: that.data.scene,
  98. systemInfo: that.data.systemInfo
  99. };
  100. if (app.globalData.locationInfo) {
  101. usrdata = {
  102. appId: config.weapp.AppId,
  103. code: code,
  104. sceneAddress: app.globalData.sceneAddress,
  105. latitude: "" + app.globalData.locationInfo.latitude,
  106. longitude: "" + app.globalData.locationInfo.longitude,
  107. scene: that.data.scene,
  108. systemInfo: that.data.systemInfo
  109. };
  110. }
  111. Http.post({
  112. url: config.api.login,
  113. data: usrdata
  114. })
  115. .then(res => {
  116. that.setData({
  117. showPages: true
  118. })
  119. app.globalData.token = res.data.token;
  120. Http.setToken(res.data.token);
  121. if (couponChannelId&&couponId || orderId){
  122. that.checkuerstatus(couponChannelId, couponId, orderId);
  123. }else{
  124. that.checkuerstatus();
  125. }
  126. })
  127. .catch(err => {
  128. wx.showModal({
  129. title: '提示',
  130. showCancel: false,
  131. content: '登录失败,请重新尝试',
  132. success:function(res){
  133. if (res.cancel) {
  134. //点击取消,默认隐藏弹框
  135. } else {
  136. //点击确定
  137. wx.reLaunch({
  138. url: '/pages/index/index',
  139. })
  140. }
  141. }
  142. })
  143. });
  144. }
  145. });
  146. },
  147. })