index.vue 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <template>
  2. <view class="width-100 height-100 view-page">
  3. <u-swiper :list="list1" @click="click"></u-swiper>
  4. <view class="p-10">
  5. <u-search :clearabled="true" placeholder="请输入搜索关键字" v-model="keyword" :shape="square" search="doRefresh" @custom="doRefresh"></u-search>
  6. </view>
  7. <u-list @scrolltolower="scrolltolower" height="calc(100% - 180px)" lowerThreshold="10">
  8. <u-list-item v-for="(item, index) in list" :key="index">
  9. <u-cell :title="item.name" @click="toDetail(item.id)">
  10. <u-avatar slot="icon" shape="square" size="35" :src="item.cover"
  11. customStyle="margin: -3px 5px -3px 0"></u-avatar>
  12. </u-cell>
  13. </u-list-item>
  14. <u-loadmore :status="page.status" :loading-text="page.loadingText" :loadmore-text="page.loadmoreText"
  15. :nomore-text="page.nomoreText" />
  16. </u-list>
  17. </view>
  18. </template>
  19. <script>
  20. import themeMixins from '@/pages/yuecai/mixins/themeMixins.js';
  21. export default {
  22. mixins: [themeMixins],
  23. data() {
  24. return {
  25. list1: [
  26. 'https://cdn.uviewui.com/uview/swiper/swiper1.png',
  27. 'https://cdn.uviewui.com/uview/swiper/swiper2.png',
  28. 'https://cdn.uviewui.com/uview/swiper/swiper3.png',
  29. ],
  30. page: {
  31. current: 1,
  32. size: 10,
  33. total: 0,
  34. // loadmore loading nomore
  35. status: 'loadmore',
  36. loadingText: '正在加载中',
  37. loadmoreText: '上拉加载更多',
  38. nomoreText: '没有更多了'
  39. },
  40. keyword: '',
  41. list: []
  42. }
  43. },
  44. onShow() {
  45. this.keyword = '';
  46. this.doRefresh();
  47. },
  48. methods: {
  49. scrolltolower() {
  50. this.loadmore()
  51. },
  52. loadmore() {
  53. this.page.current++;
  54. this.getDishList();
  55. },
  56. doRefresh() {
  57. this.page.current = 1;
  58. this.page.status = 'loadmore'
  59. this.list = [];
  60. this.getDishList();
  61. },
  62. getDishList() {
  63. if (this.page.status == 'loading' || this.page.status == 'nomore') {
  64. // 防止重复下拉
  65. return;
  66. }
  67. this.page.status = 'loading';
  68. //
  69. this.$u.api.getDishList(this.page.current, this.page.size, {
  70. name: this.keyword || ''
  71. }).then(res => {
  72. if (res.data.records && res.data.records.length > 0) {
  73. this.list.push(...res.data.records)
  74. }
  75. this.page.total = res.data.total || 0;
  76. if (this.page.size * this.page.current >= res.data.total) {
  77. this.page.status = 'nomore'
  78. } else {
  79. this.page.status = 'loadmore'
  80. }
  81. })
  82. },
  83. toDetail(id) {
  84. uni.navigateTo({
  85. url: "/pages/yuecai/dish/detail/index?id=" + id,
  86. })
  87. }
  88. },
  89. }
  90. </script>
  91. <style scoped lang="scss">
  92. .view-page {
  93. overflow: hidden;
  94. }
  95. </style>