C端小程序
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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