index.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. userIdentity: 0,
  24. bannerList: [], // 轮播
  25. mainmenu: [], // 导航分类
  26. floorList: [], // 楼层
  27. mallTheme:{}, //活动专题
  28. isScrollTop: false,
  29. }
  30. },
  31. computed: {
  32. ...mapState(['hasLogin', 'userInfo', 'isWxAuthorize'])
  33. },
  34. methods: {
  35. ...mapMutations(['login', 'logout','updateNoticeNum']),
  36. async mallOrganizeHome() {
  37. //初始化首页数据
  38. try{
  39. const res = await this.CommonService.mallOrganizeHome({ organizeId: 4 })
  40. let data = res.data
  41. this.bannerList = data.bannerList
  42. this.mainmenu = data.mainmenu
  43. this.floorList = data.floorList
  44. this.mallTheme = data.mallTheme
  45. // if (this.hasLogin) {
  46. // // this.initShoppingCartCount()
  47. // }
  48. this.skeletonShow = true
  49. }catch(error){
  50. //TODO handle the exception
  51. console.log('error',error)
  52. }
  53. },
  54. async authApplets() {
  55. const wechatCode = await authorize.getCode('weixin') // 根据微信的code获取用户登录状态:1已登录过 -1未登录过
  56. const getUserInfo = await authorize.getUserInfo('weixin')
  57. this.UserService.UserLoginAuthApplets({
  58. code: wechatCode,
  59. encryptedData: getUserInfo.encryptedData,
  60. iv: getUserInfo.iv
  61. })
  62. .then(response => {
  63. this.clubStatus = response.data.clubStatus
  64. this.$store.commit('updateStatus', response.data)
  65. this.login(response.data)
  66. uni.setStorageSync('token', response.data.token)
  67. uni.setStorageSync('unionId', response.data.unionId)
  68. })
  69. .catch(error => {
  70. this.logout()
  71. uni.setStorageSync('unionId', error.data.unionId)
  72. this.$store.commit('updateStatus', error.data)
  73. })
  74. },
  75. initShoppingCartCount() {
  76. // 获取购物车数量
  77. this.OrderService.ShoppingCartCount({ userId: this.userID }).then(res => {
  78. this.$store.commit('updateAllNum', res.data)
  79. })
  80. }
  81. }
  82. }
  83. export default homeMiXins