index.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. nvabarData: {
  9. // 顶部自定义导航
  10. showCapsule: 1, // 是否显示左上角图标 1表示显示 0表示不显示,
  11. showSearch: 0,
  12. title: '联合丽格集采商城', // 导航栏 中间的标题
  13. haveBack: false,
  14. textLeft: this.$store.state.isIphone,
  15. textColor: '#FFFFFF'
  16. },
  17. CustomBar: this.CustomBar, // 顶部导航栏高度
  18. skeletonShow: false,
  19. clubId: 0,
  20. clubStatus: '',
  21. current: 0,
  22. mode: 'round',
  23. isLogin: false,
  24. userIdentity: 0,
  25. bannerList: [], // 轮播
  26. mainmenu: [], // 导航分类
  27. floorList: [], // 楼层
  28. mallTheme:{}, //活动专题
  29. isScrollTop: false,
  30. }
  31. },
  32. computed: {
  33. ...mapState(['hasLogin', 'userInfo', 'identity', 'isActivity', 'isWxAuthorize'])
  34. },
  35. methods: {
  36. ...mapMutations(['login', 'logout','updateNoticeNum','updateRossShow']),
  37. async mallOrganizeHome() {
  38. //初始化首页数据
  39. try{
  40. const res = await this.CommonService.mallOrganizeHome({ organizeId: 1 })
  41. let data = res.data
  42. this.bannerList = data.bannerList
  43. this.mainmenu = data.mainmenu
  44. this.floorList = data.floorList
  45. this.mallTheme = data.mallTheme
  46. // if (this.hasLogin) {
  47. // // this.initShoppingCartCount()
  48. // }
  49. this.skeletonShow = true
  50. }catch(error){
  51. //TODO handle the exception
  52. console.log('error',error)
  53. }
  54. },
  55. async GetWxAuthorize() {
  56. const wechatCode = await authorize.getCode('weixin') // 根据微信的code获取用户登录状态:1已登录过 -1未登录过
  57. const getUserInfo = await authorize.getUserInfo('weixin')
  58. this.UserService.UserLoginAuthApplets({
  59. code: wechatCode,
  60. encryptedData: getUserInfo.encryptedData,
  61. iv: getUserInfo.iv
  62. })
  63. .then(response => {
  64. this.isLogin = true
  65. this.userID = response.data.userId
  66. this.clubId = response.data.clubId
  67. this.userIdentity = response.data.userIdentity
  68. this.clubStatus = response.data.clubStatus
  69. this.$store.commit('updateStatus', response.data)
  70. this.login(response.data)
  71. uni.setStorageSync('token', response.data.token)
  72. uni.setStorageSync('unionId', response.data.unionId)
  73. if (response.data.userIdentity == 1) {
  74. this.$api.redirectTo('/pages/seller/index/index')
  75. } else if (response.data.userIdentity === 3) {
  76. this.$api.redirectTo('/pages/supplier/index/index')
  77. }
  78. this.updateRossShow()
  79. this.GetInitBeansInfo()
  80. this.getHomeInformation()
  81. })
  82. .catch(error => {
  83. this.isLogin = false
  84. this.logout()
  85. uni.setStorageSync('unionId', error.data.unionId)
  86. this.$store.commit('updateStatus', error.data)
  87. this.updateRossShow()
  88. this.getHomeInformation()
  89. })
  90. },
  91. initShoppingCartCount() {
  92. // 获取购物车数量
  93. this.OrderService.ShoppingCartCount({ userId: this.userID }).then(res => {
  94. this.$store.commit('updateAllNum', res.data)
  95. })
  96. }
  97. }
  98. }
  99. export default homeMiXins