index.vue 2.8 KB

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