recommend.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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.id)">
  9. <view class="list-image"><image :src="pros.image" 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.ProductService.queryProductDetilsRelevant({productId:id,recommendType:0}).then(response =>{
  58. if( response.data && response.data.length > 0){
  59. this.isEmpty = false
  60. for (var i = 0, j = response.data.length; i < j; i += this.pageSize) {
  61. this.recommendList.push(response.data.slice(i, i + this.pageSize));
  62. }
  63. }else{
  64. this.isEmpty = true
  65. }
  66. }).catch(error =>{
  67. this.$util.msg(error.msg,2000)
  68. })
  69. },
  70. //轮播图切换修改背景色
  71. swiperChange(e) {
  72. const index = e.detail.current;
  73. this.current = index;
  74. },
  75. navToDetailPage(id) {//跳转商品详情页
  76. this.$api.navigateTo(`/pages/goods/product?id=${id}`)
  77. }
  78. }
  79. }
  80. </script>
  81. <style lang="scss">
  82. .recommend{
  83. background: #FFFFFF;
  84. width: 100%;
  85. .recommend-empty{
  86. width: 702rpx;
  87. height: 100rpx;
  88. line-height: 100rpx;
  89. padding: 0 24rpx;
  90. font-size: $font-size-28;
  91. color: #999999;
  92. text-align: center;
  93. }
  94. .recommend-list{
  95. width: 100%;
  96. height: auto;
  97. position: relative;
  98. padding-bottom: 20rpx;
  99. .tui-banner-swiper {
  100. width: 702rpx;
  101. margin: 0 auto;
  102. background: #F7F7F7;
  103. padding: 20rpx 24rpx;
  104. height: 900rpx;
  105. overflow: hidden;
  106. transform: translateY(0);
  107. .row-list{
  108. width: 340rpx;
  109. height: auto;
  110. float: left;
  111. margin-right: 20rpx;
  112. margin-bottom: 20rpx;
  113. border-radius: 20rpx;
  114. background: #FFFFFF;
  115. &:nth-child(2n){
  116. margin-right: 0;
  117. }
  118. .list-image{
  119. width: 100%;
  120. height: 340rpx;
  121. border-radius: 20rpx 20rpx 0 0;
  122. image{
  123. width: 100%;
  124. height: 340rpx;
  125. border-radius: 20rpx 20rpx 0 0;
  126. }
  127. }
  128. .list-name{
  129. font-size: $font-size-28;
  130. color: $text-color;
  131. line-height:88rpx;
  132. padding: 0 10rpx;
  133. overflow: hidden;
  134. white-space: nowrap;
  135. text-overflow: ellipsis;
  136. }
  137. }
  138. }
  139. }
  140. .swiper__recommenddots-box{
  141. position: absolute;
  142. bottom: -20rpx;
  143. left: 0;
  144. right: 0;
  145. /* #ifndef APP-NVUE */
  146. display: flex;
  147. /* #endif */
  148. flex: 1;
  149. flex-direction: row;
  150. justify-content: center;
  151. align-items: center;
  152. height: 60rpx;
  153. background: #FFFFFF;
  154. .swiper__dots-item{
  155. width: 8rpx;
  156. height: 8rpx;
  157. border-radius: 100%;
  158. margin-left: 6px;
  159. background-color:rgba(0,0,0,.3);
  160. }
  161. .swiper__dots-long{
  162. width: 32rpx;
  163. height: 8rpx;
  164. border-radius: 4rpx;
  165. background-color: #000;
  166. transition: all 0.4s;
  167. }
  168. }
  169. }
  170. </style>