home.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <template>
  2. <view class="home">
  3. <!-- 搜索框 -->
  4. <van-search 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 bannerData" :key="index">
  10. <view class="swiper-item">
  11. <image :src="item.imgUrl" mode="" class="pictures"></image>
  12. </view>
  13. </swiper-item>
  14. </swiper>
  15. </view>
  16. <!-- 宫格 -->
  17. <van-grid>
  18. <van-grid-item icon="new-arrival-o" text="新品推荐" />
  19. <van-grid-item icon="underway-o" text="限时特惠" />
  20. <van-grid-item icon="hot-o" text="每日疯抢" />
  21. <van-grid-item icon="coupon-o" text="领优惠劵" />
  22. </van-grid>
  23. <!-- 通知栏 -->
  24. <van-notice-bar left-icon="volume-o" :scrollable="false">
  25. <swiper class="notice" circular :autoplay="autoplay" :interval="interval" :duration="duration">
  26. <swiper-item v-for="(item,index) in noticeDate" :key="index">
  27. <view>{{item.title}}</view>
  28. </swiper-item>
  29. </swiper>
  30. </van-notice-bar>
  31. <!-- 商品信息 -->
  32. <view class="info">
  33. <view class="main" v-for="(item,index) in productList" :key="index">
  34. <view class="header">
  35. <view class="left">
  36. {{item.title}}
  37. </view>
  38. <view class="right">
  39. 查看更多
  40. </view>
  41. </view>
  42. <view class="list" >
  43. <view class="box" v-for="(x,y) in item.productDtoList" :key="y" @click="getToDetail(x)">
  44. <image :src="x.pic" mode="" class="img"></image>
  45. <view class="tit">{{x.prodName}}</view>
  46. <view class="price">¥{{x.price}}</view>
  47. </view>
  48. </view>
  49. </view>
  50. </view>
  51. </view>
  52. </template>
  53. <script>
  54. import {
  55. banner,
  56. noticeList,
  57. productList
  58. } from '@/api/home.js';
  59. export default {
  60. data() {
  61. return {
  62. bannerData: [],
  63. indicatorDots: true,
  64. autoplay: true,
  65. interval: 2000,
  66. duration: 500,
  67. noticeDate: [],
  68. productList: []
  69. }
  70. },
  71. onShow() {
  72. console.log("走进来了啊啊啊啊")
  73. // 轮播方法
  74. this.bannerList();
  75. // 通知信息
  76. this.notice();
  77. // 商品信息
  78. this.info();
  79. },
  80. methods: {
  81. // async await
  82. // 方法名() {
  83. // 接口名().then().catch()
  84. // }
  85. // async 方法名() {
  86. // let xxx = await 接口名(参数)
  87. // }
  88. async bannerList() {
  89. console.log("走进来")
  90. let {
  91. data
  92. } = await banner();
  93. this.bannerData = data;
  94. // banner().then(res => {
  95. // console.log("成功",res)
  96. // }).catch(err => {
  97. // console.log(err,'失败')
  98. // })
  99. },
  100. async notice() {
  101. let {
  102. data
  103. } = await noticeList();
  104. this.noticeDate = data.records;
  105. },
  106. async info() {
  107. let {
  108. data
  109. } = await productList();
  110. this.productList = data;
  111. console.log(this.productList, 'productList')
  112. },
  113. // 去详情
  114. getToDetail(val) {
  115. uni.navigateTo({
  116. url:`/pages/detail/detail?id=${val.prodId}`
  117. })
  118. }
  119. }
  120. }
  121. </script>
  122. <style scoped lang="scss">
  123. .uni-margin-wrap {
  124. width: 690rpx;
  125. width: 100%;
  126. }
  127. .swiper {
  128. height: 300rpx;
  129. }
  130. .swiper-item {
  131. display: block;
  132. height: 300rpx;
  133. line-height: 300rpx;
  134. text-align: center;
  135. }
  136. .pictures {
  137. width: 100%;
  138. height: 300rpx;
  139. }
  140. .notice {
  141. width: 600rpx;
  142. }
  143. .info {
  144. padding: 15rpx;
  145. .main {
  146. .header {
  147. width: 96%;
  148. display: flex;
  149. justify-content: space-between;
  150. align-items: center;
  151. height: 70rpx;
  152. .left {
  153. font-weight: bold;
  154. }
  155. .right {
  156. color: #ccc;
  157. font-size: 20rpx;
  158. }
  159. }
  160. .list {
  161. display: flex;
  162. flex-wrap: wrap;
  163. justify-content: space-evenly;
  164. .box {
  165. width: 30%;
  166. margin-top: 20rpx;
  167. .img {
  168. width: 100%;
  169. height: 200rpx;
  170. margin: 0 auto;
  171. display: block;
  172. border-radius: 4rpx;
  173. }
  174. .tit {
  175. font-size: 24rpx;
  176. overflow: hidden;
  177. text-overflow: ellipsis;
  178. display: -webkit-box;
  179. -webkit-line-clamp: 2; // 控制多行的行数
  180. -webkit-box-orient: vertical;
  181. margin-top: 5rpx;
  182. }
  183. .price {
  184. color: red;
  185. font-size: 27rpx;
  186. font-weight: bold;
  187. margin-top: 5rpx;
  188. }
  189. }
  190. }
  191. }
  192. }
  193. </style>