special-discount.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <template>
  2. <div class="discount-list" v-cloak>
  3. <div class="list-con" v-if="discountList.length">
  4. <div
  5. :class="['item' , item.pcPic ? '' : 'no-bg']"
  6. v-for="(item,index) in discountList"
  7. :key="item.discountId"
  8. @click="toDiscountDetail(item.discountId)"
  9. >
  10. <img :src="item.pcPic" class="bg" />
  11. <div class="text-box">
  12. <div class="time">
  13. <span class="time-icon"></span>
  14. {{ $t('onlyLeft') }}
  15. <div class="much-time" v-if="endTimeList[index].day">
  16. <span class="number">{{endTimeList[index].day}}</span>{{ $t('day') }}
  17. </div>
  18. <!-- 大于一天展示 -->
  19. <div class="number-box" v-if="endTimeList[index].day===0">
  20. <span class="number">{{endTimeList[index].hour}}</span>
  21. <span class="colon">:</span>
  22. <span class="number">{{endTimeList[index].min}}</span>
  23. <span class="colon">:</span>
  24. <span class="number">{{endTimeList[index].second}}</span>
  25. </div>
  26. <!-- 小于一天展示 -->
  27. </div>
  28. <div class="logo">
  29. <img :src="item.shopLogo" alt />
  30. </div>
  31. <div class="info">{{item.discountName}}</div>
  32. </div>
  33. </div>
  34. </div>
  35. <!-- 页码 -->
  36. <pagination v-model="current" :pages="pages" @changePage="getDiscountPage"></pagination>
  37. <!-- /页码 -->
  38. <!-- 活动列表为空 -->
  39. <div class="empty" v-if="!discountList.length">
  40. <div class="img">
  41. <img src="~/assets/images/emptyPic/not-found.png" alt />
  42. </div>
  43. <div class="action">
  44. <div class="text">{{ $t('sorryNoRelatedActivities') }}</div>
  45. <nuxt-link to="/" class="btn">{{ $t('backToHome') }}</nuxt-link>
  46. </div>
  47. </div>
  48. <!-- 活动列表为空 -->
  49. </div>
  50. </template>
  51. <script>
  52. import Pagination from '~/components/pagination'
  53. export default {
  54. components: {
  55. Pagination
  56. },
  57. data () {
  58. return {
  59. discountList: [], //优惠活动列表
  60. current: 1, // 当前页数
  61. pages: 1, // 总页数
  62. endTimeList: [], //结束时间
  63. timer: ''
  64. }
  65. },
  66. mounted () {
  67. // 设置网页标题
  68. document.title = this.$t('commonHead.limitedTimeOffer')
  69. this.getDiscountPage(1) //默认加载第一页
  70. },
  71. beforeDestroy () {
  72. clearTimeout(this.timer)
  73. },
  74. methods: {
  75. //获取优惠活动列表
  76. getDiscountPage (cur) {
  77. this.$axios.get('/marking/discount/getDiscountList', {
  78. params: {
  79. current: cur, //当前页
  80. size: 20
  81. }
  82. }).then(({ data }) => {
  83. this.discountList = data.records
  84. this.pages = data.pages
  85. var endTimeList = [];
  86. this.discountList.forEach(item => {
  87. endTimeList.push({ endTime: item.endTime });
  88. })
  89. this.endTimeList = endTimeList;
  90. this.countTime()
  91. })
  92. },
  93. // 倒计时
  94. countTime () {
  95. var endTimeList = this.endTimeList
  96. endTimeList.forEach((item, index) => {
  97. // 获取当前时间
  98. let date = new Date()
  99. let now = date.getTime()
  100. // 设置截止时间
  101. let end = new Date(item.endTime).getTime()
  102. // 时间差
  103. let leftTime = end - now
  104. // 定义变量 d,h,m,s保存倒计时的时间
  105. if (leftTime >= 0) {
  106. // 天
  107. item.day = Math.floor(leftTime / 1000 / 60 / 60 / 24)
  108. // 时
  109. let h = Math.floor(leftTime / 1000 / 60 / 60 % 24)
  110. item.hour = h < 10 ? '0' + h : h
  111. // 分
  112. let m = Math.floor(leftTime / 1000 / 60 % 60)
  113. item.min = m < 10 ? '0' + m : m
  114. // 秒
  115. let s = Math.floor(leftTime / 1000 % 60)
  116. item.second = s < 10 ? '0' + s : s
  117. } else {
  118. item.day = 0
  119. item.hour = '00'
  120. item.min = '00'
  121. item.second = '00'
  122. }
  123. this.$set(this.endTimeList, index, item)
  124. })
  125. // 递归每秒调用countTime方法,显示动态时间效果
  126. this.timer = setTimeout(this.countTime, 1000)
  127. },
  128. //跳转活动详情
  129. toDiscountDetail (discountId) {
  130. this.$router.push({
  131. path: '/discount-detail',
  132. query: {
  133. discountId: discountId
  134. }
  135. })
  136. }
  137. }
  138. }
  139. </script>
  140. <style scoped src='~/assets/css/discount.css'></style>
  141. <style scoped>
  142. .empty {
  143. padding-top: 140px;
  144. }
  145. </style>