seiminSearch.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <template>
  2. <view class="serach">
  3. <view class="content" :style="{'border-radius':radius+'px'}">
  4. <!-- HM修改 增加进入输入状态的点击范围 -->
  5. <view class="content-box" :class="{'center':mode === 2}">
  6. <text class="icon icon-serach"></text>
  7. <!-- HM修改 增加placeholder input confirm-type confirm-->
  8. <input :placeholder="placeholder" @input="inputChange" confirm-type="search" @confirm="triggerConfirm"
  9. class="input" :class="{'center':!active && mode === 2}" :focus="isFocus" v-model="inputVal" @focus="focus"
  10. @blur="blur" />
  11. <!-- HM修改 @click换成@click.stop阻止冒泡 -->
  12. <text v-if="isDelShow" class="icon icon-del" @click.stop="clear"></text>
  13. </view>
  14. <view v-show="(active&&show&&button === 'inside')||(isDelShow && button === 'inside')" class="serachBtn"
  15. @click="search">
  16. 搜索
  17. </view>
  18. </view>
  19. <view v-if="button === 'outside'" class="button" :class="{'active':show||active}" @click="search">
  20. <view class="button-item">{{!show?searchName:'搜索'}}</view>
  21. </view>
  22. </view>
  23. </template>
  24. <script>
  25. export default {
  26. name: 'seiminSearch',
  27. props: {
  28. mode: {
  29. value: Number,
  30. default: 1
  31. },
  32. placeholder: {
  33. value: String,
  34. default: '请输入搜索内容'
  35. },
  36. value: {
  37. type: String,
  38. default: ''
  39. },
  40. button: {
  41. value: String,
  42. default: 'outside'
  43. },
  44. show: {
  45. value: Boolean,
  46. default: true
  47. },
  48. radius: {
  49. value: String,
  50. default: 60
  51. }
  52. },
  53. data() {
  54. return {
  55. active: false,
  56. inputVal: '',
  57. searchName: '取消',
  58. isDelShow: false,
  59. isFocus: true
  60. };
  61. },
  62. methods: {
  63. //HM修改 触发组件confirm事件
  64. triggerConfirm() {
  65. this.$emit('confirm', false);
  66. },
  67. //HM修改 触发组件input事件
  68. inputChange(event) {
  69. var keyword = event.detail.value;
  70. this.$emit('input', keyword);
  71. if (this.inputVal) {
  72. this.isDelShow = true;
  73. }
  74. },
  75. focus() {
  76. this.active = true;
  77. //HM修改 增加获取焦点判断
  78. if (this.inputVal) {
  79. this.isDelShow = true;
  80. }
  81. },
  82. blur() {
  83. console.log('blur');
  84. this.isFocus = false;
  85. if (!this.inputVal) {
  86. this.active = false;
  87. }
  88. },
  89. clear() {
  90. //HM修改 收起键盘
  91. // uni.hideKeyboard();
  92. // this.isFocus = false;
  93. this.isFocus = true;
  94. this.inputVal = '';
  95. this.active = false;
  96. //HM修改 清空内容时候触发组件input
  97. this.$emit('input', '');
  98. },
  99. getFocus() {
  100. if (!this.isFocus) {
  101. this.isFocus = true;
  102. }
  103. },
  104. search() {
  105. //HM修改 增加点击取消时候退出输入状态,内容为空时,输入默认关键字
  106. if (!this.inputVal) {
  107. if (!this.show && this.searchName == '取消') {
  108. uni.hideKeyboard();
  109. this.isFocus = false;
  110. this.active = false;
  111. return;
  112. }
  113. }
  114. console.log(this.inputVal);
  115. // this.$emit('search', this.inputVal ? this.inputVal : this.placeholder);
  116. }
  117. },
  118. watch: {
  119. inputVal(newVal) {
  120. if (newVal) {
  121. this.searchName = '搜索';
  122. } else {
  123. this.searchName = '取消';
  124. this.isDelShow = false;
  125. }
  126. },
  127. //HM修改 双向绑定
  128. value(val) {
  129. this.inputVal = val;
  130. },
  131. }
  132. };
  133. </script>
  134. <style lang="scss">
  135. .serach {
  136. display: flex;
  137. width: 100%;
  138. box-sizing: border-box;
  139. font-size: $uni-font-size-base;
  140. .content {
  141. display: flex;
  142. align-items: center;
  143. width: 100%;
  144. height: 60upx;
  145. background: #fff;
  146. overflow: hidden;
  147. transition: all 0.2s linear;
  148. border-radius: 30px;
  149. .content-box {
  150. width: 100%;
  151. display: flex;
  152. align-items: center;
  153. &.center {
  154. justify-content: center;
  155. }
  156. .icon {
  157. padding: 0 15upx;
  158. &.icon-del {
  159. font-size: 38upx;
  160. &:before {
  161. content: "\e644";
  162. }
  163. }
  164. &.icon-serach:before {
  165. content: "\e61c";
  166. }
  167. }
  168. .input {
  169. width: 100%;
  170. max-width: 100%;
  171. line-height: 60upx;
  172. height: 60upx;
  173. transition: all 0.2s linear;
  174. &.center {
  175. width: 600upx;
  176. }
  177. &.sub {
  178. width: auto;
  179. color: grey;
  180. }
  181. }
  182. }
  183. .serachBtn {
  184. height: 100%;
  185. flex-shrink: 0;
  186. padding: 0 30upx;
  187. background: linear-gradient(to right, #72c172, #3bb197);
  188. line-height: 60upx;
  189. color: #fff;
  190. transition: all 0.3s;
  191. }
  192. }
  193. .button {
  194. display: flex;
  195. align-items: center;
  196. justify-content: center;
  197. position: relative;
  198. flex-shrink: 0;
  199. width: 0;
  200. transition: all 0.2s linear;
  201. white-space: nowrap;
  202. overflow: hidden;
  203. &.active {
  204. padding-left: 15upx;
  205. width: 100upx;
  206. }
  207. }
  208. }
  209. //HM修改 把字体改成本地加载
  210. @font-face {
  211. font-family: "iconfont";
  212. src: url('data:application/x-font-woff;charset=utf-8;base64,AAEAAAALAIAAAwAwR1NVQrD+s+0AAAE4AAAAQk9TLzI8fEg3AAABfAAAAFZjbWFws6gbWQAAAeQAAAGcZ2x5ZqgAaogAAAOMAAABMGhlYWQTyEk0AAAA4AAAADZoaGVhB90DhQAAALwAAAAkaG10eBAA//8AAAHUAAAAEGxvY2EA0gBOAAADgAAAAAptYXhwARIANgAAARgAAAAgbmFtZT5U/n0AAAS8AAACbXBvc3SanfjSAAAHLAAAAEUAAQAAA4D/gABcBAD//wAABAAAAQAAAAAAAAAAAAAAAAAAAAQAAQAAAAEAAL8Cm/NfDzz1AAsEAAAAAADYVQKbAAAAANhVApv///+ABAADgQAAAAgAAgAAAAAAAAABAAAABAAqAAQAAAAAAAIAAAAKAAoAAAD/A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');
  213. }
  214. .icon {
  215. font-family: iconfont;
  216. font-size: 32upx;
  217. font-style: normal;
  218. color: #999;
  219. }
  220. </style>