index.js 8.1 KB

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