123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- <template>
- <div @click="handlerClick">
- <el-autocomplete
- id="autocompleteId"
- ref="autocomplete"
- v-model="selectItem"
- style="width: 100%"
- :fetch-suggestions="querySearchAsync"
- placeholder="请选择"
- :debounce="0"
- @select="handleSelect"
- />
- </div>
- </template>
- <script>
- import { debounce } from '@/utils/common'
- export default {
- props: {
- value: {
- type: [String, Number],
- default: ''
- },
- list: {
- type: Array,
- default: []
- },
- getData: {
- type: Function,
- default: () => {}
- },
- params: {
- type: Object,
- default: {
- type: '',
- brandId: ''
- }
- }
- },
- data() {
- return {
- selectItem: this.value
- }
- },
- watch: {
- value(newValue) {
- this.selectItem = newValue
- }
- },
- methods: {
- handlerClick() {
- this.$emit('click')
- },
- handleSelect(value) {
- this.selectItem = `${value.other.brandWebsitNumber} ${value.other.brandWebsitName}`
- this.$emit('input', value.other.brandWebsitName)
- this.$emit('change', value)
- },
- // debounceChange: debounce(async function (queryString) {
- // console.log(333)
- // let param = {
- // pageNum: 1,
- // pageSize: 100,
- // keyword: queryString,
- // ...this.params
- // }
- // let res = await this.getData(param)
- // this.data = res.data.records.map(v => {
- // return {
- // value: v.brandWebsitName,
- // other: {
- // brandWebsitNumber: v.brandWebsitNumber,
- // label: v.brandWebsitId,
- // brandPkId: v.brandPkId
- // }
- // }
- // })
- // console.log(444)
- // }, 500),
- async querySearchAsync(queryString, cb) {
- // if (queryString === '') {
- // let param = {
- // pageNum: 1,
- // pageSize: 100,
- // keyword: queryString,
- // ...this.params
- // }
- // let res = await this.getData(param)
- // this.data = res.data.records.map(v => {
- // return {
- // // value: `${v.brandWebsitName} ${v.brandWebsitNumber}`,
- // value: v.brandWebsitName,
- // other: {
- // brandWebsitNumber: v.brandWebsitNumber,
- // brandWebsitName: v.brandWebsitName,
- // label: v.brandWebsitId,
- // brandPkId: v.brandPkId
- // }
- // }
- // })
- // } else {
- // // console.log(222)
- // this.debounceChange(queryString)
- // // console.log(555)
- // }
- // 参数处理
- if (queryString) {
- queryString = queryString.trim()
- const ovalStr = queryString
- queryString = queryString.split(' ')
- if (queryString.length > 1) {
- queryString.splice(0, 1)
- queryString = queryString.filter(k => k).join().trim()
- } else {
- queryString = ovalStr
- }
- }
- const param = {
- pageNum: 1,
- pageSize: 100,
- keyword: queryString,
- ...this.params
- }
- const res = await this.getData(param)
- this.data = res.data.records.map(v => {
- return {
- value: `${v.brandWebsitNumber} ${v.brandWebsitName}`,
- // value: v.brandWebsitName,
- other: {
- brandWebsitNumber: v.brandWebsitNumber,
- brandWebsitName: v.brandWebsitName,
- label: v.brandWebsitId,
- brandPkId: v.brandPkId,
- sysWebsitNumber: v.sysWebsitNumber
- }
- }
- })
- // let data = this.data.filter(item => ~item.value.indexOf(queryString))
- cb(this.data)
- }
- }
- }
- </script>
- <style></style>
|