1
0

search.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <template>
  2. <view class="main">
  3. <view class="search">
  4. <u-search placeholder="搜索工作" :focus="true" bgColor="white" v-model="deptName" :showAction="false" @search="search()" @clear="refresh()"></u-search>
  5. </view>
  6. <view class="search_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="(deptName = item), search()">{{ item }}</view>
  14. </view>
  15. <view class="item" v-for="(item, index) in list" :key="item.deptId" @click="go('/pages/department/detail?id=' + item.deptId)">
  16. <view class="title omit">{{ item.deptName }}</view>
  17. <view class="icon">&#xe62b;</view>
  18. </view>
  19. <u-empty v-if="list.length == 0"></u-empty>
  20. </view>
  21. </view>
  22. </template>
  23. <script>
  24. export default {
  25. data() {
  26. return {
  27. list: [],
  28. focus: false,
  29. history: uni.getStorageSync('history') || [],
  30. deptName: ''
  31. };
  32. },
  33. onLoad(e) {},
  34. methods: {
  35. getData() {
  36. this.http.request({
  37. url: '/app/department/selectDeptList',
  38. data: { deptName: this.deptName },
  39. success: (res) => {
  40. this.list = res.data.data;
  41. }
  42. });
  43. },
  44. go(url) {
  45. uni.navigateTo({ url: url });
  46. },
  47. search() {
  48. if (this.deptName.trim()) {
  49. this.focus = true;
  50. if (this.history.filter((item) => item == this.deptName.trim()) == 0) {
  51. this.history.unshift(this.deptName);
  52. uni.setStorageSync('history', this.history);
  53. }
  54. this.getData();
  55. }
  56. },
  57. refresh() {
  58. this.deptName = '';
  59. this.list = [];
  60. this.search();
  61. },
  62. del() {
  63. uni.removeStorageSync('history');
  64. this.history = [];
  65. },
  66. clear() {
  67. this.focus = false;
  68. this.deptName = '';
  69. this.list = [];
  70. }
  71. }
  72. };
  73. </script>
  74. <style lang="scss"></style>