html部分:
<el-cascader clearable :change-on-select="true" class="ml10" :options="chanceSourceType" v-model="chanceSourceArr" @active-item-change="chanceSourceChangeHandle" @change="chanceSourceChangeHandle" :props="props" :placeholder="defaultPlaceholder">
</el-cascader>
javascript部分:
//选择数据
chanceSourceChangeHandle(va) {
// console.log(va,'va')
this.getLastItem(this.chanceSourceType, va, 'id')
API.zhuxinGoodsManage.addProductType(va[va.length - 1], (data) => {
if (data.data.length) {
let arr = data.data.map((item) => {
item.children = []
return item
})
this.targetObj.children = arr
// this.childrenList = arr;
} else {
this.targetObj.children = null
}
})
},
// 获取点击得目标对象, key 对应得 值vals 数组(重点部分)
getLastItem(list, vals, key) {
let LIST = list || []
for (let item of LIST) {
if (item[key] === vals[vals.length - 1]) {
//获取当前选中id值对应的对象
this.targetObj = item
if(this.targetObj.productFlag === 1 ) {
this.detail.rzshow = false
} else {
this.detail.rzshow = true
}
break
} else {
this.getLastItem(item.children, vals, key)
}
}
},