list1.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <!-- 分类列表 -->
  2. <template>
  3. <view class="page">
  4. <!-- 带搜索框的一般导航栏 -->
  5. <NavbarSearch :title="'分类/'+cateInfo.name" v-model="searchVal" @sortType="sortTypeChange" @confirm="confirmSearch"></NavbarSearch>
  6. <!-- 商品列表 -->
  7. <view class="list">
  8. <!-- 瀑布流组件 -->
  9. <u-waterfall ref="topicWaterFall" v-model="goodsList" marginLeft="7rpx" marginRight="7rpx">
  10. <template v-slot:left="{ leftList }">
  11. <CardGoods v-for="(item, index) in leftList" :key="index" :data="item" :showOldMoney="item.oldMoney"></CardGoods>
  12. </template>
  13. <template v-slot:right="{ rightList }">
  14. <CardGoods v-for="(item, index) in rightList" :key="index" :data="item" :showOldMoney="item.oldMoney"></CardGoods>
  15. </template>
  16. </u-waterfall>
  17. </view>
  18. </view>
  19. </template>
  20. <script>
  21. // 组件
  22. import CardGoods from '@/pages/mall/components/card.vue';
  23. // import NavbarSearch from '@/pages-mall/components/navbar-search.vue';
  24. import NavbarSearch from '@/components/navbar/navbar-search.vue';
  25. // 假数据
  26. import { recommendGoodsList as goodsList } from '@/static/test-data.js';
  27. export default {
  28. components: {
  29. CardGoods,
  30. NavbarSearch
  31. },
  32. data() {
  33. return {
  34. searchVal:null,
  35. cateInfo:{
  36. name:null,
  37. },
  38. goodsList: goodsList,
  39. };
  40. },
  41. onLoad(opt) {
  42. console.log(opt.cateInfo)
  43. if(opt.cateInfo){
  44. console.log(this.cateInfo)
  45. this.cateInfo = JSON.parse(decodeURIComponent(opt.cateInfo));
  46. console.log(this.cateInfo)
  47. }
  48. },
  49. methods:{
  50. sortTypeChange(e) {
  51. console.log('eee>>>>>',e);
  52. this.sortType=e;
  53. this.page = 1;
  54. this.finish = false;
  55. this.goodsList=[];
  56. this.getGoodsList();
  57. },
  58. confirmSearch(e){
  59. console.log('搜索关键字>>>>',e);
  60. this.searchKeyWord = e;
  61. this.getGoodsList();
  62. },
  63. // 查询商品
  64. getGoodsList() {
  65. if(this.finish)return false;
  66. if(this.loading) return false;
  67. this.loading = true;
  68. this.$u.api.getGoodsListAjax({
  69. title: this.searchKeyWord,
  70. page: this.page,
  71. ...this.sortType
  72. }).then(({code,data})=>{
  73. this.loading = false;
  74. if(code==1){
  75. if(data.last_page<=data.current_page){
  76. this.finish = true;
  77. }
  78. if(data.current_page==1){
  79. this.goodsList = data.data;
  80. }else{
  81. this.goodsList=this.goodsList.concat(data.data);
  82. }
  83. }else{
  84. this.finish = true;
  85. }
  86. this.page = data.current_page+1;
  87. }).catch(()=>{
  88. this.loading = false;
  89. this.finish = true;
  90. })
  91. },
  92. },
  93. };
  94. </script>
  95. <style lang="scss" scoped>
  96. .list {
  97. padding: 30rpx;
  98. }
  99. </style>