search.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <template>
  2. <view>
  3. <view class="search-content pr">
  4. <view class="search-icon dis-inline-block pa" @tap="search_icon_event">
  5. <uni-icons :type="propIcon" size="12" :color="propIconColor"></uni-icons>
  6. </view>
  7. <input type="text" confirm-type="search" class="round wh-auto dis-block" :placeholder="propPlaceholder" :placeholder-class="propPlaceholderClass" :value="propDefaultValue" @confirm="search_input_event" :style="'color:'+propTextColor+';background:'+propBgColor+';'+((propBrColor || null) != null ? 'border:1px solid '+propBrColor+';' : '')">
  8. </view>
  9. </view>
  10. </template>
  11. <script>
  12. const app = getApp();
  13. export default {
  14. data() {
  15. return {};
  16. },
  17. components: {},
  18. props: {
  19. propUrl: {
  20. type: String,
  21. default: '/pages/goods-search/goods-search'
  22. },
  23. propFormName: {
  24. type: String,
  25. default: 'keywords'
  26. },
  27. propPlaceholder: {
  28. type: String,
  29. default: '其实搜索很简单 ^_^!'
  30. },
  31. propDefaultValue: {
  32. type: String,
  33. default: ''
  34. },
  35. propPlaceholderClass: {
  36. type: String,
  37. default: 'cr-grey'
  38. },
  39. propTextColor: {
  40. type: String,
  41. default: '#666'
  42. },
  43. propBgColor: {
  44. type: String,
  45. default: '#f0f0f0'
  46. },
  47. propBrColor: {
  48. type: String,
  49. default: ''
  50. },
  51. propIsRequired: {
  52. type: Boolean,
  53. default: true
  54. },
  55. propIsOnEvent: {
  56. type: Boolean,
  57. default: false
  58. },
  59. propIcon: {
  60. type: String,
  61. default: 'search'
  62. },
  63. propIconColor: {
  64. type: String,
  65. default: '#b7b7b7'
  66. },
  67. propIsIconOnEvent: {
  68. type: Boolean,
  69. default: false
  70. },
  71. },
  72. methods: {
  73. // 搜索事件
  74. search_input_event(e) {
  75. var keywords = e.detail.value || null;
  76. // 是否验证必须要传值
  77. if (this.propIsRequired && keywords == null) {
  78. app.globalData.showToast("请输入搜索关键字");
  79. return false;
  80. }
  81. // 是否回调事件
  82. if(this.propIsOnEvent) {
  83. this.$emit('onsearch', keywords);
  84. } else {
  85. // 进入搜索页面
  86. uni.navigateTo({
  87. url: this.propUrl+'?'+this.propFormName+'=' + keywords
  88. });
  89. }
  90. },
  91. // icon事件
  92. search_icon_event(e) {
  93. // 是否回调事件
  94. if(this.propIsIconOnEvent) {
  95. this.$emit('onicon', {});
  96. }
  97. }
  98. }
  99. };
  100. </script>
  101. <style>
  102. .search-content .search-icon {
  103. line-height: 12px;
  104. left: 10px;
  105. top: calc(50% - 11px);
  106. z-index: 1;
  107. padding: 5px;
  108. }
  109. .search-content input {
  110. font-size: 12px;
  111. padding: 0 15px 0 38px;
  112. box-sizing: border-box;
  113. height: 30px;
  114. line-height: 30px;
  115. }
  116. </style>