secondRecommend.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. export default{
  29. name:'recommend',
  30. props:{
  31. queryProductid: {
  32. // Unistars类型
  33. type: Number,
  34. default: 0
  35. }
  36. },
  37. components:{
  38. tuiLoadmore,
  39. tuiNomore,
  40. },
  41. data() {
  42. return{
  43. current:0,
  44. recommendList:[],
  45. isEmpty:false,
  46. pageSize:4,
  47. productID:'',
  48. }
  49. },
  50. created() {
  51. this.productID = this.queryProductid
  52. this.infoRecommend(this.queryProductid)
  53. },
  54. methods:{
  55. infoRecommend(id){
  56. this.SellerService.ProductRecommend({productId:id}).then(response =>{
  57. console.log(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. console.log(this.recommendList)
  64. }else{
  65. this.isEmpty = true
  66. }
  67. }).catch(error =>{
  68. this.$util.msg(error.msg,2000)
  69. })
  70. },
  71. //轮播图切换修改背景色
  72. swiperChange(e) {
  73. const index = e.detail.current;
  74. this.current = index;
  75. },
  76. navToDetailPage(id) {//跳转商品详情页
  77. this.$api.navigateTo(`/pages/goods/product?id=${id}`)
  78. }
  79. }
  80. }
  81. </script>
  82. <style lang="scss">
  83. .recommend{
  84. background: #FFFFFF;
  85. width: 100%;
  86. .recommend-empty{
  87. width: 702rpx;
  88. height: 100rpx;
  89. line-height: 100rpx;
  90. padding: 0 24rpx;
  91. font-size: $font-size-28;
  92. color: #999999;
  93. text-align: center;
  94. }
  95. .recommend-list{
  96. width: 100%;
  97. height: auto;
  98. position: relative;
  99. padding-bottom: 20rpx;
  100. .tui-banner-swiper {
  101. width: 702rpx;
  102. margin: 0 auto;
  103. background: #F7F7F7;
  104. padding: 20rpx 24rpx;
  105. height: 900rpx;
  106. overflow: hidden;
  107. transform: translateY(0);
  108. .row-list{
  109. width: 340rpx;
  110. height: auto;
  111. float: left;
  112. margin-right: 20rpx;
  113. margin-bottom: 20rpx;
  114. border-radius: 20rpx;
  115. background: #FFFFFF;
  116. &:nth-child(2n){
  117. margin-right: 0;
  118. }
  119. .list-image{
  120. width: 100%;
  121. height: 340rpx;
  122. border-radius: 20rpx 20rpx 0 0;
  123. image{
  124. width: 100%;
  125. height: 340rpx;
  126. border-radius: 20rpx 20rpx 0 0;
  127. }
  128. }
  129. .list-name{
  130. font-size: $font-size-28;
  131. color: $text-color;
  132. line-height:88rpx;
  133. padding: 0 10rpx;
  134. overflow: hidden;
  135. white-space: nowrap;
  136. text-overflow: ellipsis;
  137. }
  138. }
  139. }
  140. }
  141. .swiper__recommenddots-box{
  142. position: absolute;
  143. bottom: -20rpx;
  144. left: 0;
  145. right: 0;
  146. /* #ifndef APP-NVUE */
  147. display: flex;
  148. /* #endif */
  149. flex: 1;
  150. flex-direction: row;
  151. justify-content: center;
  152. align-items: center;
  153. height: 60rpx;
  154. background: #FFFFFF;
  155. .swiper__dots-item{
  156. width: 8rpx;
  157. height: 8rpx;
  158. border-radius: 100%;
  159. margin-left: 6px;
  160. background-color:rgba(0,0,0,.3);
  161. }
  162. .swiper__dots-long{
  163. width: 32rpx;
  164. height: 8rpx;
  165. border-radius: 4rpx;
  166. background-color: #000;
  167. transition: all 0.4s;
  168. }
  169. }
  170. }
  171. </style>