|
|
|
@ -11,15 +11,6 @@ |
|
|
|
|
@clear="list = []" |
|
|
|
|
@change="change" |
|
|
|
|
> |
|
|
|
|
<!-- <template v-if="labelIsMore"> |
|
|
|
|
<el-option |
|
|
|
|
v-for="(item, index) in list" |
|
|
|
|
:key="item.id + index" |
|
|
|
|
:label="item[config.labelKey[0]] + '(' + item[config.labelKey[1]] + '-' + item[config.labelKey[2]] + ')'" |
|
|
|
|
:value="item[config.valueKey]" |
|
|
|
|
> |
|
|
|
|
</el-option> |
|
|
|
|
</template> --> |
|
|
|
|
<template> |
|
|
|
|
<el-option v-for="(item, index) in list" :key="index" :label="labelHandler(item)" :value="item[config.valueKey]"> </el-option> |
|
|
|
|
</template> |
|
|
|
@ -33,17 +24,17 @@ export default { |
|
|
|
|
config: Object |
|
|
|
|
// config: { |
|
|
|
|
// serveTarget: {}, // 远程搜索接口 |
|
|
|
|
// autocompleteKey: "", //远程搜索接口参数名 |
|
|
|
|
// labelKey: [] || '', //接口返回数据label |
|
|
|
|
// autocompleteKey: "" || {}, // 远程搜索接口参数名 |
|
|
|
|
// labelKey: "" || [], // 接口返回数据label |
|
|
|
|
// valueKey: "", // 接口返回数据id |
|
|
|
|
// querykey: "", // 查询接口参数名 |
|
|
|
|
// echoId:'', // |
|
|
|
|
// echoId: "", // 用于回显的id |
|
|
|
|
// echoName: "", // 用于回显的name |
|
|
|
|
// }, |
|
|
|
|
}, |
|
|
|
|
data() { |
|
|
|
|
return { |
|
|
|
|
text: '', |
|
|
|
|
// labelIsMore: false, |
|
|
|
|
list: [], |
|
|
|
|
isDisabled: false |
|
|
|
|
} |
|
|
|
@ -51,7 +42,6 @@ export default { |
|
|
|
|
watch: { |
|
|
|
|
'config.echoId': { |
|
|
|
|
handler(nval, oval) { |
|
|
|
|
console.log('nvalnvalnvalnvalnval', nval) |
|
|
|
|
this.list = [] |
|
|
|
|
let type = this.$utils.typeJudgment(this.config.echoName) |
|
|
|
|
if (nval && ['String'].includes(type)) { |
|
|
|
@ -77,18 +67,22 @@ export default { |
|
|
|
|
created() { |
|
|
|
|
let { labelKey } = this.config |
|
|
|
|
let type = this.$utils.typeJudgment(labelKey) |
|
|
|
|
// if (type === 'Array') { |
|
|
|
|
// this.labelIsMore = true |
|
|
|
|
// } |
|
|
|
|
// 重构labelHandler |
|
|
|
|
this.labelHandler = this.labelHandler(type) |
|
|
|
|
// console.log(this.labelHandler()) |
|
|
|
|
}, |
|
|
|
|
methods: { |
|
|
|
|
labelHandler(type) { |
|
|
|
|
if (type === 'Array') { |
|
|
|
|
return item => { |
|
|
|
|
return this.config.labelKey.reduce((prev, cur) => { |
|
|
|
|
prev += /^[^0-9a-zA-Z]/.test(cur) ? cur : item[cur] |
|
|
|
|
let type = this.$utils.typeJudgment(cur) |
|
|
|
|
let _function = |
|
|
|
|
type != 'Function' |
|
|
|
|
? item => { |
|
|
|
|
return /^[^0-9a-zA-Z]/.test(cur) ? cur : item[cur] |
|
|
|
|
} |
|
|
|
|
: cur |
|
|
|
|
prev += _function(item) |
|
|
|
|
return prev |
|
|
|
|
}, '') |
|
|
|
|
} |
|
|
|
@ -99,7 +93,6 @@ export default { |
|
|
|
|
}, |
|
|
|
|
// 远程搜索 |
|
|
|
|
remoteMethod(query) { |
|
|
|
|
console.log('query', query) |
|
|
|
|
if (query !== '') { |
|
|
|
|
this.loading = true |
|
|
|
|
let type = this.$utils.typeJudgment(this.config.autocompleteKey) |
|
|
|
|