app-search.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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]"></i>
  6. </div>
  7. <div class="input-wrap">
  8. <input type="text" v-model="search" @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. data() {
  67. return {
  68. search: ''
  69. }
  70. },
  71. methods: {
  72. searchFn() {
  73. this.$emit('search', this.search)
  74. },
  75. inputFn(e) {
  76. // console.log('sdfa', e)
  77. setTimeout(() => {
  78. this.$emit('input', this.search)
  79. })
  80. }
  81. }
  82. }
  83. </script>
  84. <style lang="scss" scoped>
  85. .app-search-module {
  86. width: 100%;
  87. @include disFlex(center, space-between);
  88. .map-search {
  89. @include disFlex(center, flex-start);
  90. width: 100%;
  91. height: 100%;
  92. border-radius: 10px;
  93. .icon-wrap {
  94. margin-left: 20px;
  95. width: 40px;
  96. .iconfont {
  97. color: #ccc;
  98. }
  99. }
  100. .input-wrap {
  101. width: calc(100% - 90px);
  102. margin-left: 14px;
  103. input {
  104. font-size: 26px;
  105. text-align: left;
  106. }
  107. .placeholder {
  108. color: #ccc;
  109. }
  110. }
  111. }
  112. // 按钮
  113. .search-btn {
  114. height: 100%;
  115. padding: 0 20px;
  116. flex-shrink: 0;
  117. margin-left: 20px;
  118. background-color: inherit;
  119. }
  120. }
  121. </style>