home.vue 3.6 KB

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