C端小程序
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

154 líneas
3.4 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. console.log(options);
  23. console.log("----------------------------------options---------------------------------------")
  24. wx.setStorageSync('options', JSON.stringify(options))
  25. wx.setStorageSync('imgurl', imgurl)
  26. if (decodeURIComponent(options.scene) == "undefined") {
  27. that.setData({
  28. scene: 0
  29. });
  30. } else {
  31. that.setData({
  32. scene: decodeURIComponent(options.scene)
  33. });
  34. }
  35. app.getLocation();
  36. if (options.couponChannelId && options.couponId || options.orderId) {
  37. that.userLogin(options.couponChannelId, options.couponId, options.orderId);
  38. } else {
  39. that.userLogin()
  40. }
  41. },
  42. /**
  43. * 用户登录
  44. */
  45. userLogin: function(couponChannelId, couponId, orderId) {
  46. var that = this;
  47. // 登录
  48. wx.login({
  49. success: ({
  50. code
  51. }) => {
  52. wx.getSystemInfo({
  53. success: function(res) {
  54. that.setData({
  55. systemInfo: JSON.stringify(res)
  56. })
  57. }
  58. })
  59. var usrdata = {
  60. appId: config.weapp.AppId,
  61. code: code,
  62. sceneAddress: app.globalData.sceneAddress,
  63. scene: that.data.scene,
  64. systemInfo: that.data.systemInfo
  65. };
  66. if (app.globalData.locationInfo) {
  67. usrdata = {
  68. appId: config.weapp.AppId,
  69. code: code,
  70. sceneAddress: app.globalData.sceneAddress,
  71. latitude: "" + app.globalData.locationInfo.latitude,
  72. longitude: "" + app.globalData.locationInfo.longitude,
  73. scene: that.data.scene,
  74. systemInfo: that.data.systemInfo
  75. };
  76. }
  77. Http.post({
  78. url: config.api.login,
  79. data: usrdata
  80. })
  81. .then(res => {
  82. that.setData({
  83. showPages: true
  84. })
  85. app.globalData.token = res.data.token;
  86. Http.setToken(res.data.token);
  87. if(orderId){
  88. wx.redirectTo({
  89. url: '/pages/bargain/bargainDatail/bargainDatail?orderId='+orderId,
  90. })
  91. }else{
  92. wx.switchTab({
  93. url: '/pages/login/index',
  94. })
  95. }
  96. })
  97. .catch(err => {
  98. wx.showToast({
  99. title: err.message,
  100. icon: "none"
  101. })
  102. });
  103. }
  104. });
  105. },
  106. /**
  107. * 生命周期函数--监听页面初次渲染完成
  108. */
  109. onReady: function() {
  110. },
  111. /**
  112. * 生命周期函数--监听页面显示
  113. */
  114. onShow: function() {
  115. },
  116. /**
  117. * 生命周期函数--监听页面隐藏
  118. */
  119. onHide: function() {
  120. },
  121. /**
  122. * 生命周期函数--监听页面卸载
  123. */
  124. onUnload: function() {
  125. },
  126. /**
  127. * 页面相关事件处理函数--监听用户下拉动作
  128. */
  129. onPullDownRefresh: function() {
  130. },
  131. /**
  132. * 页面上拉触底事件的处理函数
  133. */
  134. onReachBottom: function() {
  135. },
  136. /**
  137. * 用户点击右上角分享
  138. */
  139. onShareAppMessage: function() {
  140. }
  141. })