search.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <template>
  2. <view class="main pt0">
  3. <view class="search">
  4. <u-search placeholder="搜索工作" :focus="true" bgColor="white" v-model="param.title" :showAction="false" @search="search()" @clear="clear()"></u-search>
  5. </view>
  6. <view class="list">
  7. <view class="history" v-if="!focus">
  8. <view class="title">搜索历史</view>
  9. <view class="del" v-if="history.length > 0" @click="del()">
  10. <text class="icon">&#xe8b6;</text>
  11. <text>清除</text>
  12. </view>
  13. <view class="tag" v-for="(item, index) in history" :key="item" @click="(param.title = item), search()">{{ item }}</view>
  14. </view>
  15. <job :list="list"></job>
  16. <view class="loading" v-if="loadMore"><u-loadmore :status="loadMore ? 'loading' : 'nomore'" /></view>
  17. <u-empty v-if="!loadMore && list.length == 0"></u-empty>
  18. </view>
  19. </view>
  20. </template>
  21. <script>
  22. export default {
  23. data() {
  24. return {
  25. list: [],
  26. focus: false,
  27. history: uni.getStorageSync('history') || [],
  28. param: { pageNum: 1, pageSize: 10, type: 0, orderBy: 'id' },
  29. loadMore: false
  30. };
  31. },
  32. onLoad(e) {
  33. if (this.getLocation()) {
  34. this.param.latitude = this.getLocation().latitude;
  35. this.param.longitude = this.getLocation().longitude;
  36. }
  37. },
  38. methods: {
  39. getData() {
  40. this.http.request({
  41. url: '/app/position/list',
  42. data: this.param,
  43. loading: 'false',
  44. success: (res) => {
  45. this.loadMore = res.data.pages > this.param.pageNum ? true : false;
  46. this.list.push(...res.data.rows);
  47. }
  48. });
  49. },
  50. go(url) {
  51. uni.navigateTo({ url: url });
  52. },
  53. search() {
  54. if (this.param.title.trim()) {
  55. this.focus = true;
  56. if (this.history.filter((item) => item == this.param.title.trim()) == 0) {
  57. this.history.unshift(this.param.title);
  58. uni.setStorageSync('history', this.history);
  59. }
  60. this.refresh();
  61. }
  62. },
  63. del() {
  64. uni.removeStorageSync('history');
  65. this.history = [];
  66. },
  67. clear() {
  68. this.focus = false;
  69. this.param.title = '';
  70. this.list = [];
  71. },
  72. //刷新数据
  73. refresh() {
  74. this.loadMore = true;
  75. this.param.pageNum = 1;
  76. this.list = [];
  77. this.getData();
  78. }
  79. },
  80. //上拉加载
  81. onReachBottom() {
  82. if (this.loadMore) {
  83. this.param.pageNum++;
  84. this.getData();
  85. }
  86. }
  87. };
  88. </script>
  89. <style lang="scss">
  90. .search {
  91. margin-bottom: 15px;
  92. }
  93. .history {
  94. overflow: hidden;
  95. .title {
  96. margin-bottom: 12px;
  97. font-weight: bold;
  98. }
  99. .del {
  100. float: right;
  101. font-size: 14px;
  102. margin-top: -30px;
  103. color: #f44336;
  104. .icon {
  105. padding-right: 3px;
  106. }
  107. }
  108. .tag {
  109. float: left;
  110. padding: 4px 10px;
  111. border-radius: 30px;
  112. background-color: white;
  113. margin-right: 10px;
  114. margin-bottom: 5px;
  115. font-size: 14px;
  116. color: $font-c;
  117. }
  118. }
  119. </style>