search-header.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <template>
  2. <view class="search-header">
  3. <view class="search-container">
  4. <view class="search-tab" @click="showBubblePopup = true">
  5. <text v-text="menuName"></text>
  6. <text class="iconfont icon-xiangxiajiantou"></text>
  7. </view>
  8. <view class="search-control">
  9. <text class="iconfont icon-sousuo"></text>
  10. <input
  11. class="control"
  12. type="text"
  13. :value="value"
  14. placeholder="请输入搜索关键字"
  15. @confirm="$emit('search', value)"
  16. @input="event => $emit('input', event.detail.value)"
  17. @blur="$emit('blur')"
  18. @focus="$emit('focus')"
  19. />
  20. <text class="iconfont icon-shanchu1" v-show="showClearBtn" @click="$emit('clear')"></text>
  21. </view>
  22. <view class="search-submit" @click="$emit('search', value)">搜索</view>
  23. </view>
  24. <!-- 下拉菜单 -->
  25. <tui-bubble-popup
  26. :show="showBubblePopup"
  27. :mask="true"
  28. position="fixed"
  29. direction="top"
  30. width="140rpx"
  31. left="10rpx"
  32. top="80rpx"
  33. triangleRight="60rpx"
  34. triangleTop="-22rpx"
  35. maskBgColor="rgba(0,0,0,0)"
  36. @close="showBubblePopup = false"
  37. >
  38. <view class="bubble-popup-container">
  39. <view
  40. class="menu-item"
  41. v-for="(item, index) in menuList"
  42. :key="index"
  43. @click="onMenuItemClick(index)"
  44. v-text="item.name"
  45. ></view>
  46. </view>
  47. </tui-bubble-popup>
  48. </view>
  49. </template>
  50. <script>
  51. export default {
  52. props: {
  53. value: {
  54. type: String,
  55. default: ''
  56. },
  57. menuList: {
  58. type: Array,
  59. default: () => []
  60. },
  61. currentMenu: {
  62. type: Number,
  63. default: 0
  64. }
  65. },
  66. model: {
  67. event: 'input',
  68. prop: 'value'
  69. },
  70. data() {
  71. return {
  72. showBubblePopup: false
  73. }
  74. },
  75. computed: {
  76. // 当前选中菜单
  77. menuName() {
  78. return this.menuList[this.currentMenu].name
  79. },
  80. // 显示输入框clear按钮
  81. showClearBtn() {
  82. return this.value.length > 0
  83. }
  84. },
  85. methods: {
  86. // menu-item 点击事件
  87. onMenuItemClick(index) {
  88. this.showBubblePopup = false
  89. this.$emit('menuClick', index)
  90. },
  91. cursor() {}
  92. }
  93. }
  94. </script>
  95. <style lang="scss" scoped>
  96. .search-header {
  97. position: relative;
  98. z-index: 9;
  99. }
  100. .search-container {
  101. width: 100%;
  102. box-sizing: border-box;
  103. padding: 10rpx 24rpx;
  104. display: flex;
  105. justify-content: space-between;
  106. align-items: center;
  107. height: 86rpx;
  108. background: #fff;
  109. .search-tab {
  110. font-size: 30rpx;
  111. color: #666;
  112. flex-shrink: 0;
  113. .icon-xiangxiajiantou {
  114. font-size: 34rpx;
  115. color: #666;
  116. margin-left: 10rpx;
  117. }
  118. }
  119. .search-control {
  120. width: 473rpx;
  121. height: 100%;
  122. background: #f7f7f7;
  123. border-radius: 33rpx;
  124. box-sizing: border-box;
  125. display: flex;
  126. justify-content: space-between;
  127. align-items: center;
  128. .icon-sousuo {
  129. display: block;
  130. width: 36rpx;
  131. margin-left: 32rpx;
  132. margin-right: 16rpx;
  133. flex-shrink: 0;
  134. color: #999999;
  135. }
  136. .icon-shanchu1 {
  137. width: 36rpx;
  138. margin: 0 12rpx;
  139. flex-shrink: 0;
  140. color: #999999;
  141. }
  142. .control {
  143. flex: 1;
  144. height: 100%;
  145. font-size: 28rpx;
  146. color: #333333;
  147. }
  148. }
  149. .search-submit {
  150. font-size: 30rpx;
  151. color: #F3B574;
  152. flex-shrink: 0;
  153. }
  154. }
  155. .bubble-popup-container {
  156. padding: 10rpx 0;
  157. .menu-item {
  158. text-align: center;
  159. line-height: 60rpx;
  160. font-size: 28rpx;
  161. }
  162. }
  163. </style>