favorite.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <template>
  2. <view class="container">
  3. <!-- 空白页 -->
  4. <!-- <empty v-if="loadingType === 'nomore' && favoriteList.length === 0"></empty> -->
  5. <view style="padding: 150rpx 0rpx;" v-if="loadingType === 'nomore' && favoriteList.length === 0">
  6. <missing v-if="loadingType === 'nomore' && favoriteList.length === 0"
  7. :imgUrl="'http://qiniuoss.nauzone.cn/%E7%BB%84%203%20%E6%8B%B7%E8%B4%9D@3x.png'" :desc="'暂时没有收藏商品哦!'"></missing>
  8. </view>
  9. <view class="favorite-list">
  10. <block v-for="(item, index) in favoriteList" :key="index">
  11. <view class="favorite-item" :class="{'b-b': index!==favoriteList.length-1}">
  12. <view class="image-wrapper" style="width: 180rpx;height: 180rpx;">
  13. <image :src="JSON.parse(item.img)[0].url" :class="[item.loaded]" mode="aspectFill" lazy-load
  14. @load="onImageLoad('favoriteList', index)" @error="onImageError('favoriteList', index)"
  15. style="width: 180rpx;height: 180rpx;"></image>
  16. </view>
  17. <view class="item-right">
  18. <text class="clamp title">{{item.productName}}</text>
  19. <text class="attr text-cut">{{item.description}}</text>
  20. <text class="attr">累计销售{{item.sales}}件</text>
  21. <text class="price"><text v-if="item.otPrice > (isVip?item.vipPrice:item.price)"
  22. style="text-decoration:line-through;color: #909399;margin-right: 20rpx;">¥{{item.otPrice}}</text>
  23. ¥{{(isVip?(item.vipPrice + ' [VIP]'):item.price)}}</text>
  24. </view>
  25. <text class="del-btn yticon icon-fork" @click="deleteFavorite(item)"></text>
  26. </view>
  27. </block>
  28. </view>
  29. </view>
  30. </template>
  31. <script>
  32. // import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
  33. import missing from '@/components/missing.vue'
  34. // import empty from "@/components/empty";
  35. export default {
  36. components: {
  37. // uniLoadMore,
  38. missing
  39. // empty
  40. },
  41. data() {
  42. return {
  43. favoriteList: [],
  44. pageNo: 1,
  45. loadingType: 'more',
  46. isVip: false
  47. };
  48. },
  49. onShow() {
  50. this.isVip = this.$api.isVip()
  51. },
  52. onLoad(options) {
  53. this.loadData()
  54. },
  55. //下拉刷新
  56. onPullDownRefresh() {
  57. this.loadData('refresh');
  58. },
  59. //加载更多
  60. onReachBottom() {
  61. this.loadData();
  62. },
  63. methods: {
  64. //获取收藏列表
  65. loadData(type) {
  66. const that = this
  67. if (type === 'refresh') {
  68. that.pageNo = 1
  69. that.favoriteList = []
  70. that.loadingType = 'more'
  71. }
  72. this.pageSize = 10
  73. if (that.loadingType === 'more') {
  74. that.loadingType = 'loading'
  75. that.$api.request('get', 'user/userCollect/getCollectAll', {
  76. pageNum: that.pageNo,
  77. pageSize: this.pageSize
  78. }).then(res => {
  79. that.pageNo = that.pageNo + 1
  80. that.loadingType = that.pageNo < res.total / this.pageSize + (res.total % this.pageSize == 0 ? 0 : 1) ?
  81. 'more' : 'nomore'
  82. res.rows.forEach(item => {
  83. that.favoriteList.push(item);
  84. if (type === 'refresh') {
  85. uni.stopPullDownRefresh();
  86. }
  87. })
  88. })
  89. }
  90. },
  91. deleteFavorite(item) {
  92. const that = this
  93. that.$api.request('post', 'user/userCollect/deleteCollect', {
  94. productId: item.productId
  95. }).then(res => {
  96. that.loadData('refresh')
  97. })
  98. },
  99. //监听image加载完成
  100. onImageLoad(key, index) {
  101. this.$set(this[key][index], 'loaded', 'loaded');
  102. },
  103. //监听image加载失败
  104. onImageError(key, index) {
  105. this[key][index].image = '/static/errorImage.jpg';
  106. },
  107. },
  108. }
  109. </script>
  110. <style lang="scss">
  111. .container {
  112. padding-bottom: 134upx;
  113. /* 空白页 */
  114. .empty {
  115. position: fixed;
  116. left: 0;
  117. top: 0;
  118. width: 100%;
  119. height: 100vh;
  120. padding-bottom: 100upx;
  121. display: flex;
  122. justify-content: center;
  123. flex-direction: column;
  124. align-items: center;
  125. background: #fff;
  126. image {
  127. width: 240upx;
  128. height: 160upx;
  129. margin-bottom: 30upx;
  130. }
  131. .empty-tips {
  132. display: flex;
  133. font-size: $font-sm+2upx;
  134. color: $font-color-disabled;
  135. .navigator {
  136. color: $uni-color-primary;
  137. margin-left: 16upx;
  138. }
  139. }
  140. }
  141. }
  142. /* 收藏列表项 */
  143. .favorite-item {
  144. display: flex;
  145. position: relative;
  146. padding: 30upx 40upx;
  147. .image-wrapper {
  148. width: 230upx;
  149. height: 230upx;
  150. flex-shrink: 0;
  151. position: relative;
  152. image {
  153. border-radius: 8upx;
  154. }
  155. }
  156. .checkbox {
  157. position: absolute;
  158. left: -16upx;
  159. top: -16upx;
  160. z-index: 8;
  161. font-size: 44upx;
  162. line-height: 1;
  163. padding: 4upx;
  164. color: $font-color-disabled;
  165. background: #fff;
  166. border-radius: 50px;
  167. }
  168. .item-right {
  169. display: flex;
  170. flex-direction: column;
  171. flex: 1;
  172. overflow: hidden;
  173. position: relative;
  174. padding-left: 30upx;
  175. .title,
  176. .price {
  177. font-size: $font-base + 2upx;
  178. color: $font-color-dark;
  179. height: 40upx;
  180. line-height: 40upx;
  181. }
  182. .attr {
  183. font-size: $font-sm + 2upx;
  184. color: $font-color-light;
  185. height: 50upx;
  186. line-height: 50upx;
  187. }
  188. .price {
  189. height: 50upx;
  190. line-height: 50upx;
  191. }
  192. }
  193. }
  194. </style>