searchSelect.vue 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <template>
  2. <view>
  3. <view class="searchSelect shadow" v-if="flag">
  4. <view class="cu-bar search bg-white">
  5. <view class="search-form round" style="margin-top:0">
  6. <input @focus="InputFocus" @blur="InputBlur" @input="handleInput()" v-model="searchInput"
  7. :adjust-position="false" type="text" placeholder="" confirm-type="search"
  8. style="border:none"></input>
  9. <!-- <text class="cuIcon-search "></text> -->
  10. </view>
  11. </view>
  12. <view class="select-items">
  13. <view class="select-item" v-for="(item,index) in searchList" @click="clickSelectItem(item,index)"
  14. :key="index">{{item}}</view>
  15. </view>
  16. </view>
  17. </view>
  18. </template>
  19. <script>
  20. export default {
  21. name: 'searchSelect',
  22. props: {
  23. flag: {
  24. type: Boolean,
  25. default: false
  26. },
  27. searchList: {
  28. type: Array,
  29. // default: []
  30. },
  31. searchList2: {
  32. type: Array,
  33. // default: []
  34. }
  35. },
  36. data() {
  37. return {
  38. searchInput: '',
  39. // flag: false,
  40. // searchList: [],
  41. // searchList2: [],
  42. }
  43. },
  44. onload() {
  45. this.getSearchList();
  46. },
  47. methods: {
  48. //请求
  49. async getSearchList(ming = {}) {
  50. const res = await this.$myRequest({
  51. url: 'Index/getSiteDropDownBox',
  52. data: ming
  53. })
  54. res.data.data.forEach(item => {
  55. this.searchList.push(item.siteName)
  56. this.searchList2.push(item.siteName)
  57. });
  58. },
  59. // 下拉选择
  60. clickSelectItem(item, index) {
  61. this.getSearchList({
  62. "siteName": item
  63. });
  64. this.flag = false
  65. },
  66. handleInput() {
  67. var newlist = this.searchList2.filter(item => item.indexOf(this.searchInput) > -1)
  68. this.searchList = newlist
  69. },
  70. InputFocus(e) {
  71. this.InputBottom = e.detail.height
  72. },
  73. InputBlur(e) {
  74. this.InputBottom = 0
  75. },
  76. changeTab(Inv) {
  77. that.navIdx = Inv;
  78. }
  79. }
  80. }
  81. </script>
  82. <style>
  83. </style>