index.js 7.9 KB

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