index.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. // 首页数据
  2. import Vue from 'vue'
  3. import { mapState,mapMutations} from 'vuex'
  4. import authorize from '@/common/config/authorize.js'
  5. const homeMiXins = {
  6. data() {
  7. return {
  8. bankInfo:{}
  9. }
  10. },
  11. computed: {
  12. ...mapState(['hasLogin', 'userInfo', 'identity', 'isActivity', 'isWxAuthorize'])
  13. },
  14. methods: {
  15. ...mapMutations(['login', 'logout','updateNoticeNum','updateRossShow']),
  16. async GetWxAuthorize() {
  17. const wechatCode = await authorize.getCode('weixin') // 根据微信的code获取用户登录状态:1已登录过 -1未登录过
  18. const getUserInfo = await authorize.getUserInfo('weixin')
  19. this.UserService.UserLoginAuthApplets({
  20. code: wechatCode,
  21. encryptedData: getUserInfo.encryptedData,
  22. iv: getUserInfo.iv
  23. })
  24. .then(response => {
  25. this.isLogin = true
  26. this.userID = response.data.userId
  27. this.clubId = response.data.clubId
  28. this.userIdentity = response.data.userIdentity
  29. this.clubStatus = response.data.clubStatus
  30. this.$store.commit('updateStatus', response.data)
  31. this.login(response.data)
  32. uni.setStorageSync('token', response.data.token)
  33. uni.setStorageSync('unionId', response.data.unionId)
  34. if (response.data.userIdentity == 1) {
  35. this.$api.redirectTo('/pages/seller/index/index')
  36. } else if (response.data.userIdentity === 3) {
  37. this.$api.redirectTo('/pages/supplier/index/index')
  38. }
  39. this.updateRossShow()
  40. this.GetInitBeansInfo()
  41. this.getHomeInformation()
  42. })
  43. .catch(error => {
  44. this.isLogin = false
  45. this.logout()
  46. uni.setStorageSync('unionId', error.data.unionId)
  47. this.$store.commit('updateStatus', error.data)
  48. this.updateRossShow()
  49. this.getHomeInformation()
  50. })
  51. },
  52. GetHomeTopDataInfo() {
  53. //直播、活动、文章模块
  54. this.CommonService.GetHomeTopDataInfo({ source: 2 })
  55. .then(response => {
  56. this.templateData = response.data
  57. this.isLiveRequest = true
  58. })
  59. .catch(error => {
  60. this.$util.msg(error.msg, 2000)
  61. })
  62. },
  63. GetHomeFloorInfo() {
  64. //初始化首页楼层数据
  65. this.CommonService.GetHomeDataInfo({ userId: this.userID, source: 2 })
  66. .then(response => {
  67. let data = response.data
  68. this.pageList = data.homePageFloor
  69. this.hotListPageFloor = data.pageFloorList
  70. this.supplierObj = data.supplierImage
  71. setTimeout(() => {
  72. this.isRequest = true
  73. }, 500)
  74. })
  75. .catch(error => {
  76. this.$util.msg(error.msg, 2000)
  77. })
  78. },
  79. GetInitBeansInfo() {
  80. //初始化采美豆信息
  81. this.UserService.GetHomeObtainBeans({ userId: this.userID })
  82. .then(response => {
  83. this.beansType = response.data.beansType
  84. this.beanNumber = response.data.num
  85. this.isActivityBean = true
  86. })
  87. .catch(error => {
  88. console.log('用户暂无采美豆推送~')
  89. })
  90. },
  91. getHomeInformation() {
  92. //初始化首页数据
  93. this.CommonService.GetHomeModulesDataInfo({ source: 2 })
  94. .then(res => {
  95. let data = res.data
  96. this.bannerImageList = data.bannerList
  97. this.mallPageModules = data.mallPageModules
  98. this.skeletonShow = false
  99. this.navBarsList = data.topMenuList
  100. this.couponEntry = data.couponEntry
  101. this.newsList = data.annlist
  102. if (!this.hasLogin && this.couponEntry == 1) {
  103. if (uni.getStorageSync('isActivitySwitch')) {
  104. this.$store.commit('setActivity', false)
  105. } else {
  106. this.$store.commit('setActivity', true)
  107. }
  108. }
  109. this.GetHomeTopDataInfo()
  110. this.GetHomeFloorInfo()
  111. if (this.hasLogin) {
  112. this.initShoppingCartCount()
  113. }
  114. this.isNavRequest = true
  115. })
  116. .catch(error => {
  117. this.$util.msg(error.msg, 2000)
  118. })
  119. },
  120. initShoppingCartCount() {
  121. // 获取购物车数量
  122. this.OrderService.ShoppingCartCount({ userId: this.userID }).then(res => {
  123. this.$store.commit('updateAllNum', res.data)
  124. })
  125. },
  126. handleClick(data) {
  127. const pageId = 306
  128. this.$api.navigateTo('/pages/user/coupon/coupon-collection')
  129. this.$store.commit('setActivity', data)
  130. uni.setStorageSync('lockTime', Date.now())
  131. uni.setStorageSync('isActivitySwitch', true)
  132. // 友盟自定义事件
  133. // if(process.env.NODE_ENV != 'development'){
  134. // this.$uma.trackEvent('meibohui_click', {
  135. // Um_Key_PageName: '美博会',
  136. // Um_Key_PageCategory: '活动专题页面',
  137. // Um_Key_SourcePage: '首页',
  138. // })
  139. // }
  140. },
  141. handleCancelClick(data) {
  142. this.$store.commit('setActivity', data)
  143. uni.setStorageSync('lockTime', Date.now())
  144. uni.setStorageSync('isActivitySwitch', true)
  145. },
  146. handleBeanlClick() {
  147. this.isActivityBean = false
  148. }
  149. }
  150. }
  151. export default homeMiXins