index.js 6.5 KB

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