cm-floor-template.vue 7.3 KB

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