a-tree-select组件的change修改事件名

This commit is contained in:
yaoyanan
2021-04-07 11:33:05 +08:00
parent ca12ba8129
commit 5172a7997e
2 changed files with 30 additions and 21 deletions
@@ -21,7 +21,11 @@
export default { export default {
name: 'JCategorySelect', name: 'JCategorySelect',
props:{ props: {
value:{
// type: String,
required: false
},
placeholder:{ placeholder:{
type: String, type: String,
default: '请选择', default: '请选择',
@@ -52,7 +56,7 @@
default:'', default:'',
required:false required:false
}, },
pcode:{ pCode:{
type:String, type:String,
default:'', default:'',
required:false required:false
@@ -72,13 +76,14 @@
tableName:"", tableName:"",
text:"", text:"",
code:"", code:"",
} }
}, },
watch: { watch: {
value () { value () {
this.loadItemByCode() this.loadItemByCode()
}, },
pcode(){ pCode(){
this.loadRoot(); this.loadRoot();
} }
}, },
@@ -100,7 +105,7 @@
loadRoot(){ loadRoot(){
let param = { let param = {
pid:this.pid, pid:this.pid,
pcode:!this.pcode?'0':this.pcode, pcode:!this.pCode?'0':this.pCode,
condition:this.condition condition:this.condition
} }
getAction(this.url,param).then(res=>{ getAction(this.url,param).then(res=>{
@@ -127,13 +132,15 @@
}else{ }else{
getAction(this.view,{ids:this.value}).then(res=>{ getAction(this.view,{ids:this.value}).then(res=>{
if(res.success){ if(res.success){
let values = this.value.split(',') if (res.result && res.result.length > 0) {
this.treeValue = res.result.map((item, index) => ({ let values = this.value.split(',')
key: values[index], this.treeValue = res.result.map((item, index) => ({
value: values[index], key: values[index],
label: item value: values[index],
})) label: item
this.onLoadTriggleChange(res.result[0]); }))
this.onLoadTriggleChange(res.result[0]);
}
} }
}) })
} }
@@ -145,12 +152,14 @@
} }
}, },
backValue(value,label){ backValue(value,label){
console.log(label)
let obj = {} let obj = {}
if(this.back){ if(this.back){
obj[this.back] = label obj[this.back] = label
} }
// this.$emit('change', value, obj) /*
* 使用$listeners向上暴露事件---和$emit一起使用出现的问题:change事件会执行两遍
* 解决办法:改变选中时提交的事件名*/
this.$emit('changeValue', value, obj)
}, },
asyncLoadTreeData (treeNode) { asyncLoadTreeData (treeNode) {
return new Promise((resolve) => { return new Promise((resolve) => {
@@ -199,7 +208,10 @@
onChange(value){ onChange(value){
if(!value){ if(!value){
// this.$emit('change', ''); /*
* 使用$listeners向上暴露事件---和$emit一起使用出现的问题:change事件会执行两遍
* 解决办法:改变选中时提交的事件名*/
this.$emit('changeValue', '');
this.treeValue = '' this.treeValue = ''
} else if (Array.isArray(value)) { } else if (Array.isArray(value)) {
let labels = [] let labels = []
@@ -218,13 +230,13 @@
return this.treeData return this.treeData
}, },
validateProp(){ validateProp(){
let mycondition = this.condition let myCondition = this.condition
return new Promise((resolve,reject)=>{ return new Promise((resolve,reject)=>{
if(!mycondition){ if(!myCondition){
resolve(); resolve();
}else{ }else{
try { try {
let test=JSON.parse(mycondition); let test=JSON.parse(myCondition);
if(typeof test == 'object' && test){ if(typeof test == 'object' && test){
resolve() resolve()
}else{ }else{
+1 -4
View File
@@ -277,7 +277,7 @@
<a-row :gutter="24"> <a-row :gutter="24">
<a-col :span="12"> <a-col :span="12">
<a-form-item label="分类字典树"> <a-form-item label="分类字典树">
<j-category-select v-model="formData.selectCategory" pcode="A01" :multiple="true" @change="changeCate"/> <j-category-select v-model="formData.selectCategory" pCode="A01" :multiple="false"/>
</a-form-item> </a-form-item>
</a-col> </a-col>
<a-col :span="12">选中的值(v-model){{ formData.selectCategory }}</a-col> <a-col :span="12">选中的值(v-model){{ formData.selectCategory }}</a-col>
@@ -589,9 +589,6 @@ sayHi('hello, world!')`
} }
}, },
methods: { methods: {
changeCate(){
console.log("ok")
},
getDepartIdValue() { getDepartIdValue() {
return this.form.getFieldValue('departId') return this.form.getFieldValue('departId')
}, },