searchBox.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <template>
  2. <view class="acea-row search-contain" :style="{'margin-top':searchTop+'px'}">
  3. <text class='iconfont icon-fanhui2' @click="toBack" v-if="toBackShow"></text>
  4. <view class='search-box acea-row row-between-wrapper' :style="[searchBoxStyle]">
  5. <text class='iconfont icon-sousuo2'></text>
  6. <input :value="searchVal" @confirm="inputSearch" type='text' confirm-type='search' name="search" placeholder='点击搜索商品' placeholder-class='placeholder' maxlength="20"></input>
  7. </view>
  8. </view>
  9. </template>
  10. <script>
  11. export default {
  12. props: {
  13. //是否展示返回按钮
  14. toBackShow: {
  15. type: Boolean,
  16. default: true
  17. },
  18. searchValue:{
  19. type: String,
  20. default: ''
  21. }
  22. },
  23. data(){
  24. return{
  25. searchVal:'',
  26. searchTop:0,
  27. searchRight:0,
  28. searchHeight:0,
  29. statusWidth:0,
  30. }
  31. },
  32. watch:{
  33. searchValue(val){
  34. this.searchVal=val
  35. }
  36. },
  37. computed:{
  38. searchBoxStyle(){
  39. return {
  40. height:this.searchHeight + 'px',
  41. flex:1,
  42. marginRight:this.statusWidth + this.searchRight+'px',
  43. }
  44. }
  45. },
  46. created() {
  47. const res = uni.getMenuButtonBoundingClientRect()
  48. this.searchTop=uni.getMenuButtonBoundingClientRect().top
  49. const statusRight = res.right //胶囊右边界坐标
  50. const jnHeight = res.height //胶囊高度
  51. this.statusWidth= res.width
  52. this.searchHeight=jnHeight
  53. //搜索框宽度计算
  54. uni.getSystemInfo({
  55. success:res=>{
  56. this.searchRight=res.windowWidth-statusRight
  57. }
  58. })
  59. },
  60. methods:{
  61. inputSearch(e){
  62. this.$emit('searchChange',e)
  63. },
  64. toBack(){
  65. uni.navigateBack()
  66. }
  67. }
  68. }
  69. </script>
  70. <style scoped lang="scss">
  71. .search-contain{
  72. padding: 0 20rpx 10rpx 0;
  73. }
  74. .search-box {
  75. margin-left: 16rpx;
  76. background-color: #f7f7f7;
  77. border-radius: 33rpx;
  78. padding: 0 35rpx;
  79. box-sizing: border-box;
  80. height: 66rpx;
  81. }
  82. .icon-fanhui2{
  83. line-height: 66rpx;
  84. }
  85. .search-box input {
  86. width: 90%;
  87. font-size: 26rpx;
  88. }
  89. .search-box .placeholder {
  90. color: #bbb;
  91. }
  92. .search-box .iconfont {
  93. color: #000;
  94. font-size: 35rpx;
  95. }
  96. </style>