home.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <template>
  2. <view class="home">
  3. <!-- 搜索框 -->
  4. <van-search :value="value" placeholder="请输入搜索关键词" />
  5. <!-- 轮播 -->
  6. <view class="uni-margin-wrap">
  7. <swiper class="swiper" circular :indicator-dots="indicatorDots" :autoplay="autoplay" :interval="interval"
  8. :duration="duration">
  9. <swiper-item v-for="(item,index) in background" :key="index">
  10. <image class="pictures" :src="item.imgUrl" mode=""></image>
  11. </swiper-item>
  12. </swiper>
  13. </view>
  14. <!-- 导航 -->
  15. <van-grid :border="false">
  16. <van-grid-item icon="new-arrival-o" text="新品推荐" />
  17. <van-grid-item icon="underway-o" text="限时特惠" />
  18. <van-grid-item icon="hot-o" text="每日疯抢" />
  19. <van-grid-item icon="coupon-o" text="领优惠券" />
  20. </van-grid>
  21. <!-- 通知栏 -->
  22. <van-notice-bar left-icon="volume-o" :scrollable="false">
  23. <swiper class="list" vertical="true" :autoplay="3000" :show-indicators="false">
  24. <swiper-item v-for="(item,index) in noticeList" :key="index">
  25. {{item.title}}
  26. </swiper-item>
  27. </swiper>
  28. </van-notice-bar>
  29. <!-- 商品列表 -->
  30. <view class="product" v-for="(item,index) in prodList" :key="index">
  31. <view class="title">
  32. <text>{{item.title}}</text>
  33. <text>查看更多</text>
  34. </view>
  35. <view class="product_list">
  36. <view class="main" v-for="(item1,index1) in item.productDtoList" :key="index1" @click.native="goDetail(item1)">
  37. <image :src="item1.pic" mode=""></image>
  38. <view class="name">
  39. {{item1.prodName}}
  40. </view>
  41. <view class="price">
  42. ¥{{item1.price}}
  43. </view>
  44. </view>
  45. </view>
  46. </view>
  47. </view>
  48. </template>
  49. <script>
  50. import {
  51. banner,
  52. notice,
  53. prod
  54. } from '../../api/home.js';
  55. export default {
  56. data() {
  57. return {
  58. background: [],
  59. indicatorDots: true,
  60. autoplay: true,
  61. interval: 2000,
  62. duration: 500,
  63. noticeList: [],
  64. prodList: []
  65. }
  66. },
  67. onLoad() {
  68. banner().then(res => {
  69. console.log(res, 'res')
  70. this.background = res;
  71. })
  72. notice().then(res => {
  73. this.noticeList = res.records;
  74. })
  75. prod().then(res => {
  76. this.prodList = res;
  77. console.log(this.prodList, '商品')
  78. })
  79. },
  80. methods: {
  81. goDetail(event) {
  82. uni.navigateTo({
  83. url:`/pages/detail/detail?id=${event.prodId}`
  84. })
  85. }
  86. }
  87. }
  88. </script>
  89. <style lang="less">
  90. .uni-margin-wrap {
  91. width: 750rpx;
  92. width: 100%;
  93. }
  94. .swiper {
  95. height: 460rpx;
  96. }
  97. .swiper-item {
  98. // display: block;
  99. height: 460rpx;
  100. line-height: 460rpx;
  101. text-align: center;
  102. }
  103. .pictures {
  104. width: 100%;
  105. height: 460rpx;
  106. }
  107. .van-notice-bar__content {
  108. width: 648rpx;
  109. }
  110. .list {
  111. height: 40rpx;
  112. line-height: 40rpx;
  113. }
  114. .product {
  115. .title {
  116. display: flex;
  117. justify-content: space-between;
  118. align-items: center;
  119. margin: 20rpx 10rpx;
  120. font-size: 28rpx;
  121. }
  122. .title text:last-child {
  123. color: #ccc;
  124. font-size: 21rpx;
  125. }
  126. .product_list {
  127. display: flex;
  128. flex-wrap: wrap;
  129. .main {
  130. width: 33%;
  131. display: flex;
  132. flex-direction: column;
  133. align-items: center;
  134. margin: 18rpx 0;
  135. image {
  136. width: 200rpx;
  137. height: 200rpx;
  138. border-radius: 8rpx;
  139. }
  140. .name {
  141. width: 200rpx;
  142. font-size: 22rpx;
  143. overflow:hidden;
  144. text-overflow:ellipsis;
  145. display:-webkit-box;
  146. -webkit-box-orient:vertical;
  147. -webkit-line-clamp:2;
  148. }
  149. .price {
  150. width: 200rpx;
  151. color: #f00;
  152. }
  153. }
  154. }
  155. }
  156. </style>