cm-floor-template.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. <template>
  2. <view class="floor-template" v-if="floorData">
  3. <cm-floor-title :title="floorData.title" @click="$emit('more', floorData)" :sub-title="floorData.detail"></cm-floor-title>
  4. <!-- banner区域 -->
  5. <view class="floor-banner-area" :class="'template-' + templateType" v-if="templateType !== '8'">
  6. <view
  7. class="banner-item"
  8. :class="'banner-item-' + (index + 1)"
  9. v-for="(item, index) in bannerList"
  10. :key="index"
  11. >
  12. <image :src="item.image" class="banner" @click="$emit('onBannerClick', item)"></image>
  13. </view>
  14. </view>
  15. <!-- 商品区域 -->
  16. <view class="floor-product-area">
  17. <view class="simple-swiper" v-if="withSwiperLayout">
  18. <cm-simple-swiper
  19. @change="onChange"
  20. :current="current"
  21. :circular="true"
  22. :swiperHeight="swiperHeight"
  23. :data="productList"
  24. :columns="3"
  25. :rows="swiperRows"
  26. :gapX="16"
  27. :gapY="16"
  28. :autoFill="true"
  29. padding="0 8rpx"
  30. :autoplay="false"
  31. >
  32. <template v-slot:slide="{ row }">
  33. <div class="product-list">
  34. <view class="product-item" @click="$emit('onProductClick', row.heheProduct)">
  35. <cm-product :data="row.heheProduct"></cm-product>
  36. </view>
  37. </div>
  38. </template>
  39. </cm-simple-swiper>
  40. </view>
  41. <view class="product-list default-list" v-else>
  42. <view
  43. class="product-item"
  44. v-for="(item, index) in productList"
  45. :key="index"
  46. @click="$emit('onProductClick', item.heheProduct)"
  47. >
  48. <cm-product :data="item.heheProduct"></cm-product>
  49. </view>
  50. </view>
  51. </view>
  52. <!-- banner区域 -->
  53. <view class="floor-banner-area template-8" v-if="templateType === '8'">
  54. <view class="banner-item banner-item-1">
  55. <image
  56. :src="bannerList[0] && bannerList[0].image"
  57. class="banner"
  58. @click="$emit('onBannerClick', item)"
  59. ></image>
  60. </view>
  61. </view>
  62. </view>
  63. </template>
  64. <script>
  65. export default {
  66. props: {
  67. floorData: {
  68. type: Object,
  69. default: () => null
  70. }
  71. },
  72. data() {
  73. return {
  74. // 商品区域
  75. current: 0
  76. }
  77. },
  78. computed: {
  79. // 楼层id
  80. templateType() {
  81. return this.floorData?.floorContent.templateType
  82. },
  83. // banner图列表
  84. bannerList() {
  85. return this.splitBannersMap()
  86. },
  87. // 商品列表
  88. productList() {
  89. return this.floorData?.floorImageList
  90. },
  91. // 使用轮播图布局
  92. withSwiperLayout() {
  93. return [5, 9].indexOf(parseInt(this.templateType)) > -1
  94. },
  95. // 轮播图行数
  96. swiperRows() {
  97. if (this.templateType === '5') return 2
  98. if (this.templateType === '9') return 1
  99. return 2
  100. },
  101. // 轮播图高度
  102. swiperHeight() {
  103. return 480 * this.swiperRows
  104. }
  105. },
  106. methods: {
  107. // 从楼层数据中拆分出banner与link的关系
  108. splitBannersMap() {
  109. const bannerList = []
  110. if (this.floorData) {
  111. const floorContent = this.floorData?.floorContent
  112. for (let key in floorContent) {
  113. const linkValue = floorContent[key]
  114. if (key.indexOf('appletsAdsImage') > -1 && linkValue) {
  115. const obj = Object.create(null)
  116. obj.id = parseInt(key[key.length - 1])
  117. const subKey = 'adsLink' + obj.id
  118. obj.image = linkValue
  119. obj.link = floorContent[subKey]
  120. bannerList.push(obj)
  121. }
  122. }
  123. }
  124. return bannerList.sort((a, b) => a.id - b.id)
  125. },
  126. // 轮播图切换事件
  127. onChange(e) {
  128. this.current = e.current
  129. }
  130. }
  131. }
  132. </script>
  133. <style lang="scss" scoped>
  134. .floor-template {
  135. background-color: #f7f7f7;
  136. }
  137. // 轮播图尺寸
  138. .size-type-1 {
  139. width: 702rpx;
  140. height: 240rpx;
  141. }
  142. .size-type-2 {
  143. width: 343rpx;
  144. height: 524rpx;
  145. }
  146. .size-type-3 {
  147. width: 343rpx;
  148. height: 254rpx;
  149. }
  150. // banner 区域
  151. .floor-banner-area {
  152. padding: 0 16rpx;
  153. padding-bottom: 8rpx;
  154. &::after {
  155. display: block;
  156. content: '';
  157. clear: both;
  158. }
  159. .banner-item {
  160. float: left;
  161. padding: 8rpx;
  162. .banner {
  163. width: 100%;
  164. height: 100%;
  165. display: block;
  166. background: pink;
  167. border-radius: 16rpx;
  168. }
  169. }
  170. &.template-1 {
  171. .banner-item-1 {
  172. @extend .size-type-1;
  173. }
  174. }
  175. &.template-2 {
  176. .banner-item-1 {
  177. @extend .size-type-1;
  178. }
  179. .banner-item-2 {
  180. @extend .size-type-2;
  181. }
  182. .banner-item-3 {
  183. @extend .size-type-2;
  184. }
  185. }
  186. &.template-3 {
  187. .banner-item-1 {
  188. @extend .size-type-2;
  189. }
  190. .banner-item-2 {
  191. @extend .size-type-2;
  192. }
  193. }
  194. &.template-4 {
  195. }
  196. &.template-5 {
  197. }
  198. &.template-6 {
  199. .banner-item-1 {
  200. @extend .size-type-2;
  201. }
  202. .banner-item-2 {
  203. @extend .size-type-3;
  204. }
  205. .banner-item-3 {
  206. @extend .size-type-3;
  207. }
  208. }
  209. &.template-7 {
  210. .banner-item-1 {
  211. @extend .size-type-2;
  212. }
  213. .banner-item-2 {
  214. @extend .size-type-3;
  215. }
  216. .banner-item-3 {
  217. @extend .size-type-3;
  218. }
  219. .banner-item-4 {
  220. @extend .size-type-3;
  221. }
  222. .banner-item-5 {
  223. @extend .size-type-3;
  224. }
  225. }
  226. &.template-8 {
  227. padding-top: 8rpx;
  228. .banner-item-1 {
  229. @extend .size-type-1;
  230. }
  231. }
  232. &.template-9 {
  233. }
  234. }
  235. // 商品区域样式
  236. .floor-product-area {
  237. padding: 0 16rpx;
  238. .product-list {
  239. // @extend .cm-flex-between;
  240. // flex-wrap: wrap;
  241. display: grid;
  242. grid-template-columns: repeat(3, 1fr);
  243. // grid-template-rows: repeat(2, 1fr);
  244. grid-row-gap: 16rpx;
  245. .product-item {
  246. @extend .cm-flex-center;
  247. }
  248. }
  249. .simple-swiper {
  250. padding-top: 8rpx;
  251. }
  252. }
  253. </style>