search-header.vue 4.1 KB

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