favorites.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <template>
  2. <view class="container">
  3. <!-- 空白页 -->
  4. <empty v-if="favoriteList.length < 1"></empty>
  5. <view class="favorites flex" v-for="ls in favoriteList" @click="toproduct(ls.pid)">
  6. <view class="favorites_img"><image :src="ls.image"></image></view>
  7. <view class="favorites_list">
  8. <view class="favorites_name">{{ ls.store_name }}</view>
  9. <view class="favorites_peice flex">
  10. <view>
  11. <text v-if="ls.integral != 0">¥{{ ls.price }} + {{ ls.integral }}消费补贴券</text>
  12. <text v-else>¥{{ ls.price }}</text>
  13. </view>
  14. <view class="icon_del" @click.prevent.stop="del(ls.pid)" v-show="delshow">
  15. <text class="iconfont icondelete"></text>
  16. <text>取消</text>
  17. </view>
  18. </view>
  19. </view>
  20. </view>
  21. </view>
  22. </template>
  23. <script>
  24. import { getcollectList, delcollect } from '@/api/user.js';
  25. import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
  26. import empty from '@/components/empty';
  27. export default {
  28. components: {
  29. uniLoadMore,
  30. empty
  31. },
  32. data() {
  33. return {
  34. tabCurrentIndex: 0,
  35. favoriteList: '',
  36. delshow: true
  37. };
  38. },
  39. onLoad() {
  40. this.loadData();
  41. },
  42. methods: {
  43. //获取收藏夹列表
  44. loadData() {
  45. let obj = this;
  46. getcollectList({
  47. page: '1',
  48. limit: '10'
  49. })
  50. .then(function(e) {
  51. obj.favoriteList = e.data;
  52. console.log(obj.favoriteList);
  53. })
  54. .catch(function(e) {
  55. console.log(e);
  56. });
  57. },
  58. //跳转商品详情页
  59. toproduct(item) {
  60. let id = item;
  61. uni.navigateTo({
  62. url: `/pages/product/product?id=${id}`
  63. })
  64. },
  65. //删除收藏夹商品
  66. del(item) {
  67. let obj = this;
  68. uni.showModal({
  69. title: '提示',
  70. content: '是否取消收藏该商品',
  71. success: e => {
  72. if (e.confirm) {
  73. delcollect({
  74. id: item,
  75. category: 'product'
  76. })
  77. .then(function(e) {
  78. uni.showToast({
  79. title: '已取消收藏',
  80. duration: 1500,
  81. });
  82. obj.loadData();
  83. })
  84. .catch(function(e) {
  85. console.log(e);
  86. });
  87. }
  88. }
  89. });
  90. },
  91. }
  92. }
  93. </script>
  94. <style lang="scss">
  95. page {
  96. height: 100%;
  97. }
  98. %flex-center {
  99. display: flex;
  100. flex-direction: column;
  101. justify-content: center;
  102. align-items: center;
  103. }
  104. %section {
  105. display: flex;
  106. justify-content: space-around;
  107. align-content: center;
  108. background: #fff;
  109. border-radius: 10rpx;
  110. }
  111. .container {
  112. height: 100%;
  113. background-color: $page-color-base;
  114. padding: 15rpx 0rpx;
  115. font-size: 28rpx;
  116. }
  117. .favorites {
  118. width: 90%;
  119. background-color: #ffffff;
  120. border-radius: 15rpx;
  121. margin: 15rpx auto;
  122. padding: 25rpx 25rpx;
  123. margin-bottom: 25rpx;
  124. }
  125. .favorites_img {
  126. width: 80px !important;
  127. height: 80px;
  128. }
  129. .favorites_img image {
  130. width: 100%;
  131. height: 100%;
  132. }
  133. .favorites_list {
  134. width: 70%;
  135. padding-left: 20rpx;
  136. }
  137. .icon_del {
  138. color: $font-color-base;
  139. z-index: 9999;
  140. font-weight: bold;
  141. }
  142. .favorites_name {
  143. height: 80rpx;
  144. overflow: hidden;
  145. text-overflow: ellipsis;
  146. display: -webkit-box;
  147. -webkit-box-orient: vertial;
  148. -webkit-line-clamp: 2;
  149. }
  150. .favorites_peice {
  151. margin-top: 25rpx;
  152. color: #db1935;
  153. font-weight: bold;
  154. }
  155. </style>