index.nvue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <template>
  2. <gracePage headerBG="#FF0000" statusBarBG="#FF0036">
  3. <!-- 页面头部 -->
  4. <view slot="gHeader">
  5. <view class="grace-header-body">
  6. <text class="grace-header-icons grace-icons grace-white">&#xe61d;</text>
  7. <view class="grace-header-content grace-flex-center">
  8. <view style="width:580rpx;">
  9. <graceSearch></graceSearch>
  10. </view>
  11. </view>
  12. <text class="grace-header-icons grace-icons grace-white">&#xe6fe;</text>
  13. </view>
  14. </view>
  15. <!-- 页面主体 -->
  16. <view slot="gBody">
  17. <!-- 轮播图 start -->
  18. <swiper class="grace-swiper" autoplay="true" indicator-dots indicator-color="rgba(255, 255, 255, 1)"
  19. indicator-active-color="#FF0036" style="height:328rpx" interval="3000">
  20. <swiper-item class="grace-swiper-item" v-for="(item, index) in swiperItems" :key="index">
  21. <view class="grace-img-in">
  22. <image :src="item" mode="widthFix" class="grace-swiper-image"></image>
  23. </view>
  24. </swiper-item>
  25. </swiper>
  26. <view class="grace-common-line"></view>
  27. <!-- 推荐图标 start -->
  28. <view class="grace-grids">
  29. <view class="grace-grids-items" v-for="(item, index) in indexCate" :key="index">
  30. <image class="grace-grids-icon-img" :src="item.img" mode="widthFix"></image>
  31. <text class="grace-grids-text">{{item.title}}</text>
  32. </view>
  33. </view>
  34. <view class="grace-common-line"></view>
  35. <view class="grace-body">
  36. <!-- 猜你喜欢 start -->
  37. <view class="grace-title">
  38. <text class="grace-title-text grace-black">猜你喜欢</text>
  39. <!-- 换一批调用 youlike 函数,利用后端随机更新喜欢的内容即可 -->
  40. <text class="grace-icons icon-refresh grace-green grace-text-small icon-right-margin" @tap="youlike">换一批</text>
  41. </view>
  42. <view class="grace-img-card">
  43. <view class="grace-img-card-item" :data-productid="index" v-for="(item, index) in youlikes" :key="index" @tap="openProductInfo">
  44. <view class="grace-img-card-img">
  45. <image :src="item.img" mode="widthFix" class="grace-img-card-img"></image>
  46. </view>
  47. <text class="grace-img-card-title grace-ellipsis">{{item.name}}</text>
  48. <view>
  49. <text class="grace-img-card-price">¥{{item.price}}</text>
  50. <text class="grace-line-through grace-text-small grace-gray">¥{{item.priceMarket}}</text>
  51. </view>
  52. </view>
  53. </view>
  54. <!-- 猜你喜欢 end -->
  55. <!-- 循环首页分类及分类推荐的产品 start -->
  56. <view v-for="(item, index) in indexCateAndProducts" :key="index">
  57. <view class="common-line"></view>
  58. <view class="grace-title">
  59. <text class="grace-title-text grace-black">{{item.cateName}}</text>
  60. <view :data-cateid="item.cateId">
  61. <text class="grace-text-small grace-gray">更多</text>
  62. <text class="grace-text-small grace-gray grace-icons icon-arrow-right icon-left-margin"></text>
  63. </view>
  64. </view>
  65. <view class="grace-img-card">
  66. <view class="grace-img-card-item" :data-productid="index" v-for="(item, index) in item.products" :key="index" @tap="openProductInfo">
  67. <view class="grace-img-card-img">
  68. <image :src="item.img" mode="widthFix" class="grace-img-card-img"></image>
  69. </view>
  70. <text class="grace-img-card-title grace-ellipsis">{{item.name}}</text>
  71. <view>
  72. <text class="grace-img-card-price">¥{{item.price}}</text>
  73. <text class="grace-line-through grace-text-small grace-gray">¥{{item.priceMarket}}</text>
  74. </view>
  75. </view>
  76. </view>
  77. </view>
  78. <!-- 循环首页分类及分类推荐的产品 end -->
  79. </view>
  80. </view>
  81. </gracePage>
  82. </template>
  83. <script>
  84. import gracePage from "../../graceUI/weexComponents/gracePage.nvue";
  85. import graceSearch from "../../graceUI/weexComponents/graceSearch.nvue";
  86. var gRequest = require('../../graceUI/jsTools/request.js');
  87. export default {
  88. data(){
  89. return {
  90. swiperItems : [],
  91. indexCate : [],
  92. youlikes:[],
  93. indexCateAndProducts : [],
  94. top: 0,
  95. }
  96. },
  97. onLoad:function(){
  98. // 加载轮播
  99. gRequest.get(
  100. 'http://grace.hcoder.net/api/swipers',{},
  101. res => { this.swiperItems = res.data});
  102. // 加载首页推荐图标
  103. gRequest.get(
  104. 'http://grace.hcoder.net/api/cate/indexCate',{},
  105. (res) => { this.indexCate = res.data;});
  106. // 猜你喜欢
  107. this.youlike();
  108. // 加载首页推荐分类及产品
  109. gRequest.get(
  110. 'http://grace.hcoder.net/api/products/indexTj',{},
  111. (res) => { this.indexCateAndProducts = res.data});
  112. },
  113. components:{
  114. gracePage, graceSearch
  115. },
  116. methods:{
  117. // 搜索相关函数
  118. inputting : function(e){ console.log(e); },
  119. confirm : function (e) { console.log(e); },
  120. // 猜你喜欢
  121. youlike : function(){
  122. gRequest.get(
  123. 'http://grace.hcoder.net/api/products/youlike',{},
  124. (res) => { this.youlikes = res.data});
  125. },
  126. // 打开商品详情
  127. openProductInfo : function(e){
  128. uni.navigateTo({ url: '../productInfo/productInfo'});
  129. }
  130. }
  131. }
  132. </script>
  133. <style>
  134. /* 九宫格个性修饰 */
  135. .grace-grids-items{width:150rpx; padding:25rpx;}
  136. .grace-grids-image{width:80rpx; height:80rpx;}
  137. /* 产品列表修饰 */
  138. .grace-img-card-img{height:340rpx;}
  139. .grace-img-card-price{margin-right:20rpx;}
  140. .grace-swiper-image{width:750rpx; height:328rpx;}
  141. </style>