recommend-goods.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <template name="recommendGoods">
  2. <view v-if="recommendGoods && recommendGoods.length > 0">
  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" @addCart="addCart" ref="recom_goods" :border_radius="10"/>
  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: "recommendGoods",
  17. data() {
  18. return {
  19. imgUrl: getApp().globalData.imgUrl,
  20. recommendGoods: [],
  21. loadingState: 'first_loading',
  22. pageSize: 8,
  23. current: 1,
  24. hasMore: true,//是否还有数据
  25. }
  26. },
  27. props: {
  28. arriveBotFlag: {
  29. type: Boolean,
  30. default: false,
  31. }
  32. },
  33. components: {
  34. goodsItemV,
  35. loadingState
  36. },
  37. created() {
  38. },
  39. mounted() {
  40. this.getData();//获取推荐商品数据
  41. },
  42. methods: {
  43. getData() {
  44. let param = {};
  45. param.url = 'v3/goods/front/goods/recommendList';
  46. param.method = 'GET';
  47. param.data = {};
  48. param.data.queryType = 'cart';
  49. // param.data.queryDetail = 'recommend';
  50. param.data.pageSize = this.pageSize;
  51. param.data.current = this.current;
  52. this.loadingState = this.loadingState == 'first_loading'?this.loadingState:'loading';
  53. this.$request(param).then(res => {
  54. if (res.state == 200) {
  55. if(this.current == 1){
  56. this.recommendGoods = res.data.list;
  57. }else{
  58. this.recommendGoods = this.recommendGoods.concat(res.data.list);
  59. }
  60. this.hasMore = this.$checkPaginationHasMore(res.data.pagination);//是否还有数据
  61. if(this.hasMore){
  62. this.current++;
  63. this.loadingState = 'allow_loading_more';
  64. }else{
  65. this.loadingState = 'no_more_data';
  66. }
  67. // 子组件向父组件传值
  68. uni.$emit("recommendGoods",{
  69. recommendLen:this.recommendGoods.length
  70. })
  71. } else {
  72. //错误提示
  73. }
  74. })
  75. },
  76. //页面到底部加载更多数据
  77. getMoreData(){
  78. if(this.hasMore){
  79. this.getData();
  80. }
  81. },
  82. reloadCartList(val){
  83. this.$emit('reload_cart',val)
  84. },
  85. addCart(val){
  86. this.$emit('addToCart',val)
  87. }
  88. }
  89. }
  90. </script>
  91. <style lang='scss'>
  92. .list-scroll-content{
  93. height: 100vh;
  94. }
  95. .recommend-title {
  96. display: flex;
  97. justify-content: center;
  98. image {
  99. width: 387rpx;
  100. height: 34rpx;
  101. margin: 30rpx 0;
  102. }
  103. }
  104. .recommend-goods {
  105. display: flex;
  106. width: 100%;
  107. flex-wrap: wrap;
  108. justify-content: space-between;
  109. padding:0 20rpx;
  110. box-sizing: border-box;
  111. }
  112. </style>