app-search.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <template>
  2. <div class="app-search-module" :style="{height: height + 'rpx'}">
  3. <div class="map-search" :style="{backgroundColor: backColor}">
  4. <div class="icon-wrap" v-if="isIcon">
  5. <i class="iconfont" :class="[icon]" style="font-size:38upx;"></i>
  6. </div>
  7. <div class="input-wrap">
  8. <input type="text" ref="searchInput" v-model="search" :focus="focus" @input="inputFn" :style="{fontSize: fontSize + 'rpx'}" :placeholder="placeholder" placeholder-class="placeholder" />
  9. </div>
  10. </div>
  11. <block v-if="isBtn">
  12. <button v-if="isTextBtn" class="search-btn" :style="{fontSize: fontSize + 'rpx'}" @click="searchFn">{{ btnText }}</button>
  13. <button v-else class="search-btn admin-button-com middle blue" :style="{fontSize: fontSize + 'rpx'}" @click="searchFn">{{ btnText }}</button>
  14. </block>
  15. </div>
  16. </template>
  17. <script>
  18. export default {
  19. name: 'app-search-module',
  20. props: {
  21. // 搜索组件的高度
  22. height: {
  23. type: Number,
  24. default: 66
  25. },
  26. placeholder: {
  27. type: String,
  28. default: '请输入'
  29. },
  30. // size字体大小
  31. fontSize: {
  32. type: Number,
  33. default: 26
  34. },
  35. // 是否有icon
  36. isIcon: {
  37. type: Boolean,
  38. default: true
  39. },
  40. // 显示的icon
  41. icon: {
  42. type: String,
  43. default: 'iconsearch'
  44. },
  45. // 背景色
  46. backColor: {
  47. type: String,
  48. default: '#F0F2F6'
  49. },
  50. // 是否需要按钮
  51. isBtn: {
  52. type: Boolean,
  53. default: false
  54. },
  55. // 是否是文字按钮
  56. isTextBtn: {
  57. type: Boolean,
  58. default: true
  59. },
  60. // 按钮文字
  61. btnText: {
  62. type: String,
  63. default: '搜索'
  64. },
  65. // 是否自动聚焦
  66. focus: {
  67. type: Boolean,
  68. default: false
  69. }
  70. },
  71. data() {
  72. return {
  73. search: ''
  74. }
  75. },
  76. methods: {
  77. searchFn() {
  78. this.$emit('search', this.search)
  79. },
  80. inputFn(e) {
  81. // console.log('sdfa', e)
  82. setTimeout(() => {
  83. this.$emit('input', this.search)
  84. })
  85. }
  86. }
  87. }
  88. </script>
  89. <style lang="scss" scoped>
  90. .app-search-module {
  91. width: 100%;
  92. @include disFlex(center, space-between);
  93. .map-search {
  94. @include disFlex(center, flex-start);
  95. width: 100%;
  96. height: 100%;
  97. border-radius: 10upx;
  98. .icon-wrap {
  99. margin-left: 20upx;
  100. width: 40upx;
  101. .iconfont {
  102. color: #ccc;
  103. }
  104. }
  105. .input-wrap {
  106. width: calc(100% - 90upx);
  107. margin-left: 14upx;
  108. input {
  109. font-size: 26upx;
  110. text-align: left;
  111. }
  112. .placeholder {
  113. color: #ccc;
  114. }
  115. }
  116. }
  117. // 按钮
  118. .search-btn {
  119. height: 100%;
  120. padding: 0 20upx;
  121. flex-shrink: 0;
  122. margin-left: 20upx;
  123. background-color: inherit;
  124. }
  125. }
  126. </style>