secondRecommend.vue 4.2 KB

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