SearchBox.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <template>
  2. <view class='search-content'>
  3. <!-- 首页搜索 -->
  4. <view class="search-box" v-if="typeFlag == 'base'" @click="toPage">
  5. <view class="search-left">
  6. <text class="icon">&#xe710;</text>
  7. <input type="text" value="" placeholder="搜索商品名称/品牌/品类" disabled="false" />
  8. </view>
  9. <text class="search-btn">搜索</text>
  10. </view>
  11. <!-- 搜索页面搜索 -->
  12. <view class="search-box1" v-if="typeFlag == 'searchPage'">
  13. <view class="search-left1">
  14. <text class="icon1">&#xe710;</text>
  15. <input type="text" class="input-styl1" placeholder-class="placeholder" confirm-type="search" :value="searchContent" @input="changeInput"
  16. @confirm="inputSearch" placeholder="搜索商品名称" />
  17. <text class="icon1" v-if="iconShow == true" @click="deleteContent">&#xe70e;</text>
  18. </view>
  19. <text class="search-btn1" @click="clickCancel">取消</text>
  20. </view>
  21. </view>
  22. </template>
  23. <script lang='ts'>
  24. import {
  25. Component,
  26. Prop,
  27. Watch,
  28. Emit,
  29. Vue
  30. } from 'vue-property-decorator';
  31. @Component({})
  32. export default class SearchBox extends Vue {
  33. @Prop({
  34. default: "base"
  35. }) private typeFlag ? : string; //搜索框类型
  36. @Prop({
  37. default: ""
  38. }) private searchTitle ? : string; //搜索内容 父->子
  39. searchContent: string = ''; //搜索框内容
  40. iconShow: boolean = false; //搜索框删除icon
  41. // methods
  42. //@input修改input内容
  43. changeInput(e: any) {
  44. this.searchContent = e.detail.value;
  45. }
  46. //删除筛选内容
  47. deleteContent() {
  48. this.searchContent = '';
  49. }
  50. //跳转页面
  51. toPage() {
  52. this.$Router.push({
  53. path: '/packages/goods/search',
  54. query: {}
  55. });
  56. }
  57. // emit-----------------------
  58. @Emit('cancelEvent') //点击取消按钮
  59. //点击取消按钮
  60. clickCancel() {
  61. this.searchContent = '';
  62. this.$Router.back(1);
  63. }
  64. @Emit('inputSearch') //点击键盘上的搜索
  65. inputSearch() {
  66. if (this.searchContent == '') {
  67. // uni.showToast({
  68. // title: '请输入搜索内容',
  69. // icon: 'none'
  70. // });
  71. return "";
  72. } else {
  73. return this.searchContent;
  74. }
  75. }
  76. // watch-------------------
  77. @Watch('searchContent') //监听是否有搜索内容,展示删除icon
  78. changeIconShow() {
  79. this.iconShow = this.searchContent !== '';
  80. }
  81. @Watch('searchTitle') //监听父组件点击历史搜索记录,更新搜索title
  82. changeSearchContent() {
  83. if (this.searchTitle !== '') {
  84. this.searchContent = this.searchTitle || '';
  85. }
  86. }
  87. }
  88. </script>
  89. <style lang='scss' scoped>
  90. .search-content {
  91. font-size: vw(14);
  92. .search-box {
  93. @include flex-x();
  94. @include wh(348, 32);
  95. margin: 0 auto;
  96. background-color: #F6F6F6;
  97. border-radius: vw(8);
  98. .search-left {
  99. @include flex-x();
  100. .icon {
  101. margin: 0 vw(10);
  102. @include icon(14);
  103. }
  104. }
  105. .search-btn {
  106. padding-left: vw(12);
  107. margin-right: vw(13);
  108. border-left: 1px solid #E3E3E3;
  109. color: $btn-color;
  110. flex-shrink: 0;
  111. }
  112. }
  113. .search-box1 {
  114. @include flex-x();
  115. @include wh(348, 32);
  116. margin: 0 auto;
  117. .search-left1 {
  118. @include flex-x(flex-start);
  119. @include wh(293, 32);
  120. border-radius: vw(8);
  121. background-color: #F6F6F6;
  122. .icon1 {
  123. margin: 0 vw(10);
  124. @include icon(14);
  125. }
  126. .input-styl1 {
  127. width: 80%;
  128. }
  129. .placeholder{
  130. color: #999;
  131. }
  132. }
  133. .search-btn1 {
  134. padding-left: vw(12);
  135. margin-right: vw(13);
  136. color: $btn-color;
  137. }
  138. }
  139. }
  140. </style>