home-discount.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <!--
  2. * @Author: jmy
  3. * @Date: 2026-01-06 12:02:41
  4. * @LastEditors: Please set LastEditors
  5. * @LastEditTime: 2026-01-06 15:02:20
  6. * @Description: 自定义轮播图组件
  7. -->
  8. <template>
  9. <view class="w-all relative zi-2 mt-4">
  10. <swiper class="w-all" :style="{ height: height * 2 + 'rpx' }" :circular="circular"
  11. :indicator-dots="indicatorDots" indicator-active-color="#02B176" indicator-color="#EEEEEE"
  12. :autoplay="autoplay" :interval="interval" :duration="duration" :current="current"
  13. :display-multiple-items="displayMultipleItems" :next-margin="nextMargin" @change="change"
  14. @transition="transition" @animationfinish="animationfinish">
  15. <swiper-item class="flex flex-wrap h-all" v-for="(item, index) in list" :key="index">
  16. <view class="w-74 h-82 bg-white flex items-center justify-center">
  17. <view class="w-64 h-82 flex flex-column items-center justify-center">
  18. <image :src="item.image || 'https://cdn.his.cdwjyyh.com/images/img.png'" class="w-35 h-44" />
  19. <view class="h-15 text-ellipsis fw-400 fs-11 my-3">{{ item.productName || '商品名称' }}</view>
  20. <view class="w-54 h-16 rounded-16 bg-FA341E text-white text-center fs-9 relative">
  21. ¥<text class="fs-13">{{ splitPrice(item.price).integer || '00' }}</text>
  22. <text class="fs-9">{{ splitPrice(item.price).decimal || '00' }}</text>
  23. <image src="https://cdn.his.cdwjyyh.com/images/sdyhzq_arrow_icon.png"
  24. class="w-16 h-16 absolute top-0 left--6 zi-10" />
  25. </view>
  26. </view>
  27. </view>
  28. </swiper-item>
  29. </swiper>
  30. <view class="flex items-center justify-center w-all gap-6 mt-11" v-if="isCustomDot">
  31. <view v-for="(item, index) in list" :key="index" class="w-10 h-2 rounded-1"
  32. :class="index == current ? 'bg-02B176' : 'bg-EEEEEE'"></view>
  33. </view>
  34. </view>
  35. </template>
  36. <script>
  37. export default {
  38. props: {
  39. swiperList: {
  40. type: Array,
  41. default: () => []
  42. },
  43. height: {
  44. type: Number,
  45. default: 85
  46. },
  47. indicatorDots: {
  48. type: Boolean,
  49. default: false
  50. },
  51. circular: {
  52. type: Boolean,
  53. default: true
  54. },
  55. autoplay: {
  56. type: Boolean,
  57. default: false
  58. },
  59. interval: {
  60. type: Number,
  61. default: 3000
  62. },
  63. duration: {
  64. type: Number,
  65. default: 1000
  66. },
  67. displayMultipleItems: {
  68. type: Number,
  69. default: 2
  70. },
  71. nextMargin: {
  72. type: String,
  73. default: '0'
  74. },
  75. current: {
  76. type: Number,
  77. default: 0
  78. },
  79. isCustomDot: {
  80. type: Boolean,
  81. default: false
  82. }
  83. },
  84. data() {
  85. return {
  86. list: [],
  87. currentDot: 0
  88. }
  89. },
  90. mounted() {
  91. console.log("首单优惠专区", this.swiperList);
  92. // 添加存在性检查
  93. this.list = this.swiperList && this.swiperList[0] && this.swiperList[0].productList ? this.swiperList[0].productList : [];
  94. console.log("数据", this.swiperList);
  95. },
  96. methods: {
  97. splitPrice(price) {
  98. const priceStr = parseFloat(price).toFixed(2).toString();
  99. return {
  100. integer: priceStr.split('.')[0],
  101. decimal: priceStr.split('.')[1]
  102. };
  103. },
  104. change(e) {
  105. this.$emit('change', e.detail.current);
  106. },
  107. transition(e) {
  108. this.$emit('transition', e.detail.current);
  109. },
  110. animationfinish(e) {
  111. this.$emit('animationfinish', e.detail.current);
  112. },
  113. handleNavTo(value) {
  114. console.log('导航到:', value);
  115. }
  116. }
  117. };
  118. </script>
  119. <style lang="scss" scoped>
  120. </style>