index.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. centerImage: [], // 优惠弹窗
  31. navBarsList: [], // 导航分类
  32. shortcutList: [], // 快捷运营
  33. newsList: [], // 公告
  34. templateData: {},
  35. hotListPageFloor: [], // 新品橱窗
  36. pageList: [], // 楼层
  37. supplierObj: [], // 供应商列表
  38. recommendProducts:[],//推荐商品列表
  39. centerImageShow:false,
  40. }
  41. },
  42. computed: {
  43. ...mapState(['hasLogin', 'userInfo', 'identity', 'isActivity', 'isWxAuthorize'])
  44. },
  45. methods: {
  46. ...mapMutations(['login', 'logout','updateNoticeNum','updateRossShow']),
  47. async GetWxAuthorize() {
  48. const wechatCode = await authorize.getCode('weixin') // 根据微信的code获取用户登录状态:1已登录过 -1未登录过
  49. const getUserInfo = await authorize.getUserInfo('weixin')
  50. this.UserService.UserLoginAuthApplets({
  51. code: wechatCode,
  52. encryptedData: getUserInfo.encryptedData,
  53. iv: getUserInfo.iv
  54. })
  55. .then(response => {
  56. this.isLogin = true
  57. this.userID = response.data.userId
  58. this.clubId = response.data.clubId
  59. this.userIdentity = response.data.userIdentity
  60. this.clubStatus = response.data.clubStatus
  61. this.$store.commit('updateStatus', response.data)
  62. this.login(response.data)
  63. uni.setStorageSync('token', response.data.token)
  64. uni.setStorageSync('unionId', response.data.unionId)
  65. if (response.data.userIdentity == 1) {
  66. this.$api.redirectTo('/pages/seller/index/index')
  67. } else if (response.data.userIdentity === 3) {
  68. this.$api.redirectTo('/pages/supplier/index/index')
  69. }
  70. this.updateRossShow()
  71. this.GetInitBeansInfo()
  72. this.getHomeInformation()
  73. })
  74. .catch(error => {
  75. this.isLogin = false
  76. this.logout()
  77. uni.setStorageSync('unionId', error.data.unionId)
  78. this.$store.commit('updateStatus', error.data)
  79. this.updateRossShow()
  80. this.getHomeInformation()
  81. })
  82. },
  83. GetHomeTopDataInfo() {
  84. //直播、活动、文章模块
  85. this.CommonService.GetHomeTopDataInfo({ source: 2 })
  86. .then(response => {
  87. this.templateData = response.data
  88. this.isLiveRequest = true
  89. })
  90. .catch(error => {
  91. this.$util.msg(error.msg, 2000)
  92. })
  93. },
  94. GetHomeFloorInfo() {
  95. //初始化首页楼层数据
  96. this.CommonService.GetHomeDataInfo({ userId: this.userID, source: 2 })
  97. .then(response => {
  98. let data = response.data
  99. this.pageList = data.zones
  100. this.hotListPageFloor = data.pageFloorList
  101. this.supplierObj = data.supplierImage
  102. this.recommendProducts = data.recommendProducts
  103. setTimeout(() => {
  104. this.isRequest = true
  105. }, 500)
  106. })
  107. .catch(error => {
  108. this.$util.msg(error.msg, 2000)
  109. })
  110. },
  111. GetInitBeansInfo() {
  112. //初始化采美豆信息
  113. this.UserService.GetHomeObtainBeans({ userId: this.userID })
  114. .then(response => {
  115. this.beansType = response.data.beansType
  116. this.beanNumber = response.data.num
  117. this.isActivityBean = true
  118. })
  119. .catch(error => {
  120. console.log('用户暂无采美豆推送~')
  121. })
  122. },
  123. getHomeInformation() {
  124. //初始化首页数据
  125. this.CommonService.GetHomeModulesDataInfo({ source: 2 })
  126. .then(res => {
  127. let data = res.data
  128. this.bannerImageList = data.bannerList
  129. this.mallPageModules = data.mallPageModules
  130. this.skeletonShow = false
  131. this.navBarsList = data.topMenuList
  132. this.couponEntry = data.couponEntry
  133. this.newsList = data.annlist
  134. this.shortcutList = data.shortcutList || [] // 快捷运营
  135. if (!this.hasLogin && this.couponEntry === 1) {
  136. this.$store.commit('updateCouponEntry', data.couponEntry)
  137. if (uni.getStorageSync('isActivitySwitch')) {
  138. this.$store.commit('setActivity', false)
  139. } else {
  140. this.$store.commit('setActivity', true)
  141. }
  142. }
  143. if(data.centerImage && data.centerImage.length > 0){
  144. this.centerImage = data.centerImage
  145. // 获取当前日期的字符串表示(YYYY-MM-DD)
  146. const currentDate = new Date().toISOString().split('T')[0]
  147. console.log('currentDate',currentDate)
  148. // 从localStorage获取上次显示弹窗的日期
  149. const lastPopupDate = uni.getStorageSync('lastPopupDate')
  150. console.log('lastPopupDate',lastPopupDate)
  151. // 检查今天是否已经显示过弹窗
  152. if (lastPopupDate !== currentDate) {
  153. // 显示弹窗和遮罩层
  154. this.centerImageShow = true
  155. }
  156. }
  157. this.GetHomeTopDataInfo()
  158. this.GetHomeFloorInfo()
  159. if (this.hasLogin) {
  160. this.initShoppingCartCount()
  161. this.updateNoticeNum()
  162. }
  163. this.isNavRequest = true
  164. })
  165. .catch(error => {
  166. this.$util.msg(error.msg, 2000)
  167. })
  168. },
  169. initShoppingCartCount() {
  170. // 获取购物车数量
  171. this.OrderService.ShoppingCartCount({ userId: this.userID }).then(res => {
  172. this.$store.commit('updateAllNum', res.data)
  173. })
  174. },
  175. handleClick(data) {
  176. const pageId = 306
  177. this.$api.navigateTo('/pages/user/coupon/coupon-collection')
  178. this.$store.commit('setActivity', data)
  179. uni.setStorageSync('lockTime', Date.now())
  180. uni.setStorageSync('isActivitySwitch', true)
  181. // 友盟自定义事件
  182. // if(process.env.NODE_ENV != 'development'){
  183. // this.$uma.trackEvent('meibohui_click', {
  184. // Um_Key_PageName: '美博会',
  185. // Um_Key_PageCategory: '活动专题页面',
  186. // Um_Key_SourcePage: '首页',
  187. // })
  188. // }
  189. },
  190. handleCancelClick(data) {
  191. this.$store.commit('setActivity', data)
  192. uni.setStorageSync('lockTime', Date.now())
  193. uni.setStorageSync('isActivitySwitch', true)
  194. },
  195. // 关闭广告弹窗
  196. handleCenterImageCancelClick(){
  197. const currentDate = new Date().toISOString().split('T')[0]
  198. console.log('currentDate',currentDate)
  199. // 更新localStorage中的上次显示弹窗的日期
  200. uni.setStorageSync('lastPopupDate', currentDate)
  201. this.centerImageShow = false
  202. },
  203. // 广告弹窗跳转
  204. handleCenterImageClick(item){
  205. this.$api.FlooryNavigateTo(item)
  206. },
  207. handleBeanlClick() {
  208. this.isActivityBean = false
  209. },
  210. }
  211. }
  212. export default homeMiXins