favorite.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. <template>
  2. <view class="content">
  3. <scroll-view class="list-scroll-content" scroll-y @scrolltolower="loadData">
  4. <!-- 空白页 -->
  5. <empty v-if="favorite.loaded === true && favorite.list.length === 0"></empty>
  6. <!-- 产品列表 -->
  7. <view v-for="(item, index) in favorite.list" :key="index" class="order-item">
  8. <view class="info" @click="navToDetailPage(item.product.product_id, item.status)">
  9. <view class="image">
  10. <image mode="aspectFill" :src="item.product.image"></image>
  11. </view>
  12. <view class="detail">
  13. <view class="title">{{item.product.title}}</view>
  14. <view class="price">
  15. <view class="sales">¥{{item.product.sales_price}} </view>
  16. <view class="market"> ¥{{item.product.market_price}}</view>
  17. </view>
  18. <view class="invalid" v-if="item.status == 0">失效</view>
  19. <text class="del-btn yticon icon-lajitong" @click.stop="deleteFavorite(item.product.product_id,index)"></text>
  20. </view>
  21. </view>
  22. </view>
  23. <uni-load-more :status="favorite.loadingType"></uni-load-more>
  24. </scroll-view>
  25. </view>
  26. </template>
  27. <script>
  28. import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
  29. import empty from "@/components/empty";
  30. export default {
  31. components: {
  32. uniLoadMore,
  33. empty
  34. },
  35. computed: {
  36. },
  37. data() {
  38. return {
  39. favorite: {
  40. list:[],
  41. loadingType: 'more'
  42. },
  43. page: 1,
  44. pageSize: 20
  45. }
  46. },
  47. onLoad() {
  48. this.loadData();
  49. },
  50. onPullDownRefresh() {
  51. this.favorite = {};
  52. this.favorite.list = [];
  53. this.page = 1;
  54. this.loadData();
  55. },
  56. methods: {
  57. /**
  58. * 获取收藏数据
  59. */
  60. async loadData(source = false) {
  61. uni.stopPullDownRefresh();
  62. var favorite = this.favorite;
  63. if (favorite.loadingType === 'loading') {
  64. //防止重复加载
  65. return;
  66. }
  67. if (favorite.loadingType == 'noMore') {
  68. //没有更多数据
  69. return;
  70. }
  71. favorite.loadingType = 'loading';
  72. let list = await this.$api.request('/product/favoriteList', 'GET', {
  73. page: this.page,
  74. pagesize: this.pageSize
  75. });
  76. if (list && list.length > 0) {
  77. if (list.length >= this.pageSize) {
  78. //判断是否还有数据, 有改为 more, 没有改为noMore
  79. favorite.loadingType = 'more';
  80. } else {
  81. favorite.loadingType = 'noMore';
  82. }
  83. // 页数加一
  84. this.page++;
  85. list.forEach((item, index) => {
  86. favorite.list.push(item);
  87. });
  88. } else {
  89. favorite.loadingType = 'noMore';
  90. }
  91. },
  92. // 商品详情页
  93. navToDetailPage(product_id, status) {
  94. if (status == 0) {
  95. this.$api.msg('此商品已失效');
  96. return;
  97. }
  98. uni.navigateTo({
  99. url: `/pages/product/product?id=${product_id}&flash=0`
  100. });
  101. },
  102. // 删除
  103. async deleteFavorite(id, index) {
  104. let data = await this.$api.request('/product/favorite?id='+id);
  105. if (data) {
  106. this.favorite.list.splice(index,1);
  107. }
  108. }
  109. }
  110. }
  111. </script>
  112. <style lang="scss">
  113. page,
  114. .content {
  115. background: #f5f5f5;
  116. height: 100%;
  117. }
  118. .list-scroll-content{
  119. height: 100%;
  120. }
  121. .order-item {
  122. display: flex;
  123. flex-direction: column;
  124. padding-left: 30upx;
  125. background: #fff;
  126. margin-top: 16upx;
  127. .info {
  128. display: flex;
  129. flex-direction: row;
  130. .image {
  131. image {
  132. width: 250upx;
  133. height: 250upx;
  134. border-radius: 10upx;
  135. }
  136. }
  137. .detail {
  138. width: 440upx;
  139. height: 250upx;
  140. padding-left: 30upx;
  141. padding-top: 6upx;
  142. position: relative;
  143. .title {
  144. color: #303133;
  145. width: 370rpx;
  146. -webkit-line-clamp: 2;
  147. overflow: hidden;
  148. display: -webkit-box;
  149. -webkit-box-orient: vertical;
  150. }
  151. .introduction {
  152. color: #999999;
  153. font-size: 26upx;
  154. }
  155. .price {
  156. display: flex;
  157. flex-direction: row;
  158. margin-top: 20upx;
  159. .sales {
  160. font-size: 40upx;
  161. color: $base-color;
  162. font-weight: 500;
  163. }
  164. .market {
  165. vertical-align: bottom;
  166. font-size: 25rpx;
  167. text-decoration: line-through;
  168. line-height: 60rpx;
  169. }
  170. }
  171. .ProgressBar {
  172. position: absolute;
  173. bottom: 0;
  174. }
  175. .loot {
  176. position: absolute;
  177. right: 0;
  178. bottom: 14rpx;
  179. background: $base-color;
  180. color: #fff;
  181. padding: 4upx 14upx;
  182. border-radius: 4upx;
  183. box-shadow: 2upx 2upx 8upx -2px #000;
  184. font-size: 32rpx;
  185. }
  186. .invalid{
  187. color: $base-color;
  188. position: absolute;
  189. right: 0;
  190. bottom: 0;
  191. }
  192. .yticon{
  193. position: absolute;
  194. right: 0;
  195. top: 20rpx;
  196. }
  197. }
  198. }
  199. }
  200. /* load-more */
  201. .uni-load-more {
  202. display: flex;
  203. flex-direction: row;
  204. height: 80upx;
  205. align-items: center;
  206. justify-content: center
  207. }
  208. .uni-load-more__text {
  209. font-size: 28upx;
  210. color: #999
  211. }
  212. .uni-load-more__img {
  213. height: 24px;
  214. width: 24px;
  215. margin-right: 10px
  216. }
  217. .uni-load-more__img>view {
  218. position: absolute
  219. }
  220. .uni-load-more__img>view view {
  221. width: 6px;
  222. height: 2px;
  223. border-top-left-radius: 1px;
  224. border-bottom-left-radius: 1px;
  225. background: #999;
  226. position: absolute;
  227. opacity: .2;
  228. transform-origin: 50%;
  229. animation: load 1.56s ease infinite
  230. }
  231. .uni-load-more__img>view view:nth-child(1) {
  232. transform: rotate(90deg);
  233. top: 2px;
  234. left: 9px
  235. }
  236. .uni-load-more__img>view view:nth-child(2) {
  237. transform: rotate(180deg);
  238. top: 11px;
  239. right: 0
  240. }
  241. .uni-load-more__img>view view:nth-child(3) {
  242. transform: rotate(270deg);
  243. bottom: 2px;
  244. left: 9px
  245. }
  246. .uni-load-more__img>view view:nth-child(4) {
  247. top: 11px;
  248. left: 0
  249. }
  250. .load1,
  251. .load2,
  252. .load3 {
  253. height: 24px;
  254. width: 24px
  255. }
  256. .load2 {
  257. transform: rotate(30deg)
  258. }
  259. .load3 {
  260. transform: rotate(60deg)
  261. }
  262. .load1 view:nth-child(1) {
  263. animation-delay: 0s
  264. }
  265. .load2 view:nth-child(1) {
  266. animation-delay: .13s
  267. }
  268. .load3 view:nth-child(1) {
  269. animation-delay: .26s
  270. }
  271. .load1 view:nth-child(2) {
  272. animation-delay: .39s
  273. }
  274. .load2 view:nth-child(2) {
  275. animation-delay: .52s
  276. }
  277. .load3 view:nth-child(2) {
  278. animation-delay: .65s
  279. }
  280. .load1 view:nth-child(3) {
  281. animation-delay: .78s
  282. }
  283. .load2 view:nth-child(3) {
  284. animation-delay: .91s
  285. }
  286. .load3 view:nth-child(3) {
  287. animation-delay: 1.04s
  288. }
  289. .load1 view:nth-child(4) {
  290. animation-delay: 1.17s
  291. }
  292. .load2 view:nth-child(4) {
  293. animation-delay: 1.3s
  294. }
  295. .load3 view:nth-child(4) {
  296. animation-delay: 1.43s
  297. }
  298. @-webkit-keyframes load {
  299. 0% {
  300. opacity: 1
  301. }
  302. 100% {
  303. opacity: .2
  304. }
  305. }
  306. </style>