templateE.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <template>
  2. <view class="section_page_main clearfix">
  3. <view class="recommend-list" :style="{height: hasLessImage ? '105px' : ''}" v-if="productList.length > 0">
  4. <swiper
  5. class="tui-banner-swiper"
  6. :autoplay="true"
  7. :interval="5000"
  8. :duration="500"
  9. :circular="true"
  10. @change="swiperChange"
  11. :style="{height: hasLessImage ? '105px' : ''}"
  12. >
  13. <swiper-item v-for="(list, index1) in productList" :key="index1">
  14. <view class="template-grid">
  15. <view
  16. class="img-box"
  17. v-for="(product, index2) in list"
  18. :key="index2"
  19. @click="navigaitionTo(product)"
  20. >
  21. <image :src="product.appletsImage" mode="aspectFit"></image>
  22. <view class="cm-cover" v-if="pageData.floorContent.templateClassify === 4"></view>
  23. </view>
  24. </view>
  25. </swiper-item>
  26. </swiper>
  27. <view class="swiper__recommenddots-box" v-if="productList.length > 1">
  28. <view
  29. v-for="(item, idx) in productList"
  30. :key="idx"
  31. :class="[idx === swiperCurrent ? 'swiper__dots-long' : 'none']"
  32. :data-index="swiperCurrent"
  33. class="swiper__dots-item"
  34. ></view>
  35. </view>
  36. </view>
  37. </view>
  38. </template>
  39. <script>
  40. import { mapState, mapMutations } from 'vuex'
  41. import uniGrader from '@/components/uni-grade/uni-grade.vue'
  42. import caimeiApi from '@/common/config/caimeiApi.js'
  43. export default {
  44. name: 'templateE',
  45. components: {
  46. uniGrader
  47. },
  48. props: {
  49. pageData: {
  50. type: Object
  51. },
  52. userIdentity: {
  53. type: Number
  54. }
  55. },
  56. data() {
  57. return {
  58. productList: [],
  59. swiperCurrent: 0,
  60. pageSize: 4,
  61. imageCount: 2
  62. }
  63. },
  64. created() {
  65. this.initData(this.pageData)
  66. },
  67. computed: {
  68. hasLessImage() {
  69. return this.imageCount <= 2
  70. }
  71. },
  72. watch: {
  73. pageData: {
  74. handler: function(el) {
  75. //监听对象的变换使用 function,箭头函数容易出现this指向不正确
  76. this.pageData = el
  77. this.initData(this.pageData)
  78. },
  79. deep: true
  80. }
  81. },
  82. methods: {
  83. initData(data) {
  84. this.imageCount = data.floorImageList.length
  85. while (data.floorImageList.length > 0) {
  86. this.productList.push(data.floorImageList.splice(0, this.pageSize))
  87. }
  88. console.log(this.productList)
  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">
  110. .section_page_main {
  111. width: 100%;
  112. height: auto;
  113. box-sizing: border-box;
  114. .recommend-list {
  115. width: 100%;
  116. height: 500rpx;
  117. position: relative;
  118. padding-bottom: 20rpx;
  119. .tui-banner-swiper {
  120. width: 100%;
  121. margin: 0 auto;
  122. height: 445rpx;
  123. overflow: hidden;
  124. transform: translateY(0);
  125. .template-grid {
  126. width: 100%;
  127. height: 100%;
  128. display: grid;
  129. grid-template-columns: repeat(2, 1fr);
  130. grid-template-rows: repeat(2, 1fr);
  131. grid-gap: 12rpx;
  132. }
  133. .img-box {
  134. position: relative;
  135. width: 339rpx;
  136. height: 210rpx;
  137. float: left;
  138. overflow: hidden;
  139. border-radius: 16rpx;
  140. background: #fff;
  141. image {
  142. width: 339rpx;
  143. height: 210rpx;
  144. }
  145. &:nth-child(2n) {
  146. margin-right: 0;
  147. }
  148. &:nth-child(1) {
  149. margin-top: 0;
  150. }
  151. .cm-cover {
  152. z-index: 99;
  153. top: 0;
  154. left: 0;
  155. position: absolute;
  156. width: 100%;
  157. height: 100%;
  158. background: url(https://static.caimei365.com/app/img/icon2/cm_player.png) no-repeat center;
  159. background-size: 40rpx 40rpx;
  160. }
  161. }
  162. }
  163. }
  164. .swiper__recommenddots-box {
  165. position: absolute;
  166. bottom: 0;
  167. left: 0;
  168. right: 0;
  169. /* #ifndef APP-NVUE */
  170. display: flex;
  171. /* #endif */
  172. flex: 1;
  173. flex-direction: row;
  174. justify-content: center;
  175. align-items: center;
  176. height: 60rpx;
  177. .swiper__dots-item {
  178. width: 8rpx;
  179. height: 8rpx;
  180. border-radius: 100%;
  181. margin-left: 6px;
  182. background-color: rgba(225, 86, 22, 0.3);
  183. }
  184. .swiper__dots-long {
  185. width: 32rpx;
  186. height: 8rpx;
  187. border-radius: 4rpx;
  188. background-color: #FF5B00;
  189. transition: all 0.4s;
  190. }
  191. }
  192. }
  193. </style>