favorites.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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 >¥</text>
  12. <text style="font-size: 40rpx;">{{ ls.price }}</text>
  13. </view>
  14. <view @click.prevent.stop="del(ls.pid)">
  15. <image src="../../static/img/aixin.png"></image>
  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: false
  36. };
  37. },
  38. onLoad() {
  39. this.loadData();
  40. },
  41. methods: {
  42. onNavigationBarButtonTap(){
  43. if(this.delshow == false){
  44. this.delshow = true;
  45. }
  46. else{
  47. this.delshow = false;
  48. }
  49. },
  50. //获取收藏夹列表
  51. loadData() {
  52. let obj = this;
  53. getcollectList({
  54. page: '1',
  55. limit: '10'
  56. })
  57. .then(function(e) {
  58. obj.favoriteList = e.data;
  59. console.log(obj.favoriteList,9);
  60. })
  61. .catch(function(e) {
  62. console.log(e);
  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. })
  76. .then(function(e) {
  77. uni.showToast({
  78. title: '已取消收藏',
  79. duration: 1500,
  80. });
  81. obj.loadData();
  82. })
  83. .catch(function(e) {
  84. console.log(e);
  85. });
  86. }
  87. }
  88. });
  89. },
  90. //跳转商品详情页
  91. toproduct(item) {
  92. let id = item;
  93. let type = 2;
  94. uni.navigateTo({
  95. // url: `/pages/product/product?id=${id}`
  96. url: '/pages/product/product?id=' + item.pid +'&type=' + type
  97. });
  98. }
  99. // //跳转忘记密码
  100. // forget() {
  101. // uni.navigateTo({
  102. // url: `/pages/public/forget`
  103. // });
  104. // },
  105. // // 后退
  106. // navBack() {
  107. // uni.navigateBack();
  108. // }
  109. }
  110. };
  111. </script>
  112. <style lang="scss">
  113. .uni-page-head-ft{
  114. margin-right: 10px !important;
  115. }
  116. page {
  117. height: 100%;
  118. }
  119. .del-btn{
  120. font-size: 30rpx;
  121. }
  122. %flex-center {
  123. display: flex;
  124. flex-direction: column;
  125. justify-content: center;
  126. align-items: center;
  127. }
  128. %section {
  129. display: flex;
  130. justify-content: space-around;
  131. align-content: center;
  132. background: #fff;
  133. border-radius: 10rpx;
  134. }
  135. .container {
  136. height: 100%;
  137. background-color: $page-color-base;
  138. padding: 15rpx 0rpx;
  139. font-size: 28rpx;
  140. }
  141. .favorites {
  142. background-color: #ffffff;
  143. border-radius: 15rpx;
  144. margin: 15rpx 25rpx 25rpx 25rpx;
  145. padding: 25rpx 25rpx;
  146. }
  147. .favorites_img {
  148. width: 80px !important;
  149. height: 80px;
  150. }
  151. .favorites_img image {
  152. width: 100%;
  153. height: 100%;
  154. }
  155. .favorites_list {
  156. width: 70%;
  157. padding-left: 20rpx;
  158. }
  159. .icon_del {
  160. color: #999;
  161. }
  162. .favorites_name {
  163. font-size: 28rpx;
  164. overflow: hidden;
  165. line-height: 40rpx;
  166. text-overflow: ellipsis;
  167. display: -webkit-box;
  168. -webkit-box-orient: vertical;
  169. -webkit-line-clamp: 2;
  170. }
  171. .favorites_peice {
  172. margin-top:45rpx;
  173. font-size: 30rpx;
  174. color: #FA2740;
  175. image{
  176. width: 30rpx;
  177. height: 30rpx;
  178. }
  179. }
  180. </style>