selection-goods.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <template name="recommendGoods">
  2. <view v-if="recommendGoods.length">
  3. <view class="recommend-title">
  4. <image :src="imgUrl+'member/recommend-title.png'" />
  5. </view>
  6. <view class="recommend-goods flex_row_start_start">
  7. <goodsItemV v-for="(item,key,index) in recommendGoods" :goods_info="item" :key='index' :show_sale="false" :icon_type="1" @reloadCartList="reloadCartList"/>
  8. </view>
  9. <loadingState :state='loadingState'/>
  10. </view>
  11. </template>
  12. <script>
  13. import goodsItemV from "@/components/goods_item_v.vue";
  14. import loadingState from "@/components/loading-state.vue";
  15. export default {
  16. name: "selectionGoods",
  17. data() {
  18. return {
  19. imgUrl: getApp().globalData.imgUrl,
  20. recommendGoods: [],
  21. loadingState: 'first_loading',
  22. pageSize: 10,
  23. current: 1,
  24. loading: false,//是否加载数据
  25. ishasMore: true,//是否还有数据
  26. }
  27. },
  28. props: {
  29. arriveBotFlag: {
  30. type: Boolean,
  31. default: false,
  32. },
  33. hasMore: {
  34. type: Boolean,
  35. },
  36. pn: {
  37. type: Number,
  38. },
  39. recGoods:{
  40. type: Array,
  41. },
  42. loadingstate: {
  43. type: String
  44. },
  45. loadings: {
  46. type: Boolean,
  47. }
  48. },
  49. components: {
  50. goodsItemV,
  51. loadingState
  52. },
  53. created() {
  54. },
  55. mounted() {
  56. this.ishasMore = this.hasMore;
  57. this.current = this.pn;
  58. this.recommendGoods = this.recGoods;
  59. this.loadingState = this.loadingstate;
  60. this.loading = this.loadings;
  61. this.getData();//获取推荐商品数据
  62. },
  63. methods: {
  64. getData() {
  65. this.loading = true;
  66. let param = {};
  67. param.url = 'v1/front/goods/selectList';
  68. param.method = 'GET';
  69. param.data = {};
  70. param.data.queryType = 'cart';
  71. param.data.queryDetail = 'recommend';
  72. param.data.pageSize = this.pageSize;
  73. param.data.current = this.current;
  74. this.loadingState = this.loadingState == 'first_loading'?this.loadingState:'loading';
  75. this.$request(param).then(res => {
  76. if (res.state == 200) {
  77. if(this.current == 1){
  78. this.recommendGoods = res.data.list;
  79. }else{
  80. this.recommendGoods = this.recommendGoods.concat(res.data.list);
  81. }
  82. this.ishasMore = this.$checkPaginationHasMore(res.data.pagination);//是否还有数据
  83. if(this.ishasMore){
  84. this.current++;
  85. this.loadingState = 'allow_loading_more';
  86. }else{
  87. this.loadingState = 'no_more_data';
  88. }
  89. } else {
  90. //错误提示
  91. }
  92. this.loading = false;
  93. })
  94. },
  95. //页面到底部加载更多数据
  96. getMoreData(){
  97. if(this.ishasMore){
  98. this.getData();
  99. }
  100. },
  101. reloadCartList(val){
  102. this.$emit('reload_cart',val)
  103. }
  104. }
  105. }
  106. </script>
  107. <style lang='scss'>
  108. .list-scroll-content{
  109. height: 100vh;
  110. }
  111. .recommend-title {
  112. display: flex;
  113. justify-content: center;
  114. image {
  115. width: 387rpx;
  116. height: 34rpx;
  117. margin: 30rpx 0;
  118. }
  119. }
  120. .recommend-goods {
  121. display: flex;
  122. width: 100%;
  123. flex-wrap: wrap;
  124. justify-content: space-between;
  125. padding:0 20rpx;
  126. box-sizing: border-box;
  127. }
  128. </style>