//组件调用
//dataTree 树结构数组,isAllChoice 是否全选 0 不选 1全选 isOpenAll true展开 '' 折叠
//type代表当前是否编辑 edit 还是新增 add bind:select选中的新数组
<tree dataTree="{{menuOptionsMerchant}}" isAllChoice="{{isAllChoice2}}" isOpenAll="{{isOpenAll2}}" type="{{type}}" bind:select="handleClick2"></tree>
//展开/折叠树结构、全选/全不选
onChange(field, e) {
var that = this;
const {
value
} = e.detail
const data = this.data[field]
const index = data.indexOf(value)
const current =
index === -1 ? [...data, value] : data.filter((n) => n !== value)
this.setData({
[field]: current,
})
if (field == 'value3') {
let isOpenAll2 = current.findIndex(function (item) {
return item === '1'
})
let isAllChoice2 = current.findIndex(function (item) {
return item === '2'
})
if (isOpenAll2 != -1) {
that.setData({
isOpenAll2: true
})
} else if (isOpenAll2 == -1) {
that.setData({
isOpenAll2: ''
})
}
if (isAllChoice2 != -1) {
that.setData({
isAllChoice2: 1
})
} else if (isAllChoice2 == -1) {
that.setData({
isAllChoice2: 0
})
}
}
},

//获取接口返回的树结构权限
// checkedKeys 选中的权限数组
//menus 原数组
funRecursion(checkedKeys, menus) {
checkedKeys.push('&&&&&&&&');
let temp = checkedKeys.join(',');
menus.forEach(item => {
if (temp.indexOf(item.id + ',') != -1 || item.checked == 1) {
item.checked = 1;
}
if (item.children && item.children.length > 0) {
this.funRecursion(checkedKeys, item.children)
var checkCount = 0;
var scheckCount = 0;
item.children.forEach(chi => {
if (temp.indexOf(chi.id + ',') != -1 || chi.checked == 1) {
checkCount++;
chi.checked = 1;
}
if (chi.checked == -1) {
scheckCount++;
}
})
if (checkCount > 0) {
if (checkCount == item.children.length) {
item.checked = 1;
} else {
item.checked = -1;
}
} else {
if (scheckCount > 0) {
item.checked = -1;
}
}
}
});
// for (let i = 0; i < checkedKeys.length; i++) {
// // 获取当前元素的值作为id
// let currentId = checkedKeys[i];
// // 在response.data.menus中查找与currentId相等的元素
// for (let j = 0; j < menus.length; j++) {
// if (menus[j].id === currentId) {
// // 如果找到了匹配的元素,则将其添加"checked"属性 0未选中、1全选、-1部分选择
// menus[j]["checked"] = 1;
// menus[j]["open"] = false;
// break; // 只处理第一次匹配的情况,因此跳出内部循环
// }
// if (menus[j].children) {
// this.funRecursion(checkedKeys, menus[j].children);
// }
// }
// }
// return
},