favorites.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. onShow() {
  39. this.loadData();
  40. },
  41. //下拉刷新
  42. onPullDownRefresh() {
  43. let obj = this;
  44. //监听下拉刷新动作的执行方法,每次手动下拉刷新都会执行一次
  45. setTimeout(function() {
  46. obj.loadData();
  47. uni.stopPullDownRefresh(); //停止下拉刷新动画
  48. }, 1000);
  49. },
  50. methods: {
  51. //获取收藏夹列表
  52. loadData() {
  53. let obj = this;
  54. getcollectList({
  55. page: '1',
  56. limit: '10'
  57. })
  58. .then(function(e) {
  59. obj.favoriteList = e.data;
  60. console.log(obj.favoriteList);
  61. })
  62. .catch(function(e) {
  63. console.log(e);
  64. });
  65. },
  66. //删除收藏夹商品
  67. del(item) {
  68. let obj = this;
  69. uni.showModal({
  70. title: '提示',
  71. content: '是否取消收藏该商品',
  72. success: e => {
  73. if (e.confirm) {
  74. delcollect({
  75. id: item,
  76. category: 'product'
  77. })
  78. .then(function(e) {
  79. uni.showToast({
  80. title: '已取消收藏',
  81. duration: 1500,
  82. icon:'none'
  83. });
  84. obj.loadData();
  85. })
  86. .catch(function(e) {
  87. console.log(e);
  88. });
  89. }
  90. }
  91. });
  92. },
  93. //跳转商品详情页
  94. toproduct(item) {
  95. let id = item;
  96. uni.navigateTo({
  97. url: `/pages/product/product?id=${id}`
  98. });
  99. }
  100. // //跳转忘记密码
  101. // forget() {
  102. // uni.navigateTo({
  103. // url: `/pages/public/forget`
  104. // });
  105. // },
  106. // // 后退
  107. // navBack() {
  108. // uni.navigateBack();
  109. // }
  110. }
  111. };
  112. </script>
  113. <style lang="scss">
  114. page {
  115. height: 100%;
  116. }
  117. %flex-center {
  118. display: flex;
  119. flex-direction: column;
  120. justify-content: center;
  121. align-items: center;
  122. }
  123. %section {
  124. display: flex;
  125. justify-content: space-around;
  126. align-content: center;
  127. background: #fff;
  128. border-radius: 10rpx;
  129. }
  130. .container {
  131. height: 100%;
  132. background-color: $page-color-base;
  133. padding: 15rpx 0rpx;
  134. font-size: 28rpx;
  135. }
  136. .favorites {
  137. width: 90%;
  138. background-color: #ffffff;
  139. // height:100%;
  140. border-radius: 15rpx;
  141. margin: 15rpx auto;
  142. padding: 25rpx 25rpx;
  143. margin-bottom: 25rpx;
  144. }
  145. .favorites_img {
  146. width: 80px !important;
  147. height: 80px;
  148. }
  149. .favorites_img image {
  150. width: 100%;
  151. height: 100%;
  152. }
  153. .favorites_list {
  154. width: 70%;
  155. padding-left: 20rpx;
  156. }
  157. .icon_del {
  158. color: $font-color-base;
  159. z-index: 9999;
  160. font-weight: bold;
  161. }
  162. .favorites_name {
  163. height: 80rpx;
  164. overflow: hidden;
  165. text-overflow: ellipsis;
  166. display: -webkit-box;
  167. -webkit-box-orient: vertical;
  168. -webkit-line-clamp: 2;
  169. }
  170. .favorites_peice {
  171. margin-top: 25rpx;
  172. color: #db1935;
  173. font-weight: bold;
  174. }
  175. </style>