zone.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <!-- 专区页面 -->
  2. <template>
  3. <view class="zone">
  4. <view class="listbox">
  5. <Goods v-for="(item, index) in list" :key="index" :data="item"></Goods>
  6. </view>
  7. <NoData v-if="finish&&list.length<1"></NoData>
  8. <LoadMore v-else :loadtype="{page, loading, finish}"></LoadMore>
  9. </view>
  10. </template>
  11. <script>
  12. import Goods from '@/pages/mall/components/goods.vue';
  13. export default {
  14. name: 'zone',
  15. components: {
  16. Goods
  17. },
  18. data(){
  19. return {
  20. type:'default',
  21. page:1,
  22. loading:false,
  23. finish:false,
  24. pullDown:false,
  25. list: [],
  26. }
  27. },
  28. onLoad(opt) {
  29. if(opt){
  30. this.type = opt.type;
  31. }
  32. uni.setNavigationBarTitle({
  33. title:this.type=='hot'?'热门好物':this.type=='recommend'?'精选推荐':'好物推荐'
  34. });
  35. this.getList();
  36. },
  37. onReachBottom() {
  38. this.getList();
  39. },
  40. onPullDownRefresh(){
  41. this.pullDown = true;
  42. this.reData();
  43. },
  44. methods: {
  45. // 刷新数据
  46. reData(){
  47. this.page=1;
  48. this.finish=false;
  49. this.list=[];
  50. this.getList();
  51. },
  52. getList(){
  53. if(this.finish)return false;
  54. if(this.loading)return false;
  55. this.$u.api.getGoodsListAjax({
  56. page:this.page,
  57. tags_type:this.type,
  58. }).then(({code,data})=>{
  59. console.log(code,data)
  60. if(this.pullDown){
  61. uni.stopPullDownRefresh();
  62. this.pullDown = false;
  63. }
  64. this.loading = false;
  65. let returnData = data.data;
  66. if(code==1){
  67. if(data.last_page<=data.current_page){
  68. this.finish = true;
  69. }
  70. returnData.forEach(e => {
  71. e.checked = false;
  72. })
  73. if(data.current_page==1){
  74. this.list = returnData;
  75. }else{
  76. this.list=this.list.concat(returnData);
  77. }
  78. }else{
  79. this.finish = true;
  80. }
  81. this.page++;
  82. }).catch(()=>{
  83. this.loading = false;
  84. this.finish = true;
  85. if(this.pullDown){
  86. uni.stopPullDownRefresh();
  87. this.pullDown = false;
  88. }
  89. })
  90. },
  91. }
  92. };
  93. </script>
  94. <style lang="scss" scoped>
  95. .zone{
  96. // background-color: #fff;
  97. }
  98. .listbox{
  99. margin: 20rpx 20rpx 0;
  100. background-color: #fff;
  101. }
  102. </style>