cm-floor-template.vue 6.8 KB

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