search.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <template>
  2. <view class="slot" :style="{ padding }">
  3. <view class="search">
  4. <u-search
  5. class="search-components"
  6. :placeholder="placeholder"
  7. v-model="keyword"
  8. bg-color="#F4F5F8"
  9. height="70"
  10. @focus="focus"
  11. @search="search"
  12. @custom="search"
  13. @change="change"
  14. ></u-search>
  15. </view>
  16. <view class="list" v-show="showSearchList" v-if="showFastTip">
  17. <view class="item" v-for="(item, index) in searchList" :key="index">{{ item }}</view>
  18. </view>
  19. </view>
  20. </template>
  21. <script>
  22. const searchList = [];
  23. export default {
  24. name: 'search',
  25. props: {
  26. // 占位内容
  27. placeholder: {
  28. type: String,
  29. default: '请输入'
  30. },
  31. // 内边距
  32. padding: {
  33. type: String,
  34. default: '20rpx 30rpx'
  35. },
  36. // 是否显示取消按钮
  37. showCancelBtn: {
  38. type: Boolean,
  39. default: false
  40. },
  41. showFastTip:{
  42. type: Boolean,
  43. default: false
  44. },
  45. },
  46. data() {
  47. return {
  48. // 关键字
  49. keyword: '',
  50. // 检索列表
  51. showSearchList: false,
  52. searchList: []
  53. };
  54. },
  55. watch: {
  56. // 监听关键字,如果有输入关键字,则打开待选词列表
  57. keyword(newVal) {
  58. if (newVal.length > 0) {
  59. this.showSearchList = true;
  60. this.searchList = searchList;
  61. } else {
  62. this.showSearchList = false;
  63. }
  64. }
  65. },
  66. methods: {
  67. // 聚焦
  68. focus() {},
  69. // 内容改变
  70. change(e) {
  71. this.$emit('change', e);
  72. },
  73. // 取消搜索
  74. cancelSearch() {
  75. this.showSearchList = false;
  76. },
  77. // 搜索
  78. search(e) {
  79. this.$emit('search', e);
  80. }
  81. }
  82. };
  83. </script>
  84. <style lang="scss">
  85. .slot {
  86. }
  87. .search {
  88. width: 100%;
  89. // display: flex;
  90. // justify-content: space-between;
  91. // align-items: center;
  92. // .search-components {
  93. // width: 100%;
  94. // &.active {
  95. // width: 86%;
  96. // }
  97. // }
  98. }
  99. /deep/.u-content {
  100. border-radius: 0 !important;
  101. }
  102. .cancel {
  103. width: 14%;
  104. text-align: center;
  105. }
  106. .list {
  107. .item {
  108. width: 100%;
  109. height: 100rpx;
  110. line-height: 100rpx;
  111. border-bottom: 1rpx solid $app-theme-border-color;
  112. &.last-child {
  113. border: none;
  114. }
  115. }
  116. }
  117. </style>