favorites.vue 3.1 KB

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