recommend_list.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <!-- 推荐商品列表组件 -->
  2. <template name="recommendList">
  3. <view class="recommend">
  4. <view class="recommend_title flex_row_center_center">
  5. <image :src="imgUrl + '/point/goods/recommend_tips.png'" mode=""></image>
  6. </view>
  7. <view class="recommend_list">
  8. <recommendItemV class="recommend_pre" v-for="(recommendItem,recommendIndex) in recommendedList" :key="recommendIndex" :goods_info="recommendItem"></recommendItemV>
  9. </view>
  10. <loadingState :state='loadingState'/>
  11. </view>
  12. </template>
  13. <script>
  14. import recommendItemV from './recommend_item_v.vue';
  15. import loadingState from './loading-state.vue';
  16. export default{
  17. name:'recommendList',
  18. components:{
  19. recommendItemV,
  20. loadingState
  21. },
  22. data(){
  23. return{
  24. imgUrl: getApp().globalData.imgUrl,
  25. recommendedList:[], //店铺推荐列表
  26. current:1,
  27. pageSize:10,
  28. loadingState:'first_loading',
  29. hasMore:true,
  30. }
  31. },
  32. mounted(){
  33. this.getRecommend();
  34. },
  35. methods:{
  36. //获取店铺推荐商品信息
  37. getRecommend(){
  38. let param = {};
  39. param.url = 'v3/integral/front/integral/mall/recommendList';
  40. param.method = 'GET';
  41. param.data = {};
  42. param.data.current = this.current;
  43. param.data.pageSize = this.pageSize;
  44. this.loadingState = this.loadingState == 'first_loading'?this.loadingState:'loading';
  45. this.$request(param).then(res => {
  46. if (res.state == 200) {
  47. let result = res.data;
  48. if(this.current == 1){
  49. this.recommendedList = result.list;
  50. }else{
  51. this.recommendedList = this.recommendedList.concat(result.list);
  52. }
  53. this.hasMore = this.$checkPaginationHasMore(res.data.pagination); //是否还有数据
  54. if (this.hasMore) {
  55. this.current++;
  56. this.loadingState = 'allow_loading_more';
  57. }else{
  58. this.loadingState = 'no_more_data';
  59. }
  60. } else {
  61. this.$api.msg(res.msg);
  62. }
  63. }).catch((e) => {
  64. //异常处理
  65. })
  66. },
  67. //加载更多
  68. getMoreData(){
  69. if(this.hasMore){
  70. this.getRecommend();
  71. }
  72. }
  73. }
  74. }
  75. </script>
  76. <style lang='scss'>
  77. /* 店铺推荐 start */
  78. .recommend{
  79. .recommend_title{
  80. width: 750rpx;
  81. padding: 40rpx 0 26rpx;
  82. box-sizing: border-box;
  83. image{
  84. width: 193rpx;
  85. height: 30rpx;
  86. }
  87. }
  88. .recommend_list{
  89. display: flex;
  90. flex-wrap: wrap;
  91. padding: 0 20rpx;
  92. .recommend_pre{
  93. margin-right: 20rpx!important;
  94. &:nth-child(2n){
  95. margin-right: 0!important;
  96. }
  97. }
  98. }
  99. }
  100. /* 店铺推荐 end */
  101. </style>