index.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <template>
  2. <view class="container">
  3. <!-- 头部轮播 -->
  4. <view class="carousel-section">
  5. <swiper class="carousel" autoplay="true" duration="400" interval="5000">
  6. <swiper-item v-for="(item, index) in bannerImg" :key="index" class="carousel-item" @click="bannerNavToUrl(item)">
  7. <image :src="item.img" mode=" scaleToFill" />
  8. </swiper-item>
  9. </swiper>
  10. </view>
  11. <view class="goodsList-box">
  12. <view class="goodsList-item" :key="ind" v-for="(ls, ind) in list" @click="navToDetailPage(ls)">
  13. <navigator :url="'/pages/product/product?id=' + ls.id">
  14. <image :src="ls.image" mode=" scaleToFill"></image>
  15. <view class="goodsList-content">
  16. <view class="title clamp">
  17. <text>{{ ls.store_name }}</text>
  18. </view>
  19. <view class="goods-money flex">
  20. <view class="money-box flex">
  21. <view v-if="ls.use_max_integral != 0">
  22. <text class="money">{{ ls.use_max_integral }}</text>
  23. <text class="font-size-sm">积分</text>
  24. </view>
  25. <view v-else>
  26. <text class="money">¥{{ ls.price }}</text>
  27. </view>
  28. <view class="otMoney-box" v-if="ls.use_max_integral != 0">
  29. <text class="otMoney" v-if="ls.price - ls.use_max_integral > 0">+¥{{ (ls.price - ls.use_max_integral) | toFixed }}</text>
  30. </view>
  31. </view>
  32. <view class="otprice">
  33. <text>¥{{ ls.price }}</text>
  34. </view>
  35. </view>
  36. </view>
  37. </navigator>
  38. </view>
  39. </view>
  40. </view>
  41. </template>
  42. <script>
  43. import { groomList } from '@/api/product.js';
  44. export default {
  45. filters: {
  46. toFixed: function(value) {
  47. // 判断是否为整数
  48. if (value % 1 == 0) {
  49. return value;
  50. } else {
  51. return value.toFixed(2);
  52. }
  53. }
  54. },
  55. data() {
  56. return {
  57. list: [],
  58. bannerImg: []
  59. };
  60. },
  61. onLoad(option) {
  62. // 加载基础数据
  63. this.loadData();
  64. },
  65. methods: {
  66. //详情页
  67. navToDetailPage(item) {
  68. uni.navigateTo({
  69. url: '/pages/product/product?id=' + item.id
  70. });
  71. },
  72. // 轮播图跳转
  73. bannerNavToUrl(item) {
  74. // #ifdef H5
  75. if (item.wap_link.indexOf('http') > 0) {
  76. window.location.href = item.wap_link;
  77. }
  78. // #endif
  79. //测试数据没有写id,用title代替
  80. uni.navigateTo({
  81. url: item.wap_link
  82. });
  83. },
  84. // 请求载入数据
  85. async loadData() {
  86. groomList({}, 5)
  87. .then(({ data }) => {
  88. // 保存轮播图
  89. this.bannerImg = data.banner;
  90. // 保存商品信息
  91. this.list = data.list.map(e => {
  92. e.price = Number(e.price);
  93. e.ot_price = Number(e.ot_price);
  94. return e;
  95. });
  96. })
  97. .catch(e => {
  98. console.log(e);
  99. });
  100. }
  101. }
  102. };
  103. </script>
  104. <style lang="scss">
  105. page {
  106. background: $page-color-base;
  107. }
  108. .carousel-section {
  109. margin-bottom: 30rpx;
  110. padding: 0;
  111. .titleNview-placing {
  112. padding-top: 0;
  113. height: 0;
  114. }
  115. .swiper-dots {
  116. left: 45rpx;
  117. bottom: 40rpx;
  118. }
  119. .carousel {
  120. width: 100%;
  121. height: 360rpx;
  122. .carousel-item {
  123. width: 100%;
  124. height: 100%;
  125. overflow: hidden;
  126. }
  127. image {
  128. width: 100%;
  129. height: 100%;
  130. }
  131. }
  132. }
  133. // 商品列表
  134. .goodsList-box {
  135. padding: 0 25rpx;
  136. display: flex;
  137. flex-wrap: wrap;
  138. .goodsList-item {
  139. width: 340rpx;
  140. margin-bottom: 30rpx;
  141. background-color: #ffffff;
  142. border-radius: $border-radius-sm;
  143. image {
  144. flex-shrink: 0;
  145. height: 340rpx;
  146. width: 340rpx;
  147. }
  148. &:nth-child(2n + 1) {
  149. margin-right: 20rpx;
  150. }
  151. .goodsList-content {
  152. padding-left: 20rpx;
  153. flex-grow: 1;
  154. padding: 20rpx;
  155. .title {
  156. font-size: $font-base;
  157. color: $font-color-dark;
  158. font-weight: 500;
  159. }
  160. .goods-money {
  161. line-height: 1;
  162. margin-top: 10rpx;
  163. font-size: $font-sm - 4rpx;
  164. .money {
  165. color: $color-red;
  166. font-weight: bold;
  167. }
  168. .font-size-sm {
  169. color: $font-color-light;
  170. }
  171. .otMoney {
  172. background-color: #ffeae2;
  173. color: $color-red;
  174. }
  175. .otprice {
  176. text-decoration: line-through;
  177. color: $font-color-light;
  178. }
  179. }
  180. }
  181. }
  182. }
  183. </style>