search.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. this.param.type = e.type || 0;
  34. if (this.getLocation()) {
  35. this.param.latitude = this.getLocation().latitude;
  36. this.param.longitude = this.getLocation().longitude;
  37. }
  38. },
  39. methods: {
  40. getData() {
  41. this.http.request({
  42. url: '/app/position/list',
  43. data: this.param,
  44. loading: 'false',
  45. success: (res) => {
  46. this.loadMore = res.data.pages > this.param.pageNum ? true : false;
  47. this.list.push(...res.data.rows);
  48. }
  49. });
  50. },
  51. go(url) {
  52. uni.navigateTo({ url: url });
  53. },
  54. search() {
  55. if (this.param.title.trim()) {
  56. this.focus = true;
  57. if (this.history.filter((item) => item == this.param.title.trim()) == 0) {
  58. this.history.unshift(this.param.title);
  59. uni.setStorageSync('history', this.history);
  60. }
  61. this.refresh();
  62. }
  63. },
  64. del() {
  65. uni.removeStorageSync('history');
  66. this.history = [];
  67. },
  68. clear() {
  69. this.focus = false;
  70. this.param.title = '';
  71. this.list = [];
  72. },
  73. //刷新数据
  74. refresh() {
  75. this.loadMore = true;
  76. this.param.pageNum = 1;
  77. this.list = [];
  78. this.getData();
  79. }
  80. },
  81. //上拉加载
  82. onReachBottom() {
  83. if (this.loadMore) {
  84. this.param.pageNum++;
  85. this.getData();
  86. }
  87. }
  88. };
  89. </script>
  90. <style lang="scss">
  91. .search {
  92. margin-bottom: 15px;
  93. }
  94. .history {
  95. overflow: hidden;
  96. .title {
  97. margin-bottom: 12px;
  98. font-weight: bold;
  99. }
  100. .del {
  101. float: right;
  102. font-size: 14px;
  103. margin-top: -30px;
  104. color: #f44336;
  105. .icon {
  106. padding-right: 3px;
  107. }
  108. }
  109. .tag {
  110. float: left;
  111. padding: 4px 10px;
  112. border-radius: 30px;
  113. background-color: white;
  114. margin-right: 10px;
  115. margin-bottom: 5px;
  116. font-size: 14px;
  117. color: $font-c;
  118. }
  119. }
  120. </style>