1.在子组件里面传form,在父组件区分不同的id
<div>
<el-form :model="Form" :rules="aRules" ref="Form">
<el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
<el-form-item prop="villageId" style="width:100%" >
<el-select
class="widthVillage"
clearable
v-model="tempVillageValue"
filterable
placeholder="请选择小区"
@change="handleChangeVillage"
size="medium">
<el-option
v-for="item in villageSelect"
:key="item.villageId"
:value="item.villageId"
:label="item.villageName">
</el-option>
</el-select>
</el-form-item>
</el-col>
<el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
<el-form-item prop="nameId" style="width:100%" >
<el-select
class="widthVillage"
clearable
v-model="tempPayValue"
filterable
placeholder="请选择收费项目"
@change="handleChangePay"
size="medium">
<el-option
v-for="item in paySelect"
:key="item.name_id"
:value="item.name_id"
:label="item.name">
</el-option>
</el-select>
</el-form-item>
</el-col>
</el-form>
</div>
js
//小区选中
handleChangeVillage(villageId) {
//选中的id必须给验证的id
this.Form.villageId=villageId;
//记住这里传form,在父级区分不同的id
this.$emit('village-pay-tree',this.Form);
//点击小区调用收费项目接口
api.getNameGroupList(JSON.stringify({'villageId':villageId})).then(res=>{
if(res.code==200) {
this.paySelect=res.data;
}
})
},
//选中收费项目
handleChangePay(nameId){
//选中的id必须给验证的id
this.Form.nameId=nameId;
//记住这里传form,在父级区分不同的id
this.$emit('village-pay-tree',this.Form);
}
父组件
getVillagePayTree(data){
//在这里区分不同的id
if (data.villageId) {
this.addForm.vallageId=data.villageId;
}else {
this.addForm.vallageId = '';
}
//收费项目id
//在这里区分不同的id
if (data.nameId) {
this.addForm.nameId=data.nameId;
} else {
this.addForm.nameId = '';
}
},