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.

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