collect.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <template>
  2. <view class="container">
  3. <view class="collect-list" v-if="collectList.length>0">
  4. <view class="item" @tap="openGoods" @touchstart="touchStart" @touchend="touchEnd" v-for="(item, index) in collectList"
  5. :key="item.id" :data-index="index">
  6. <image class="img" :src="item.list_pic_url"></image>
  7. <view class="info">
  8. <view class="name">{{item.name||''}}</view>
  9. <view class="subtitle">{{item.goods_brief||''}}</view>
  10. <view class="price">¥{{item.retail_price||''}}</view>
  11. </view>
  12. </view>
  13. </view>
  14. <show-empty v-else text="暂无收藏"></show-empty>
  15. </view>
  16. </template>
  17. <script>
  18. const util = require("@/utils/util.js");
  19. const api = require('@/utils/api.js');
  20. export default {
  21. data() {
  22. return {
  23. typeId: 0,
  24. collectList: []
  25. }
  26. },
  27. methods: {
  28. getCollectList() {
  29. let that = this;
  30. util.request(api.CollectList, {
  31. typeId: that.typeId
  32. }).then(function(res) {
  33. if (res.errno === 0) {
  34. that.collectList = res.data;
  35. }
  36. });
  37. },
  38. openGoods(event) {
  39. let that = this;
  40. let goodsId = that.collectList[event.currentTarget.dataset.index].value_id;
  41. //触摸时间距离页面打开的毫秒数
  42. var touchTime = that.touch_end - that.touch_start;
  43. //如果按下时间大于350为长按
  44. if (touchTime > 350) {
  45. uni.showModal({
  46. title: '',
  47. content: '确定删除收藏吗?',
  48. success: function(res) {
  49. if (res.confirm) {
  50. util.request(api.CollectAddOrDelete, {
  51. typeId: that.typeId,
  52. valueId: goodsId
  53. }, "POST", "application/json").then(function(res) {
  54. if (res.errno === 0) {
  55. uni.showToast({
  56. title: '删除成功',
  57. icon: 'success',
  58. duration: 2000
  59. });
  60. that.getCollectList();
  61. }
  62. });
  63. }
  64. }
  65. })
  66. } else {
  67. uni.navigateTo({
  68. url: '/pages/goods/goods?id=' + goodsId,
  69. });
  70. }
  71. },
  72. //按下事件开始
  73. touchStart: function(e) {
  74. let that = this;
  75. that.touch_start = e.timeStamp
  76. },
  77. //按下事件结束
  78. touchEnd: function(e) {
  79. let that = this;
  80. that.touch_end = e.timeStamp
  81. }
  82. },
  83. onPullDownRefresh() {
  84. var self = this;
  85. this.getCollectList();
  86. },
  87. onShow: function() {
  88. this.getCollectList();
  89. }
  90. }
  91. </script>
  92. <style lang="scss">
  93. page {
  94. background: #f4f4f4;
  95. min-height: 100%;
  96. }
  97. .container {
  98. background: #f4f4f4;
  99. min-height: 100%;
  100. }
  101. .collect-list {
  102. width: 100%;
  103. height: auto;
  104. overflow: hidden;
  105. background: #fff;
  106. padding-left: 30rpx;
  107. border-top: 1px solid #e1e1e1;
  108. }
  109. .item {
  110. height: 212rpx;
  111. width: 720rpx;
  112. background: #fff;
  113. padding: 30rpx 30rpx 30rpx 0;
  114. border-bottom: 1px solid #e1e1e1;
  115. }
  116. .item:last-child {
  117. border-bottom: 1px solid #fff;
  118. }
  119. .item .img {
  120. float: left;
  121. width: 150rpx;
  122. height: 150rpx;
  123. }
  124. .item .info {
  125. float: right;
  126. width: 540rpx;
  127. height: 150rpx;
  128. display: flex;
  129. flex-direction: column;
  130. justify-content: center;
  131. padding-left: 20rpx;
  132. }
  133. .item .info .name {
  134. font-size: 28rpx;
  135. color: #333;
  136. line-height: 40rpx;
  137. }
  138. .item .info .subtitle {
  139. margin-top: 8rpx;
  140. font-size: 24rpx;
  141. color: #888;
  142. line-height: 40rpx;
  143. }
  144. .item .info .price {
  145. margin-top: 8rpx;
  146. font-size: 28rpx;
  147. color: #333;
  148. line-height: 40rpx;
  149. }
  150. </style>