search.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <template>
  2. <view>
  3. <view class="px3 py2 p-fixed left0 right0 bg-color-white ">
  4. <u-search placeholder="请输入名称" v-model="keyword" @search="search" @custom="search">
  5. </u-search>
  6. </view>
  7. <view style="padding-top: 104rpx;">
  8. <template v-if="listData.length > 0">
  9. <view class="py2 px3 one-ellipsis border-bottom" v-for="(item, index) in listData" :key="index"
  10. @click="handleBack(item)">
  11. {{ item.no }}——{{ item.name }}——{{ item.zbh }}
  12. </view>
  13. <view class="py3">
  14. <u-loadmore :status="status" />
  15. </view>
  16. </template>
  17. <template v-else>
  18. <view class="empty">
  19. <u-empty text="暂无数据" mode="list"></u-empty>
  20. </view>
  21. </template>
  22. </view>
  23. </view>
  24. </template>
  25. <script>
  26. export default {
  27. data() {
  28. return {
  29. keyword: '',
  30. listData: [],
  31. status: 'loadmore',
  32. page: 1,
  33. limit: 20,
  34. loadMore: true
  35. }
  36. },
  37. onLoad() {
  38. this.initData()
  39. },
  40. onPullDownRefresh() {
  41. // 请求结束取消刷新
  42. this.page = 1;
  43. this.loadMore = true;
  44. this.listData = [];
  45. this.initData();
  46. uni.stopPullDownRefresh();
  47. },
  48. onReachBottom() {
  49. if (this.loadMore) {
  50. this.page++;
  51. this.initData();
  52. }
  53. },
  54. methods: {
  55. handleBack(item) {
  56. const pages = getCurrentPages();
  57. const prevPage = pages[pages.length - 2];
  58. prevPage.sbBackId = item.id
  59. // prevPage.setData({
  60. // "ceshiId":item.id,
  61. // })
  62. // console.log(prevPage);
  63. uni.navigateBack();
  64. },
  65. search(value) {
  66. console.log(value);
  67. this.page = 1;
  68. this.loadMore = true;
  69. this.listData = [];
  70. this.initData();
  71. },
  72. initData() {
  73. const that = this
  74. that.status = 'loading';
  75. this.$Http
  76. .getSbInfoPage({
  77. pageNum: that.page,
  78. pageSize: that.limit,
  79. filter: -1,
  80. keyword: that.keyword
  81. })
  82. .then((res) => {
  83. const data = res.data.rows;
  84. if (data && data.length > 0 && data.length < that.limit) {
  85. that.status = 'nomore';
  86. that.loadMore = false;
  87. } else if (data.length == that.limit) {
  88. that.status = 'loadmore';
  89. } else {
  90. that.status = 'nomore';
  91. }
  92. that.listData = [...that.listData, ...data];
  93. console.log(that.listData);
  94. })
  95. }
  96. }
  97. }
  98. </script>
  99. <style scoped>
  100. page {
  101. background-color: #FFFFFF;
  102. }
  103. </style>