searchBox.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <template>
  2. <!-- 灰色背景,用在最顶部 -->
  3. <view>
  4. <view class='header acea-row row-center-wrapper fixed z-999'>
  5. <!-- #ifdef MP -->
  6. <view class="acea-row search-contain w-100-p111- " :style="{'margin-top':searchTop+'px'}">
  7. <text class='iconfont icon-ic_left' @click="toBack" v-if="toBackShow"></text>
  8. <view class='search-box acea-row row-between-wrapper w-100-p111-' :style="[searchBoxStyle]">
  9. <text class='iconfont icon-ic_search'></text>
  10. <input :value="searchVal" @confirm="inputSearch" type='text' confirm-type='search' name="search" placeholder='点击搜索商品' placeholder-class='placeholder' maxlength="20" />
  11. </view>
  12. </view>
  13. <!-- #endif -->
  14. <!-- #ifndef MP -->
  15. <view class='acea-row row-between-wrapper search-input'>
  16. <text class='iconfont icon-ic_search'></text>
  17. <input type='text' placeholder='点击搜索商品' @confirm="inputSearch" confirm-type='search' name="search"
  18. placeholder-class='placeholder' maxlength="20" :value="searchVal"/>
  19. </view>
  20. <!-- #endif -->
  21. </view>
  22. <view class="w-100-p111-" :style="{ 'height' : `${placeholderHeight}rpx`}"></view>
  23. </view>
  24. </template>
  25. <script>
  26. export default {
  27. props: {
  28. //是否展示返回按钮
  29. toBackShow: {
  30. type: Boolean,
  31. default: true
  32. },
  33. searchValue:{
  34. type: String,
  35. default: ''
  36. }
  37. },
  38. data(){
  39. return{
  40. searchVal: this.searchValue,
  41. searchTop:0,
  42. searchRight:0,
  43. searchHeight:0,
  44. statusWidth:0,
  45. }
  46. },
  47. watch:{
  48. searchValue(val){
  49. this.searchVal=val
  50. }
  51. },
  52. computed:{
  53. placeholderHeight(){
  54. // #ifdef MP
  55. return this.searchTop*2 + 66
  56. // #endif
  57. // #ifndef MP
  58. return 96
  59. // #endif
  60. },
  61. cssVarStyle() {
  62. return this.$getCssVarStyle();
  63. },
  64. searchBoxStyle(){
  65. return {
  66. height:this.searchHeight + 'px',
  67. flex:1,
  68. marginRight:this.statusWidth + this.searchRight+'px',
  69. }
  70. }
  71. },
  72. created() {
  73. // #ifdef MP
  74. this.getCalculate();
  75. // #endif
  76. },
  77. methods:{
  78. getCalculate(){
  79. const res = uni.getMenuButtonBoundingClientRect()
  80. this.searchTop=uni.getMenuButtonBoundingClientRect().top
  81. const statusRight = res.right //胶囊右边界坐标
  82. const jnHeight = res.height //胶囊高度
  83. this.statusWidth= res.width
  84. this.searchHeight=jnHeight
  85. //搜索框宽度计算
  86. uni.getSystemInfo({
  87. success:res=>{
  88. this.searchRight=res.windowWidth-statusRight
  89. }
  90. })
  91. },
  92. inputSearch(e){
  93. this.$emit('searchChange',e)
  94. },
  95. toBack(){
  96. uni.navigateBack()
  97. }
  98. }
  99. }
  100. </script>
  101. <style scoped lang="scss">
  102. .header {
  103. width: 100%;
  104. /* #ifndef MP */
  105. height: 96rpx;
  106. /* #endif */
  107. background-color: #fff;
  108. }
  109. .search-input{
  110. width: 700rpx;
  111. height: 60rpx;
  112. background-color: #f5f5f5;
  113. border-radius: 50rpx;
  114. box-sizing: border-box;
  115. padding: 0 30rpx;
  116. .iconfont {
  117. font-size: 28rpx;
  118. color: #555;
  119. }
  120. .placeholder {
  121. color: #999;
  122. }
  123. input {
  124. font-size: 28rpx;
  125. height: 100%;
  126. width: 597rpx;
  127. }
  128. }
  129. .search-contain{
  130. padding: 0 20rpx 10rpx 0;
  131. }
  132. .search-box {
  133. margin-left: 16rpx;
  134. background-color: #f7f7f7;
  135. border-radius: 33rpx;
  136. padding: 0 35rpx;
  137. box-sizing: border-box;
  138. height: 66rpx;
  139. }
  140. .icon-ic_left{
  141. line-height: 66rpx;
  142. }
  143. .search-box input {
  144. width: 90%;
  145. font-size: 26rpx;
  146. }
  147. .search-box .placeholder {
  148. color: #999999;
  149. }
  150. .search-box .iconfont {
  151. color: #999999;
  152. font-size: 24rpx;
  153. }
  154. </style>