favorites.vue 3.1 KB

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