index.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <template>
  2. <div class="w-full bg-[#f6f6f6]">
  3. <div class="main-container home-carousel">
  4. <el-carousel :interval="3000" height="520px" arrow="never">
  5. <el-carousel-item v-for="(item,index) in advInfo.adv_list">
  6. <NuxtLink :to="item.adv_url && item.adv_url.url ? item.adv_url.url : '' ">
  7. <div class="h-full index-carousel">
  8. <img :src="img(item.adv_image)" alt="" class="w-full h-full">
  9. </div>
  10. </NuxtLink>
  11. </el-carousel-item>
  12. </el-carousel>
  13. <div class="mt-[40px]">
  14. <template v-for="(item,index) in floorList" :key="index">
  15. <div class="mt-[30px] mb-[10px]">
  16. <div class="flex justify-between items-center mb-[20px]" v-if="item.config.title || item.config.sub_title || item.config.url">
  17. <div class="flex items-center">
  18. <div class="leading-[40px] h-[40px]">
  19. <span class="text-[24px] text-[#333]">{{item.config.title}}</span>
  20. <span class="text-[#999] text-[12px] ml-[10px]">{{item.config.sub_title}}</span>
  21. </div>
  22. </div>
  23. <div class="text-[14px] text-[#999] cursor-pointer oppoSans-R" v-if="item.config && item.config.url && item.config.url.url" @click="toLink(item.config.url.url)">
  24. <span>更多</span>
  25. <span class="iconfont icon-youV6xx ml-[4px]"></span>
  26. </div>
  27. </div>
  28. <div class="flex box-border">
  29. <div class="w-[224px] h-[628px] mr-[20px]" v-if="item.config.adv_img1">
  30. <el-image :src="img(item.config.adv_img1)" :fit="cover" class="w-full max-w-[628px] rounded-tl-[16px] rounded-br-[16px]"/>
  31. </div>
  32. <div class="flex flex-wrap flex-1">
  33. <template v-for="(subItem,subIndex) in item.goods_list" :key="subIndex">
  34. <div class="w-[224px] h-[304px] mb-[20px] bg-[#fff] py-[11px] cursor-pointer" :class="{'mr-[20px]': (item.config.adv_img1 ? (subIndex + 1) % 4 : (subIndex + 1) % 5 ) }" @click="toDetail(subItem.goods_id)" v-if="item.config.adv_img1 ? (subIndex < 8) : (subIndex < 10)">
  35. <div class="w-full h-[200px] mb-[10px] flex items-center justify-center" >
  36. <el-image style="width: 200px; height: 200px" :src="img(subItem.goods_cover)" :fit="cover">
  37. <template #error>
  38. <img src="@/assets/images/goods_default.png" class="w-[200px] h-[200px]">
  39. </template>
  40. </el-image>
  41. </div>
  42. <div class="mx-[10px]">
  43. <div class="mb-[10px] h-[42px] text-[14px] multi-hidden text-[#333] leading-[21px]">{{ subItem.goods_name }}</div>
  44. <div class="flex items-center justify-between flex-wrap">
  45. <div class="text-[var(--el-price)] flex items-baseline">
  46. <span class="text-[12px] price-font">¥</span>
  47. <span class="text-[20px] price-font">{{parseFloat(goodsPrice(subItem)).toFixed(2)}}</span>
  48. <img v-if="priceType(subItem) == 'member_price'" class="h-[16px] ml-[3px] w-[54px]" src="@/assets/images/addon/VIP.png" />
  49. <img v-if="priceType(subItem) == 'discount_price'" class="h-[12px] ml-[3px] w-[36px]" src="@/assets/images/addon/discount.png" />
  50. </div>
  51. <div class="text-[12px] leading-[16px] text-[#999]">已售{{subItem.sale_num}}{{ subItem.unit || '件' }}</div>
  52. </div>
  53. </div>
  54. </div>
  55. </template>
  56. </div>
  57. </div>
  58. <div class="w-[1200px] h-[120px] mt-[10px]" v-if="item.config.adv_img2">
  59. <el-image :src="img(item.config.adv_img2)" :fit="cover" class="w-full max-h-[120px]"/>
  60. </div>
  61. </div>
  62. </template>
  63. </div>
  64. </div>
  65. </div>
  66. </template>
  67. <script lang="ts" setup>
  68. import { ref } from 'vue'
  69. import { getToken} from '@/utils/common'
  70. import { useRouter, useRoute } from 'vue-router'
  71. import { getAdvInfo, getFloor } from '@/app/api/index'
  72. const router = useRouter()
  73. // 广告位
  74. const advInfo = ref({})
  75. const getAdvInfoFn = () =>{
  76. getAdvInfo({ap_key:'ADV_INDEX'}).then(res =>{
  77. advInfo.value = res.data
  78. })
  79. }
  80. getAdvInfoFn()
  81. // 首页楼层
  82. const floorList = ref([])
  83. const getFloorFn = () =>{
  84. getFloor().then(res =>{
  85. floorList.value = res.data
  86. })
  87. }
  88. getFloorFn()
  89. // 查看更多
  90. const toLink = (url:string) =>{
  91. // 外部链接
  92. if (url.indexOf('https') != -1 || url.indexOf('http') != -1) {
  93. window.open(url)
  94. }else {
  95. router.push(url)
  96. }
  97. }
  98. // 商品详情
  99. const toDetail = (goods_id:number) =>{
  100. router.push(`/goods/detail?id=${goods_id}`)
  101. }
  102. // 价格类型
  103. let priceType = (data:any) =>{
  104. let type = "";
  105. if(data.is_discount){
  106. type = 'discount_price'// 折扣
  107. }else if(data.member_discount && getToken()){
  108. type = 'member_price' // 会员价
  109. }else{
  110. type = ""
  111. }
  112. return type;
  113. }
  114. // 商品价格
  115. let goodsPrice = (data:any) =>{
  116. let price = "0.00";
  117. if(data.is_discount){
  118. price = data.goodsSku.sale_price?data.goodsSku.sale_price:data.goodsSku.price // 折扣价
  119. }else if(data.member_discount && getToken()){
  120. price = data.goodsSku.member_price?data.goodsSku.member_price:data.goodsSku.price // 会员价
  121. }else{
  122. price = data.goodsSku.price
  123. }
  124. return price;
  125. }
  126. </script>
  127. <style lang="scss" scoped>
  128. .home-carousel :deep(.el-carousel__indicators--horizontal){
  129. bottom: 30px;
  130. }
  131. .brick-item{
  132. transition: all .2s linear;
  133. &:hover{
  134. box-shadow: 0 15px 30px rgba(0,0,0,.1);
  135. transform: translate3d(0,-2px,0)
  136. }
  137. }
  138. /* 多行超出隐藏 */
  139. .multi-hidden {
  140. word-break: break-all;
  141. text-overflow: ellipsis;
  142. overflow: hidden;
  143. display: -webkit-box;
  144. -webkit-line-clamp: 2;
  145. -webkit-box-orient: vertical;
  146. }
  147. .floor-bg{
  148. /*background-image: url(@/assets/images/index/floor-bg.png);*/
  149. /*background-position: center center;*/
  150. /*background-size: 100% 100%;*/
  151. /*background-repeat: no-repeat;*/
  152. }
  153. </style>