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.

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