cm-floor-template.vue 6.7 KB

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