secondRecommend.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <template name="recommend">
  2. <!-- 供应商信息 -->
  3. <view class="recommend clearfix">
  4. <view class="recommend-empty" v-if="isEmpty">暂无相关推荐商品</view>
  5. <view class="recommend-list" v-else>
  6. <swiper class="tui-banner-swiper" :autoplay="false" :interval="5000" :duration="500" :circular="true" @change="swiperChange">
  7. <swiper-item v-for="(item,index) in recommendList" :key="index">
  8. <view class="row-list" v-for="(pros, idx) in item" :key="idx" @click.stop="navToDetailPage(pros.productID)">
  9. <view class="list-image"><image :src="pros.mainImage" mode=""></image></view>
  10. <view class="list-name">{{pros.name}}</view>
  11. </view>
  12. </swiper-item>
  13. </swiper>
  14. <view class="swiper__recommenddots-box" v-if="recommendList.length > 1">
  15. <view v-for="(item,idx) in recommendList"
  16. :key="idx"
  17. :class="[idx===current?'swiper__dots-long':'none']"
  18. :data-index="current" class="swiper__dots-item">
  19. </view>
  20. </view>
  21. </view>
  22. </view>
  23. </template>
  24. <script>
  25. import authorize from '@/common/config/authorize.js'
  26. import tuiLoadmore from "@/components/tui-components/loadmore/loadmore"
  27. import tuiNomore from "@/components/tui-components/nomore/nomore"
  28. import { queryRelevant } from "@/api/product.js"
  29. export default{
  30. name:'recommend',
  31. props:{
  32. queryProductid: {
  33. // Unistars类型
  34. type: Number,
  35. default: 0
  36. }
  37. },
  38. components:{
  39. tuiLoadmore,
  40. tuiNomore,
  41. },
  42. data() {
  43. return{
  44. current:0,
  45. recommendList:[],
  46. isEmpty:false,
  47. pageSize:4,
  48. productID:'',
  49. }
  50. },
  51. created() {
  52. this.productID = this.queryProductid
  53. this.infoRecommend(this.queryProductid)
  54. },
  55. methods:{
  56. infoRecommend(id){
  57. this.SellerService.ProductRecommend({productId:id}).then(response =>{
  58. console.log(response)
  59. if( response.data && response.data.length > 0){
  60. this.isEmpty = false
  61. for (var i = 0, j = response.data.length; i < j; i += this.pageSize) {
  62. this.recommendList.push(response.data.slice(i, i + this.pageSize));
  63. }
  64. console.log(this.recommendList)
  65. }else{
  66. this.isEmpty = true
  67. }
  68. }).catch(error =>{
  69. this.$util.msg(error.msg,2000)
  70. })
  71. },
  72. //轮播图切换修改背景色
  73. swiperChange(e) {
  74. const index = e.detail.current;
  75. this.current = index;
  76. },
  77. navToDetailPage(id) {//跳转商品详情页
  78. this.$api.navigateTo(`/pages/goods/product?id=${id}`)
  79. }
  80. }
  81. }
  82. </script>
  83. <style lang="scss">
  84. .recommend{
  85. background: #FFFFFF;
  86. width: 100%;
  87. .recommend-empty{
  88. width: 702rpx;
  89. height: 100rpx;
  90. line-height: 100rpx;
  91. padding: 0 24rpx;
  92. font-size: $font-size-28;
  93. color: #999999;
  94. text-align: center;
  95. }
  96. .recommend-list{
  97. width: 100%;
  98. height: auto;
  99. position: relative;
  100. padding-bottom: 20rpx;
  101. .tui-banner-swiper {
  102. width: 702rpx;
  103. margin: 0 auto;
  104. background: #F7F7F7;
  105. padding: 20rpx 24rpx;
  106. height: 900rpx;
  107. overflow: hidden;
  108. transform: translateY(0);
  109. .row-list{
  110. width: 340rpx;
  111. height: auto;
  112. float: left;
  113. margin-right: 20rpx;
  114. margin-bottom: 20rpx;
  115. border-radius: 20rpx;
  116. background: #FFFFFF;
  117. &:nth-child(2n){
  118. margin-right: 0;
  119. }
  120. .list-image{
  121. width: 100%;
  122. height: 340rpx;
  123. border-radius: 20rpx 20rpx 0 0;
  124. image{
  125. width: 100%;
  126. height: 340rpx;
  127. border-radius: 20rpx 20rpx 0 0;
  128. }
  129. }
  130. .list-name{
  131. font-size: $font-size-28;
  132. color: $text-color;
  133. line-height:88rpx;
  134. padding: 0 10rpx;
  135. overflow: hidden;
  136. white-space: nowrap;
  137. text-overflow: ellipsis;
  138. }
  139. }
  140. }
  141. }
  142. .swiper__recommenddots-box{
  143. position: absolute;
  144. bottom: -20rpx;
  145. left: 0;
  146. right: 0;
  147. /* #ifndef APP-NVUE */
  148. display: flex;
  149. /* #endif */
  150. flex: 1;
  151. flex-direction: row;
  152. justify-content: center;
  153. align-items: center;
  154. height: 60rpx;
  155. background: #FFFFFF;
  156. .swiper__dots-item{
  157. width: 8rpx;
  158. height: 8rpx;
  159. border-radius: 100%;
  160. margin-left: 6px;
  161. background-color:rgba(0,0,0,.3);
  162. }
  163. .swiper__dots-long{
  164. width: 32rpx;
  165. height: 8rpx;
  166. border-radius: 4rpx;
  167. background-color: #000;
  168. transition: all 0.4s;
  169. }
  170. }
  171. }
  172. </style>