C端小程序
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

165 rindas
4.7 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. if (options.cuserId){
  36. /**
  37. * 转赠判断
  38. */
  39. that.userLogin(options.couponChannelId, options.couponId, null, options.cuserId, options.coverImg);
  40. }else{
  41. that.userLogin(options.couponChannelId, options.couponId, options.orderId);
  42. }
  43. } else {
  44. that.userLogin()
  45. }
  46. },
  47. checkuerstatus(couponChannelId, couponId, orderId, cuserId, coverImg) {
  48. let that = this;
  49. Http.post({
  50. url: config.api.checkUserStatus,
  51. data: {}
  52. })
  53. .then(res => {
  54. if (couponChannelId && couponId && !cuserId) {
  55. wx.redirectTo({
  56. url: `/pages/coupon/detail/index?couponChannelId=${couponChannelId}&couponId=${couponId}`,
  57. })
  58. } else if (couponChannelId && couponId && cuserId){
  59. /**
  60. * 转赠判断
  61. */
  62. wx.redirectTo({
  63. url: `/pages/coupon/detail/index?couponChannelId=${couponChannelId}&couponId=${couponId}&cuserId=${cuserId}&coverImg=${coverImg}`,
  64. })
  65. } else if (orderId) {
  66. wx.redirectTo({
  67. url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${orderId}&from='${"discount"}`,
  68. })
  69. }else{
  70. wx.switchTab({
  71. url: '/pages/login/index'
  72. });
  73. }
  74. })
  75. .catch(err => {
  76. if (err.code == 11004) {
  77. // 用户昵称未授权
  78. if (couponChannelId && couponId) {
  79. wx.redirectTo({
  80. url: `/pages/getuserinfo/index?couponChannelId=${couponChannelId}&couponId=${couponId}`
  81. });
  82. } else if (orderId) {
  83. wx.redirectTo({
  84. url: `/pages/getuserinfo/index?orderId=${orderId}&from='${"discount"}`
  85. });
  86. } else {
  87. wx.redirectTo({
  88. url: `/pages/getuserinfo/index`
  89. });
  90. }
  91. }
  92. });
  93. },
  94. /**
  95. * 用户登录
  96. */
  97. userLogin: function (couponChannelId, couponId, orderId, cuserId) {
  98. var that = this;
  99. // 登录
  100. wx.login({
  101. success: ({
  102. code
  103. }) => {
  104. wx.getSystemInfo({
  105. success: function(res) {
  106. that.setData({
  107. systemInfo: JSON.stringify(res)
  108. })
  109. }
  110. })
  111. var usrdata = {
  112. appId: config.weapp.AppId,
  113. code: code,
  114. sceneAddress: app.globalData.sceneAddress,
  115. scene: that.data.scene,
  116. systemInfo: that.data.systemInfo
  117. };
  118. if (app.globalData.locationInfo) {
  119. usrdata = {
  120. appId: config.weapp.AppId,
  121. code: code,
  122. sceneAddress: app.globalData.sceneAddress,
  123. latitude: "" + app.globalData.locationInfo.latitude,
  124. longitude: "" + app.globalData.locationInfo.longitude,
  125. scene: that.data.scene,
  126. systemInfo: that.data.systemInfo
  127. };
  128. }
  129. Http.post({
  130. url: config.api.login,
  131. data: usrdata
  132. })
  133. .then(res => {
  134. that.setData({
  135. showPages: true
  136. })
  137. app.globalData.token = res.data.token;
  138. Http.setToken(res.data.token);
  139. if (couponChannelId&&couponId || orderId){
  140. that.checkuerstatus(couponChannelId, couponId, orderId, cuserId, coverImg);
  141. }else{
  142. that.checkuerstatus();
  143. }
  144. })
  145. .catch(err => {
  146. wx.showModal({
  147. title: '提示',
  148. showCancel: false,
  149. content: '登录失败,请重新尝试',
  150. success:function(res){
  151. if (res.cancel) {
  152. //点击取消,默认隐藏弹框
  153. } else {
  154. //点击确定
  155. wx.reLaunch({
  156. url: '/pages/index/index',
  157. })
  158. }
  159. }
  160. })
  161. });
  162. }
  163. });
  164. },
  165. })