index.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // pages/public/cashCoupon/index.js
  2. const util = require('../../../utils/util.js');
  3. const app = getApp();
  4. Page({
  5. data: {
  6. getSuccess: -1,
  7. getImgUrl: '',
  8. channelId: '',
  9. failContent: ''
  10. },
  11. onLoad(options) {
  12. },
  13. onShow() {
  14. let pages = getCurrentPages();
  15. let currentPages = pages[pages.length - 1];
  16. let options = currentPages.options;
  17. console.log(options)
  18. if (app.globalData.userInfo) {
  19. // 微信分享链接进入
  20. if (!util.isEmpty(options.channel)) {
  21. this.setData({ channelId: options.channel })
  22. }
  23. // 小程序码进入 eg:channel%3D14
  24. if (!util.isEmpty(options.scene)) {
  25. let scene = decodeURIComponent(options.scene).split('=');
  26. if (scene[0] == 'channel') {
  27. this.setData({ channelId: scene[1] })
  28. }
  29. }
  30. this.getVoucher()
  31. } else {
  32. // 静默登录
  33. let that = this
  34. util.silentLogin().then(res => {
  35. // 微信分享链接进入
  36. if (!util.isEmpty(options.channel)) {
  37. that.setData({ channelId: options.channel })
  38. }
  39. // 小程序码进入 eg:channel%3D14
  40. if (!util.isEmpty(options.scene)) {
  41. let scene = decodeURIComponent(options.scene).split('=');
  42. if (scene[0] == 'channel') {
  43. that.setData({ channelId: scene[1] })
  44. }
  45. }
  46. that.getVoucher()
  47. })
  48. }
  49. },
  50. // 领取现金券
  51. getVoucher() {
  52. let that = this;
  53. util.ajax({
  54. func: "voucher/new_user/receive",
  55. data: {
  56. channelId: this.data.channelId,
  57. type: 'wxNewUser',
  58. phone: app.globalData.userInfo.phoneNum
  59. }
  60. }, function (res) {
  61. if (res.code == 0) {
  62. that.setData({ getImgUrl: 'https://img.bbztx.com/image_test/upload/thumbs/20220930/logo/1664519389257009593.jpg', getSuccess: 1 })
  63. } else {
  64. that.setData({ getImgUrl: 'https://img.bbztx.com/image_test/upload/thumbs/20220930/logo/1664519439365071430.jpg', getSuccess: 0, failContent: res.reason })
  65. }
  66. });
  67. },
  68. onShareAppMessage() {
  69. let that = this;
  70. console.log('/pages/public/cashCoupon/index?channel=' + this.data.channelId)
  71. return {
  72. title: '价值158元新人优惠券免费领',
  73. path: '/pages/public/cashCoupon/index?channel=' + this.data.channelId,
  74. imageUrl: 'https://img.bbztx.com/image_test/upload/thumbs/20220906/logo/1662445015137076027.png'
  75. }
  76. }
  77. })