index.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <template>
  2. <div class="index">
  3. <div v-if="isMobile">
  4. <Home></Home>
  5. </div>
  6. <div v-if="!isMobile">
  7. <christmas v-if="isOpen" @listenopen="listenOpen" :hasNewYear="hasNewYear"></christmas>
  8. <carousel>
  9. <kind-category @loadchild="loadProductKinds"></kind-category>
  10. </carousel>
  11. <advert></advert>
  12. <floor-list></floor-list>
  13. <img class="banner-img" src="/images/all/banner-home2.jpg" style="margin: 44px auto 24px;" alt="">
  14. <news></news>
  15. <partner></partner>
  16. </div>
  17. </div>
  18. </template>
  19. <script>
  20. import { KindCategory, Carousel, Advert, FloorList, Partner, News } from '~components/home'
  21. import { Christmas } from '~components/default'
  22. import { Home } from '~components/mobile'
  23. export default {
  24. name: 'index',
  25. layout (context) {
  26. return context.store.state.option.isMobile ? 'mobile' : 'main'
  27. },
  28. data () {
  29. return {
  30. isOpen: false,
  31. hasNewYear: false,
  32. defaultFloorsData: [
  33. // 'BT2018012500000141',
  34. // 'BT2018012500000126',
  35. // 'BT2018012500000131',
  36. // 'BT2018012500000152',
  37. // 'BT2018012500000124',
  38. // 'BT2018012500000164',
  39. // 'BT2018012500000167',
  40. // 'BT2018012500000145',
  41. // 'BT2018012500000151',
  42. // 'BT2018012500000161',
  43. // 'BT2018012500000149',
  44. // 'BT2018012500000162'
  45. 'BT2018012900002056',
  46. 'BT2018012900002056',
  47. 'BT2018012900002056',
  48. 'BT2018012900002056',
  49. 'BT2018012900002056',
  50. 'BT2018012900002056',
  51. 'BT2018012900002056',
  52. 'BT2018012900002056',
  53. 'BT2018012900002056',
  54. 'BT2018012900002056',
  55. 'BT2018012900002056',
  56. 'BT2018012900002056'
  57. ]
  58. }
  59. },
  60. components: {
  61. KindCategory,
  62. Carousel,
  63. Advert,
  64. FloorList,
  65. Partner,
  66. News,
  67. Christmas,
  68. Home
  69. },
  70. fetch ({store}) {
  71. return !store.state.option.isMobile ? Promise.all([
  72. store.dispatch('loadFloors'),
  73. store.dispatch('loadBanners', {type: 'home'}),
  74. store.dispatch('loadProductKinds', { id: 0 }),
  75. store.dispatch('loadNewsSnapshot', { page: 1, pageSize: 10 }),
  76. store.dispatch('loadBatchCommodities', this.defaultFloorsData)
  77. ]) : []
  78. },
  79. mounted () {
  80. let user = this.user.logged
  81. let count = 1
  82. let self = this
  83. const nowDate = new Date()
  84. const activeStartDate = new Date('2017/12/20 00:00:00')
  85. const activeEndDate = new Date('2018/1/2 00:00:00')
  86. const EndDate = new Date('2017/12/26 00:00:00')
  87. this.hasNewYear = nowDate > EndDate
  88. if (nowDate > activeStartDate && nowDate < activeEndDate) {
  89. const endTime = window.localStorage.getItem('endTime')
  90. if (!user) {
  91. setInterval(function () {
  92. count++
  93. if (count >= 60 * 60 * 2) {
  94. count = 1
  95. self.isOpen = true
  96. }
  97. }, 1000)
  98. }
  99. if (endTime) {
  100. if (nowDate.getTime() - endTime >= 1000 * 60 * 60 * 2) {
  101. user ? this.isOpen = false : this.isOpen = true
  102. window.localStorage.setItem('endTime', nowDate.getTime())
  103. } else {
  104. this.isOpen = false
  105. }
  106. } else {
  107. user ? this.isOpen = false : this.isOpen = true
  108. window.localStorage.setItem('endTime', nowDate.getTime())
  109. }
  110. } else {
  111. this.isOpen = false
  112. }
  113. },
  114. computed: {
  115. user () {
  116. return this.$store.state.option.user
  117. },
  118. isMobile: function () {
  119. return this.$store.state.option.isMobile
  120. }
  121. },
  122. methods: {
  123. listenOpen () {
  124. this.isOpen = false
  125. },
  126. loadProductKinds (id) {
  127. this.$store.dispatch('loadAllProductKinds', {id})
  128. }
  129. }
  130. }
  131. </script>