secondRecommend.vue 4.2 KB

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