wbpNavBarSearch.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <template>
  2. <view class="u-f-ajc u-f-jsb wbpNavBar" :style="{ backgroundColor: bgColor }">
  3. <view class="wbp-searchInput">
  4. <input type="text" placeholder="请输入搜索内容" v-model="keyword" @confirm="rightTap" />
  5. <image src="../../static/login/del30.png" v-if="keyword.length > 0" @click="deleteTap"></image>
  6. </view>
  7. <view class="wbp-right-text" :style="{ color: cancelColor }" @click="rightTap" v-if="!searchState">
  8. 取消
  9. </view>
  10. <view class="wbp-right-text" :style="{ color: cancelColor }" @click="rightTap" v-if="searchState">
  11. 搜索
  12. </view>
  13. </view>
  14. </template>
  15. <script>
  16. import util from "@/common/util.js"
  17. export default {
  18. props: {
  19. title: {
  20. type: String,
  21. default: "标题"
  22. },
  23. bgColor: {
  24. type: String,
  25. default: "#ffffff"
  26. },
  27. cancelColor: {
  28. type: String,
  29. default: "#0A0204"
  30. },
  31. },
  32. data() {
  33. return {
  34. keyword: '',
  35. searchState: false
  36. };
  37. },
  38. watch: {
  39. keyword(newVal) {
  40. console.log(newVal)
  41. if (newVal) {
  42. this.$emit("input", newVal);
  43. }
  44. this.searchState = newVal.length
  45. }
  46. },
  47. methods: {
  48. rightTap(e) {
  49. if (!util.isEmpty(e.target.value)) {
  50. this.searchState = true
  51. this.keyword = e.target.value
  52. }
  53. if (this.searchState) {
  54. this.$emit("search", this.keyword)
  55. } else {
  56. this.$emit("cancel")
  57. }
  58. },
  59. deleteTap() {
  60. this.keyword = '';
  61. this.$emit('delete');
  62. }
  63. }
  64. }
  65. </script>
  66. <style lang="scss" scoped>
  67. .wbpNavBar {
  68. /* #ifdef MP-WEIXIN */
  69. width: 550rpx;
  70. margin-right: 200rpx;
  71. /* #endif */
  72. background-color: #ff0000;
  73. /* #ifdef APP-PLUS */
  74. width: 750rpx;
  75. /* #endif */
  76. height: 88rpx;
  77. display: flex;
  78. justify-content: space-between;
  79. align-items: center;
  80. .wbp-back-content {
  81. height: 100%;
  82. display: flex;
  83. justify-content: flex-end;
  84. align-items: center;
  85. .wbp-back {
  86. width: 40rpx;
  87. height: 40rpx;
  88. margin-left: 30rpx;
  89. }
  90. }
  91. .wbp-searchInput {
  92. background-color: #efefef;
  93. width: 600rpx;
  94. height: 30px;
  95. border-radius: 15px;
  96. margin: 30rpx;
  97. display: flex;
  98. flex-direction: row;
  99. align-items: center;
  100. input {
  101. background-color: #efefef;
  102. width: 100%;
  103. height: 30px;
  104. border-radius: 15px;
  105. line-height: 30rpx;
  106. text-indent: 30rpx;
  107. }
  108. image {
  109. width: 30rpx;
  110. height: 30rpx;
  111. margin-left: -45rpx;
  112. }
  113. }
  114. .wbp-title {
  115. font-size: 36rpx;
  116. color: #0a0204;
  117. }
  118. .wbp-right-text {
  119. text-align: center;
  120. width: 90rpx;
  121. height: 40rpx;
  122. margin-right: 30rpx;
  123. color: #232323;
  124. }
  125. }
  126. </style>