index.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <template>
  2. <view class="zs-search" :class="[fixed?'fixed':'']">
  3. <input :readOnly="readOnly" :class="[showPrefix?'input':'fullwidInput']" :style="{lineHeight:height+'rpx',height:height+'rpx',borderRadius:height / 2+'px',color:color,background:bgColor}" :type="type" v-model="value" :placeholder="placeholder" />
  4. <image v-if="showPrefix" class="icon" src="../../static/search.png" mode=""></image>
  5. <button v-if="showBtn" class="btn" type="default" @click="search">搜索</button>
  6. </view>
  7. </template>
  8. <script>
  9. export default {
  10. props: {
  11. type: {
  12. type: String,
  13. default: 'text'
  14. },
  15. readOnly:{
  16. type: Boolean,
  17. default: false
  18. },
  19. height: {
  20. type: String,
  21. default: '72'
  22. },
  23. color: {
  24. type: String,
  25. default: '#606266'
  26. },
  27. bgColor:{
  28. type: String,
  29. default: '#efefef'
  30. },
  31. fixed:{
  32. type: Boolean,
  33. default: false
  34. },
  35. value:{
  36. },
  37. placeholder:{
  38. type: String,
  39. default: '搜索'
  40. },
  41. showBtn:{
  42. type: Boolean,
  43. default: true
  44. },
  45. showPrefix:{
  46. type: Boolean,
  47. default: true
  48. }
  49. },
  50. data() {
  51. return {
  52. value1:this.value
  53. }
  54. },
  55. onReady(res) {
  56. },
  57. onLoad(){
  58. },
  59. methods: {
  60. input(val){
  61. this.$emit('input',this.value1 )
  62. },
  63. search(){
  64. this.$emit('search',this.value1)
  65. }
  66. }
  67. }
  68. </script>
  69. <style lang="scss">
  70. .zs-search{
  71. box-sizing: border-box;
  72. top: 0%;
  73. left: 0;
  74. position: relative;
  75. margin: 0 20rpx;
  76. .input{
  77. box-sizing: border-box;
  78. padding-left: 100rpx;
  79. padding-right: 130rpx;
  80. }
  81. .fullwidInput{
  82. // width: 100vw;
  83. box-sizing: border-box;
  84. font-size: 22rpx;
  85. padding-left: 20rpx;
  86. padding-right: 130rpx;
  87. }
  88. .icon {
  89. width: 37rpx;
  90. height: 37rpx;
  91. position: absolute;
  92. top: 50%;
  93. left: 36rpx;
  94. transform: translateY(-50%);
  95. }
  96. .btn {
  97. position: absolute;
  98. top: 50%;
  99. transform: translateY(-50%);
  100. right: 10rpx;
  101. width: 128rpx;
  102. height: 56rpx;
  103. line-height: 56rpx;
  104. background: #FF4C3A;
  105. color: #fff;
  106. font-size: 28rpx;
  107. border-radius: 32rpx;
  108. padding: 0;
  109. }
  110. }
  111. .fixed{
  112. position: fixed !important;
  113. }
  114. </style>