App.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <style lang="scss">
  2. /* 注意要写在第一行,同时给style标签加入lang="scss"属性 */
  3. @import "uview-ui/index.scss";
  4. </style>
  5. <script>
  6. export default {
  7. onLaunch: function () {
  8. console.log('App Launch')
  9. },
  10. onShow: function () {
  11. console.log('App Show 小程序显示了+++++++++++++++++++++++')
  12. let that = this;
  13. wx.login({
  14. success(re) {
  15. that.$api.wxLogin({code: re.code}).then(res => {
  16. console.log('++++++++++登录返回了++++++++++++++++', res)
  17. uni.setStorageSync('userInfo', res.data.data.userInfo)
  18. uni.setStorageSync('accessToken', res.data.data.access_token)
  19. let isNew = res.data.data.isNew
  20. uni.removeStorageSync('parent_member_id');
  21. //用户点击用户分享进入小程序,进行绑定操作
  22. let shareUserId = uni.getStorageSync('shareUserId')
  23. if (shareUserId) {
  24. that.$api.scanCode({
  25. openId: res.data.data.userInfo.otherId,
  26. memberId: shareUserId
  27. }).then(res => {
  28. console.log('用户分享用户绑定成功', res)
  29. uni.removeStorageSync('shareUserId');
  30. })
  31. }
  32. //用户扫码拓客端进入小程序,携带的参数,进行绑定操作
  33. let expandParam = uni.getStorageSync('expandParam')
  34. if (expandParam) {
  35. console.log('获取到的拓客端参数',expandParam)
  36. if (new Date().getTime() <= expandParam.timestamp){
  37. if (isNew){
  38. //用户扫码拓客端进入小程序
  39. that.$api.userBindMember(
  40. {
  41. ...expandParam,
  42. memberId: res.data.data.userInfo.id
  43. }
  44. ).then(res1 => {
  45. console.log('拓客端推广用户绑定成功!')
  46. that.$api.addRecordForAttach({
  47. ...expandParam,
  48. isNew:1,
  49. isBindSuccess:1,
  50. }).then(res=>{
  51. console.log('+++++++++新用户,扫码推广成功记录!++++++++++++++++')
  52. })
  53. uni.removeStorageSync('expandParam');
  54. }).catch(err=>{
  55. that.$api.addRecordForAttach({
  56. ...expandParam,
  57. isNew:1,
  58. isBindSuccess:0,
  59. }).then(res=>{
  60. console.log('+++++++++新用户,扫码推广失败记录!++++++++++++++++')
  61. })
  62. uni.removeStorageSync('expandParam');
  63. })
  64. }else {
  65. that.$api.addRecordForAttach({
  66. ...expandParam,
  67. isNew:0,
  68. isBindSuccess:0,
  69. }).then(res=>{
  70. console.log('+++++++++老用户,扫码推广失败记录!++++++++++++++++')
  71. })
  72. uni.removeStorageSync('expandParam');
  73. }
  74. }else {
  75. uni.showModal({
  76. title: '温馨提示',
  77. content: ' 当前二维码已过期,请重新扫码',
  78. showCancel:false,
  79. success: function (res) {
  80. if (res.confirm) {
  81. console.log('用户点击确定');
  82. } else if (res.cancel) {
  83. console.log('用户点击取消');
  84. }
  85. }
  86. });
  87. uni.removeStorageSync('expandParam');
  88. }
  89. }
  90. //用户扫码技师端进入小程序,携带的参数。 暂无操作
  91. let promotionParam = uni.getStorageSync('promotionParam')
  92. })
  93. },
  94. })
  95. },
  96. onHide: function () {
  97. console.log('App Hide')
  98. }
  99. }
  100. </script>