footprint.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <template>
  2. <view class="container">
  3. <!-- 空白页 -->
  4. <view style="padding: 150rpx 0rpx;" v-if="loadingType === 'nomore' && footprintList.length === 0">
  5. <missing v-if="loadingType === 'nomore' && footprintList.length === 0"
  6. :imgUrl="'http://qiniuoss.nauzone.cn/%E7%BB%84%203%20%E6%8B%B7%E8%B4%9D@3x.png'" :desc="'暂无浏览足迹哦!'"></missing>
  7. </view>
  8. <view class="footprint-list">
  9. <block v-for="(item, index) in footprintList" :key="index">
  10. <view class="footprint-item" :class="{'b-b': index!==footprintList.length-1}">
  11. <view class="image-wrapper" style="width: 180rpx;height: 180rpx;">
  12. <image :src="JSON.parse(item.img)[0].url" :class="[item.loaded]" mode="aspectFill" lazy-load
  13. @load="onImageLoad('footprintList', index)" @error="onImageError('footprintList', index)"
  14. style="width: 180rpx;height: 180rpx;"></image>
  15. </view>
  16. <view class="item-right">
  17. <text class="clamp title">{{item.productName}}</text>
  18. <text class="attr text-cut">{{item.description}}</text>
  19. <text class="attr">累计销售{{item.sales}}件</text>
  20. <text class="attr">浏览时间:{{item.updateTime}}</text>
  21. <text class="price"><text v-if="item.otPrice > (isVip?item.vipPrice:item.price)"
  22. style="text-decoration:line-through;color: #909399;margin-right: 20rpx;">¥{{item.otPrice}}</text>
  23. ¥{{(isVip?(item.vipPrice + ' [VIP]'):item.price)}}</text>
  24. </view>
  25. <text class="del-btn yticon icon-fork" @click="deleteFootprint(item)"></text>
  26. </view>
  27. </block>
  28. </view>
  29. </view>
  30. </template>
  31. <script>
  32. import missing from '@/components/missing.vue'
  33. export default {
  34. components: {
  35. missing
  36. },
  37. data() {
  38. return {
  39. footprintList: [],
  40. pageNo: 1,
  41. loadingType: 'more',
  42. isVip: false
  43. };
  44. },
  45. onShow() {
  46. this.isVip = this.$api.isVip()
  47. },
  48. onLoad(options) {
  49. this.loadData()
  50. },
  51. //下拉刷新
  52. onPullDownRefresh() {
  53. this.loadData('refresh');
  54. },
  55. //加载更多
  56. onReachBottom() {
  57. this.loadData();
  58. },
  59. methods: {
  60. //获取足迹列表
  61. loadData(type) {
  62. const that = this
  63. if (type === 'refresh') {
  64. that.pageNo = 1
  65. that.footprintList = []
  66. that.loadingType = 'more'
  67. }
  68. this.pageSize = 10
  69. if (that.loadingType === 'more') {
  70. that.loadingType = 'loading'
  71. that.$api.request('get', 'user/userFootprint/getFootprintAll', {
  72. pageNum: that.pageNo,
  73. pageSize: this.pageSize
  74. }).then(res => {
  75. that.pageNo = that.pageNo + 1
  76. that.loadingType = that.pageNo < res.total / this.pageSize + (res.total % this.pageSize == 0 ? 0 : 1) ?
  77. 'more' : 'nomore'
  78. res.rows.forEach(item => {
  79. that.footprintList.push(item);
  80. })
  81. if (type === 'refresh') {
  82. uni.stopPullDownRefresh();
  83. }
  84. })
  85. }
  86. },
  87. //删除足迹
  88. deleteFootprint(item) {
  89. const that = this
  90. uni.showModal({
  91. title: '提示',
  92. content: '确定要删除这条足迹记录吗?',
  93. success: function(res) {
  94. if (res.confirm) {
  95. that.$api.request('post', 'user/userFootprint/deleteFootprint', {
  96. id: item.id
  97. }).then(res => {
  98. uni.showToast({
  99. title: '删除成功',
  100. icon: 'success'
  101. });
  102. that.loadData('refresh');
  103. })
  104. }
  105. }
  106. });
  107. },
  108. //监听image加载完成
  109. onImageLoad(key, index) {
  110. this.$set(this[key][index], 'loaded', 'loaded');
  111. },
  112. //监听image加载失败
  113. onImageError(key, index) {
  114. this[key][index].image = '/static/errorImage.jpg';
  115. },
  116. },
  117. }
  118. </script>
  119. <style lang="scss">
  120. .container {
  121. padding-bottom: 134upx;
  122. }
  123. /* 足迹列表项 */
  124. .footprint-item {
  125. display: flex;
  126. position: relative;
  127. padding: 30upx 40upx;
  128. .image-wrapper {
  129. width: 230upx;
  130. height: 230upx;
  131. flex-shrink: 0;
  132. position: relative;
  133. image {
  134. border-radius: 8upx;
  135. }
  136. }
  137. .item-right {
  138. display: flex;
  139. flex-direction: column;
  140. flex: 1;
  141. overflow: hidden;
  142. position: relative;
  143. padding-left: 30upx;
  144. .title,
  145. .price {
  146. font-size: $font-base + 2upx;
  147. color: $font-color-dark;
  148. height: 40upx;
  149. line-height: 40upx;
  150. }
  151. .attr {
  152. font-size: $font-sm + 2upx;
  153. color: $font-color-light;
  154. height: 50upx;
  155. line-height: 50upx;
  156. }
  157. .price {
  158. height: 50upx;
  159. line-height: 50upx;
  160. }
  161. }
  162. .del-btn {
  163. position: absolute;
  164. right: 30upx;
  165. top: 30upx;
  166. color: $font-color-disabled;
  167. font-size: 40upx;
  168. }
  169. }
  170. </style>