C端小程序
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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