my.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. import {loginByUserInfo, loginFn} from './../../utils/login'
  2. import { VueLikePage } from '../../utils/page'
  3. import Router from '../../utils/routes'
  4. import { autoSubcrebe, subcribe } from '../../utils/utils'
  5. const app = getApp();
  6. VueLikePage([], {
  7. options: {
  8. addGlobalClass: true,
  9. },
  10. data: {
  11. cu_items: [{
  12. title: '名片夹',
  13. icon: 'my_contacts',
  14. value: 'businessCard',
  15. needLogin: true
  16. },
  17. {
  18. title: '我的收藏',
  19. icon: 'my_product',
  20. value: 'collectGoods',
  21. needLogin: true
  22. },
  23. // {
  24. // title: '已收藏参展商',
  25. // icon: 'my_enterprise',
  26. // value: 'collectEnterprise',
  27. // },
  28. // {
  29. // title: '数据报表',
  30. // icon: 'my_reportform',
  31. // value: 'dataReport',
  32. // needLogin: true
  33. // },
  34. {
  35. title: '账号设置',
  36. icon: 'my_set',
  37. value: 'logout',
  38. needLogin: true
  39. },
  40. {
  41. title: '开启消息订阅',
  42. icon: 'cus_msg',
  43. value: 'message',
  44. needLogin: true,
  45. hiddenKey: 'isCustomer',
  46. hidden: true
  47. },
  48. ],
  49. user_code: '',
  50. isLogined: getApp().globalData.token ? true : false,
  51. userinfo: getApp().globalData.userinfo
  52. },
  53. methods: {
  54. Navigator_to(e) {
  55. const { value } = e.currentTarget.dataset
  56. const item = this.data.cu_items.find(item => item.value === value)
  57. if (item.needLogin && !getApp().globalData.token) {
  58. this.toLogin()
  59. return
  60. }
  61. if (value === 'message') {
  62. subcribe().then((res) => {
  63. console.log(res, 'res')
  64. this.onShow()
  65. })
  66. return
  67. }
  68. Router.push(value)
  69. },
  70. toModifyUser() {
  71. if (!this.data.isLogined) {
  72. return
  73. }
  74. wx.navigateTo({
  75. url: '/pages/user-info/user-info',
  76. })
  77. },
  78. /**
  79. * 生命周期函数--监听页面加载
  80. */
  81. onLoad: function (e) {
  82. this.isCustomer = true
  83. wx.login({
  84. success: (res) => {
  85. this.setData({
  86. user_code: res.code
  87. })
  88. }
  89. })
  90. },
  91. onShow: function () {
  92. let cu_items = this.data.cu_items
  93. this.isCustomer = getApp().globalData.userinfo ? getApp().globalData.userinfo.type !== 'guide' : true
  94. autoSubcrebe().then(res => {
  95. cu_items.forEach(item => {
  96. if (item.hiddenKey) {
  97. item.hidden = this[item.hiddenKey]
  98. }
  99. if (item.hiddenKey === 'isCustomer' && !this.isCustomer) {
  100. item.hidden = res
  101. }
  102. })
  103. this.setData({
  104. cu_items,
  105. isLogined: getApp().globalData.token ? true : false,
  106. userinfo: getApp().globalData.userinfo,
  107. showLogin: false
  108. });
  109. })
  110. wx.login({
  111. success: (res) => {
  112. if (res.code) {
  113. this.wx_code = res.code
  114. }
  115. }
  116. })
  117. },
  118. bindgetuserinfo (e) {
  119. if (!e.detail.userInfo) {
  120. return
  121. }
  122. wx.showLoading({
  123. title: '登录中',
  124. })
  125. loginByUserInfo(e.detail, this.wx_code).then(() => {
  126. wx.hideLoading({
  127. complete: (res) => {
  128. this.onShow()
  129. },
  130. })
  131. })
  132. },
  133. toLogin () {
  134. // Router.push('login')
  135. this.setData({
  136. showLogin: true
  137. })
  138. },
  139. hideLogin () {
  140. this.setData({
  141. showLogin: false
  142. })
  143. },
  144. loginSuccess () {
  145. console.log('login')
  146. this.onShow()
  147. }
  148. }
  149. })