index.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. mallOrganizeHome() {
  53. //初始化首页数据
  54. this.CommonService.mallOrganizeHome({ organizeId: 1 })
  55. .then(res => {
  56. let data = res.data
  57. if (this.hasLogin) {
  58. // this.initShoppingCartCount()
  59. }
  60. this.skeletonShow = false
  61. })
  62. .catch(error => {
  63. this.$util.msg(error.msg, 2000)
  64. })
  65. },
  66. initShoppingCartCount() {
  67. // 获取购物车数量
  68. this.OrderService.ShoppingCartCount({ userId: this.userID }).then(res => {
  69. this.$store.commit('updateAllNum', res.data)
  70. })
  71. }
  72. }
  73. }
  74. export default homeMiXins