展品维保小程序前端代码接口
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

116 lines
2.2 KiB

  1. <template>
  2. <view class="search-input-container">
  3. <view class="search-box">
  4. <view class="search-icon" @click="handleSearch">
  5. <uv-icon name="search" size="20"></uv-icon>
  6. </view>
  7. <input
  8. class="search-input"
  9. type="text"
  10. :placeholder="placeholder"
  11. v-model="inputValue"
  12. @input="handleInput"
  13. @confirm="handleSearch"
  14. />
  15. <text class="search-text" v-if="showSearchButton" @click="handleSearch">{{ searchButtonText }}</text>
  16. </view>
  17. </view>
  18. </template>
  19. <script>
  20. export default {
  21. name: 'SearchInput',
  22. props: {
  23. placeholder: {
  24. type: String,
  25. default: '请输入搜索内容'
  26. },
  27. showSearchButton: {
  28. type: Boolean,
  29. default: true
  30. },
  31. searchButtonText: {
  32. type: String,
  33. default: '搜索'
  34. },
  35. value: {
  36. type: String,
  37. default: ''
  38. }
  39. },
  40. data() {
  41. return {
  42. inputValue: this.value
  43. }
  44. },
  45. watch: {
  46. value(newVal) {
  47. this.inputValue = newVal
  48. },
  49. inputValue(newVal) {
  50. this.$emit('input', newVal)
  51. }
  52. },
  53. methods: {
  54. handleInput(e) {
  55. this.inputValue = e.detail.value || e.target.value
  56. this.$emit('input', this.inputValue)
  57. },
  58. handleSearch() {
  59. // console.log('搜索的数值为', this.inputValue);
  60. this.$emit('search', this.inputValue)
  61. }
  62. }
  63. }
  64. </script>
  65. <style lang="scss" scoped>
  66. .search-input-container {
  67. padding: 20rpx 30rpx;
  68. }
  69. .search-box {
  70. display: flex;
  71. align-items: center;
  72. background-color: #fff;
  73. border-radius: 37rpx;
  74. box-shadow: 0rpx 3rpx 6rpx 0rpx rgba(0,0,0,0.16);
  75. padding: 0 19rpx 0 29rpx;
  76. height: 79rpx;
  77. // transition: border-color 0.3s ease;
  78. // &:focus-within {
  79. // border: 1rpx solid $primary-color;
  80. // border-color: #c70019;
  81. // }
  82. }
  83. .search-icon {
  84. margin-right: 7rpx;
  85. display: flex;
  86. align-items: center;
  87. justify-content: center;
  88. }
  89. .search-input {
  90. flex: 1;
  91. border: none;
  92. outline: none;
  93. background: transparent;
  94. font-size: 28rpx;
  95. color: $secondary-text-color;
  96. height: 100%;
  97. &::placeholder {
  98. color: #999;
  99. }
  100. }
  101. .search-text {
  102. color: $primary-color;
  103. font-size: 28rpx;
  104. }
  105. </style>