index.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <template>
  2. <div @click="handlerClick">
  3. <el-autocomplete
  4. id="autocompleteId"
  5. ref="autocomplete"
  6. v-model="selectItem"
  7. style="width: 100%"
  8. :fetch-suggestions="querySearchAsync"
  9. placeholder="请选择"
  10. :debounce="0"
  11. @select="handleSelect"
  12. />
  13. </div>
  14. </template>
  15. <script>
  16. import { debounce } from '@/utils/common'
  17. export default {
  18. props: {
  19. value: {
  20. type: [String, Number],
  21. default: ''
  22. },
  23. list: {
  24. type: Array,
  25. default: []
  26. },
  27. getData: {
  28. type: Function,
  29. default: () => {}
  30. },
  31. params: {
  32. type: Object,
  33. default: {
  34. type: '',
  35. brandId: ''
  36. }
  37. }
  38. },
  39. data() {
  40. return {
  41. selectItem: this.value
  42. }
  43. },
  44. watch: {
  45. value(newValue) {
  46. this.selectItem = newValue
  47. }
  48. },
  49. methods: {
  50. handlerClick() {
  51. this.$emit('click')
  52. },
  53. handleSelect(value) {
  54. this.selectItem = `${value.other.brandWebsitNumber} ${value.other.brandWebsitName}`
  55. this.$emit('input', value.other.brandWebsitName)
  56. this.$emit('change', value)
  57. },
  58. // debounceChange: debounce(async function (queryString) {
  59. // console.log(333)
  60. // let param = {
  61. // pageNum: 1,
  62. // pageSize: 100,
  63. // keyword: queryString,
  64. // ...this.params
  65. // }
  66. // let res = await this.getData(param)
  67. // this.data = res.data.records.map(v => {
  68. // return {
  69. // value: v.brandWebsitName,
  70. // other: {
  71. // brandWebsitNumber: v.brandWebsitNumber,
  72. // label: v.brandWebsitId,
  73. // brandPkId: v.brandPkId
  74. // }
  75. // }
  76. // })
  77. // console.log(444)
  78. // }, 500),
  79. async querySearchAsync(queryString, cb) {
  80. // if (queryString === '') {
  81. // let param = {
  82. // pageNum: 1,
  83. // pageSize: 100,
  84. // keyword: queryString,
  85. // ...this.params
  86. // }
  87. // let res = await this.getData(param)
  88. // this.data = res.data.records.map(v => {
  89. // return {
  90. // // value: `${v.brandWebsitName} ${v.brandWebsitNumber}`,
  91. // value: v.brandWebsitName,
  92. // other: {
  93. // brandWebsitNumber: v.brandWebsitNumber,
  94. // brandWebsitName: v.brandWebsitName,
  95. // label: v.brandWebsitId,
  96. // brandPkId: v.brandPkId
  97. // }
  98. // }
  99. // })
  100. // } else {
  101. // // console.log(222)
  102. // this.debounceChange(queryString)
  103. // // console.log(555)
  104. // }
  105. // 参数处理
  106. if (queryString) {
  107. queryString = queryString.trim()
  108. const ovalStr = queryString
  109. queryString = queryString.split(' ')
  110. if (queryString.length > 1) {
  111. queryString.splice(0, 1)
  112. queryString = queryString.filter(k => k).join().trim()
  113. } else {
  114. queryString = ovalStr
  115. }
  116. }
  117. const param = {
  118. pageNum: 1,
  119. pageSize: 100,
  120. keyword: queryString,
  121. ...this.params
  122. }
  123. const res = await this.getData(param)
  124. this.data = res.data.records.map(v => {
  125. return {
  126. value: `${v.brandWebsitNumber} ${v.brandWebsitName}`,
  127. // value: v.brandWebsitName,
  128. other: {
  129. brandWebsitNumber: v.brandWebsitNumber,
  130. brandWebsitName: v.brandWebsitName,
  131. label: v.brandWebsitId,
  132. brandPkId: v.brandPkId,
  133. sysWebsitNumber: v.sysWebsitNumber
  134. }
  135. }
  136. })
  137. // let data = this.data.filter(item => ~item.value.indexOf(queryString))
  138. cb(this.data)
  139. }
  140. }
  141. }
  142. </script>
  143. <style></style>