similarGoods.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <template>
  2. <view class="similar-goods">
  3. <view class="goods" @click="goDetail(goods.goods_id)">
  4. <image :src="goods.goods_img" mode=""></image>
  5. <view class="goods-intro">
  6. <view>{{goods.goodsName}}</view>
  7. <view>{{goods.goods_sn}}</view>
  8. <view>¥{{goods.goods_price | unitPrice}}</view>
  9. </view>
  10. <!-- <button>找相似</button> -->
  11. </view>
  12. <view class="title">相似好货&nbsp;为您推荐</view>
  13. <view class="scroll-con">
  14. <view v-if="nomsg">没有相似商品</view>
  15. <view v-else class="con" v-for="(item,index) in goodsList" :key="index" @click="goDetail(item)">
  16. <image :src="item.thumbnail" mode=""></image>
  17. <view class="nowrap">{{item.name}}</view>
  18. <view>
  19. <text>¥{{item.price | unitPrice}}
  20. <!-- <text v-if="item.point">+{{item.point || 0}}积分</text> -->
  21. </text>
  22. <text>¥{{item.mktprice}}</text>
  23. </view>
  24. <view>
  25. <text>已售{{item.buy_count}}件</text>
  26. <text>{{item.grade}}%好评</text>
  27. </view>
  28. </view>
  29. </view>
  30. <uni-load-more :status="loadStatus"></uni-load-more>
  31. </view>
  32. </template>
  33. <script>
  34. import {
  35. getGoodsList
  36. } from '@/api/goods.js';
  37. export default {
  38. data() {
  39. return {
  40. loadStatus: 'more',
  41. params: {
  42. pageNumber: 1,
  43. pageSize: 10,
  44. keyword: ''
  45. },
  46. goods: {},
  47. goodsList: [],
  48. nomsg: false,
  49. };
  50. },
  51. methods: {
  52. getList() {
  53. uni.showLoading({
  54. title: "加载中"
  55. })
  56. this.params.keyword = this.goods.goodsName;
  57. getGoodsList(this.params).then(res => {
  58. uni.hideLoading()
  59. if (res.statusCode == 200) {
  60. let data = res.data;
  61. if (data.data_total == 0) {
  62. // this.nomsg = true;
  63. this.loadStatus = 'noMore';
  64. } else if (data.data_total < 10) {
  65. this.loadStatus = 'noMore'
  66. this.goodsList.push(...data.data)
  67. } else {
  68. this.goodsList.push(...data.data);
  69. if (data.data.length < 10) this.loadStatus = 'noMore'
  70. }
  71. }
  72. })
  73. },
  74. goDetail(item) {
  75. uni.navigateTo({
  76. url: '/pages/product/goods?id=' + item.id + "&goodsId=" +item.goodsId
  77. })
  78. },
  79. loadData() {
  80. if(this.loadStatus!='noMore'){
  81. this.params.pageNumber++;
  82. this.getList()
  83. }
  84. },
  85. },
  86. onLoad(option) {
  87. this.goods = JSON.parse(decodeURIComponent(option.goods))
  88. this.getList()
  89. },
  90. onReachBottom() { //触底事件,页面整个滚动使用
  91. this.loadData()
  92. }
  93. }
  94. </script>
  95. <style lang="scss" scoped>
  96. @import './collect.scss';
  97. .title {
  98. height: 110rpx;
  99. line-height: 110rpx;
  100. text-align: center;
  101. color: #333;
  102. background-color: #F1F1F1;
  103. margin-top: 20rpx;
  104. font-size: $font-base;
  105. }
  106. .goods {
  107. padding: 0 30rpx;
  108. }
  109. .scroll-con {
  110. width: 750rpx;
  111. flex-wrap: wrap;
  112. .con {
  113. width: 345rpx;
  114. margin: 20rpx 0 0 20rpx;
  115. background-color: #FFFFFF;
  116. border-radius: 10rpx;
  117. box-sizing: border-box;
  118. display: inline-block;
  119. font-size: $font-sm;
  120. // line-height: 1.5em;
  121. image {
  122. width: 100%;
  123. height: 320rpx;
  124. border-radius: 8rpx 8rpx 0 0;
  125. }
  126. view{
  127. padding: 0 20rpx;
  128. &::after{
  129. content: '';
  130. display: block;
  131. clear: right;
  132. }
  133. text {
  134. display: inline-block;
  135. color: #999;
  136. }
  137. text:nth-child(2) {
  138. float: right;
  139. text-align: right;
  140. }
  141. }
  142. view:last-child{
  143. margin-bottom: 20rpx;
  144. }
  145. .nowrap {
  146. position: relative;
  147. line-height: 1.4em;
  148. max-height: 2.8em; //height是line-height的整数倍,防止文字显示不全
  149. overflow: hidden;
  150. }
  151. view:nth-child(2) {
  152. font-size: 26rpx;
  153. }
  154. view:nth-child(3) {
  155. margin-top: 10rpx;
  156. font-weight: bold;
  157. text:nth-child(1) {
  158. color: #f56c6c;
  159. }
  160. text:nth-child(2) {
  161. color: #d7d7d7;
  162. text-decoration: line-through;
  163. }
  164. }
  165. view:nth-child(4) {
  166. margin-top: 10rpx;
  167. }
  168. }
  169. }
  170. </style>