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.

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