swiper-temp1.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <template>
  2. <view class="section_page_main clearfix">
  3. <view class="recommend-list">
  4. <swiper
  5. class="tui-banner-swiper"
  6. :autoplay="true"
  7. :interval="5000"
  8. :duration="500"
  9. :circular="true"
  10. @change="swiperChange"
  11. :class="{ minHeigth: hasLessImage }"
  12. >
  13. <swiper-item class="clearfix" v-for="(item, index1) in list" :key="index1">
  14. <view
  15. class="img-box"
  16. v-for="(product, index2) in item"
  17. :key="index2"
  18. @click="navigaitionTo(product)"
  19. >
  20. <view class="cm-cover" :class="'color' + checkDisplayDate">{{coverText[checkDisplayDate]}}</view>
  21. <image :src="product.appletsImage" mode="scaleToFill"></image>
  22. </view>
  23. </swiper-item>
  24. </swiper>
  25. <view class="swiper__recommenddots-box" v-if="list.length > 1">
  26. <view
  27. v-for="(item, idx) in list"
  28. :key="idx"
  29. :class="[idx === swiperCurrent ? 'swiper__dots-long' : 'none']"
  30. :data-index="swiperCurrent"
  31. class="swiper__dots-item"
  32. >
  33. </view>
  34. </view>
  35. </view>
  36. </view>
  37. </template>
  38. <script>
  39. import { mapState, mapMutations } from 'vuex'
  40. import caimeiApi from '@/common/config/caimeiApi.js'
  41. export default {
  42. name: 'SwiperTemp',
  43. props: {
  44. floorImageList: {
  45. type: Array
  46. },
  47. displayDate: String
  48. },
  49. data() {
  50. return {
  51. list: [],
  52. swiperCurrent: 0,
  53. pageSize: 4,
  54. imageCount: 0,
  55. coverText: ['未开始', '已开始', '已结束']
  56. }
  57. },
  58. created() {
  59. this.initData()
  60. },
  61. computed: {
  62. hasLessImage() {
  63. return this.imageCount <= 2
  64. },
  65. checkDisplayDate() {
  66. const nowDate = new Date().getTime()
  67. const displayDate = new Date(this.displayDate).getTime()
  68. const oneDay = 60 * 60 * 24 * 1000
  69. // 未开始
  70. if (nowDate < displayDate) {
  71. return 0
  72. }
  73. // 已开始
  74. if (nowDate > displayDate && nowDate < displayDate + oneDay) {
  75. return 1
  76. }
  77. // 已结束
  78. if (nowDate > displayDate + oneDay) {
  79. return 2
  80. }
  81. }
  82. },
  83. methods: {
  84. initData() {
  85. this.imageCount = this.floorImageList.length
  86. while (this.floorImageList.length > 0) {
  87. this.list.push(this.floorImageList.splice(0, this.pageSize))
  88. }
  89. },
  90. swiperChange(e) {
  91. //轮播切换
  92. const index = e.detail.current
  93. this.swiperCurrent = index
  94. },
  95. navigaitionTo(item) {
  96. if (item.adsImage === '' && item.linkType === -1) {
  97. return
  98. } else if (item.linkType === -1) {
  99. uni.navigateTo({
  100. url: `/pages/h5/activity/activity-detail?adsImage=${item.adsImage}&title=${item.name}`
  101. })
  102. } else {
  103. caimeiApi.FlooryNavigateTo(item)
  104. }
  105. }
  106. }
  107. }
  108. </script>
  109. <style lang="scss" scoped>
  110. .minHeigth {
  111. height: 250rpx !important;
  112. }
  113. .section_page_main {
  114. width: 100%;
  115. height: auto;
  116. box-sizing: border-box;
  117. .recommend-list {
  118. width: 100%;
  119. position: relative;
  120. padding-bottom: 20rpx;
  121. .tui-banner-swiper {
  122. height: 550rpx;
  123. width: 100%;
  124. margin: 0 auto;
  125. background: #f7f7f7;
  126. overflow: hidden;
  127. transform: translateY(0);
  128. .img-box {
  129. position: relative;
  130. width: 339rpx;
  131. height: 240rpx;
  132. float: left;
  133. margin: 24rpx 24rpx 0 0;
  134. overflow: hidden;
  135. border-radius: 16rpx;
  136. image {
  137. width: 339rpx;
  138. height: 240rpx;
  139. }
  140. &:nth-child(2n) {
  141. margin-right: 0;
  142. }
  143. &:nth-child(1),
  144. &:nth-child(2) {
  145. margin-top: 0;
  146. }
  147. .cm-cover {
  148. position: absolute;
  149. width: 96rpx;
  150. height: 40rpx;
  151. top: 0;
  152. right: 0;
  153. border-radius: 0 16rpx 0 16rpx;
  154. color: #fff;
  155. font-size: 24rpx;
  156. text-align: center;
  157. line-height: 36rpx;
  158. &.color2 {
  159. background: rgba(0, 0, 0, 0.5);
  160. }
  161. &.color1 {
  162. background: rgb(255, 92, 0);
  163. }
  164. &.color0 {
  165. background: rgb(30, 206, 112);
  166. }
  167. }
  168. }
  169. }
  170. }
  171. .swiper__recommenddots-box {
  172. position: absolute;
  173. bottom: 0;
  174. left: 0;
  175. right: 0;
  176. /* #ifndef APP-NVUE */
  177. display: flex;
  178. /* #endif */
  179. flex: 1;
  180. flex-direction: row;
  181. justify-content: center;
  182. align-items: center;
  183. height: 60rpx;
  184. .swiper__dots-item {
  185. width: 8rpx;
  186. height: 8rpx;
  187. border-radius: 100%;
  188. margin-left: 6px;
  189. background-color: rgba(225, 86, 22, 0.3);
  190. }
  191. .swiper__dots-long {
  192. width: 32rpx;
  193. height: 8rpx;
  194. border-radius: 4rpx;
  195. background-color: #e15616;
  196. transition: all 0.4s;
  197. }
  198. }
  199. }
  200. </style>