index.vue 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <template>
  2. <div @click="handlerClick">
  3. <el-autocomplete
  4. clearable
  5. id="autocompleteId"
  6. ref="autocomplete"
  7. style="width: 100%"
  8. v-model="selectItem"
  9. :fetch-suggestions="querySearchAsync"
  10. placeholder="请选择"
  11. :debounce="0"
  12. @select="handleSelect"
  13. ></el-autocomplete>
  14. </div>
  15. </template>
  16. <script>
  17. export default {
  18. props: {
  19. value: {
  20. type: [String, Number],
  21. default: ''
  22. },
  23. getData: {
  24. type: Function,
  25. default: () => {}
  26. },
  27. params: {
  28. type: Object,
  29. default: {
  30. type: '',
  31. brandId: ''
  32. }
  33. }
  34. },
  35. data() {
  36. return {
  37. selectItem: this.value
  38. }
  39. },
  40. watch: {
  41. value(newValue) {
  42. this.selectItem = newValue
  43. }
  44. },
  45. methods: {
  46. handlerClick() {
  47. this.$emit('click')
  48. },
  49. handleSelect(value) {
  50. this.selectItem = value.value
  51. this.$emit('input', value.value)
  52. this.$emit('change', value)
  53. },
  54. async querySearchAsync(queryString, cb) {
  55. let param = {
  56. pageNum: 1,
  57. pageSize: 100,
  58. params: [
  59. { param: 'a.product_brand_id', compare: '=', value: this.params.productBrandId },
  60. { param: 'a.main_id', compare: '=', value: this.params.mainId },
  61. { param: 'a.small_id', compare: '=', value: this.params.smallId },
  62. { param: 'a.series_id', compare: '=', value: this.params.seriesId },
  63. { param: 'a.name', compare: 'like', value: queryString }
  64. ]
  65. }
  66. let res = await this.getData(param)
  67. this.data = res.data.records.map(v => {
  68. return {
  69. value: `${v.name}`,
  70. other: {
  71. productId: v.productId,
  72. mainImg: v.mainImg,
  73. insideImg: v.insideImg,
  74. outImg: v.outImg,
  75. partImgs: v.partImgs,
  76. otherImgs: v.otherImgs,
  77. smallId: v.smallId,
  78. smallName: v.smallName,
  79. seriesId: v.seriesId,
  80. seriesName: v.seriesName
  81. }
  82. }
  83. })
  84. // let data = this.data.filter(item => ~item.value.indexOf(queryString))
  85. cb(this.data)
  86. }
  87. }
  88. }
  89. </script>
  90. <style></style>