选人插件修改完毕
This commit is contained in:
parent
38f7bdfe8f
commit
0a48f6fb50
|
@ -11,7 +11,6 @@ Page({
|
|||
selectList: [], //已选择的元素列表
|
||||
originalList: [], //最原始的数据列表
|
||||
indexList: [], //存储目录层级的数组,用于准确的返回上一层
|
||||
selectList: [], //已选中的人员列表
|
||||
},
|
||||
|
||||
onLoad: function (options) {
|
||||
|
@ -53,11 +52,21 @@ Page({
|
|||
this._getUserByGroup(item)
|
||||
} else {
|
||||
//children的长度不为0时,更新 currentList
|
||||
let currentList = item.children
|
||||
let selectids = []
|
||||
for (var i=0;i<this.data.selectList.length;i++){
|
||||
selectids.push(this.data.selectList[i].id)
|
||||
}
|
||||
for(var i =0;i<currentList.length;i++){
|
||||
if (currentList[i].isPeople && selectids.indexOf(currentList[i]['id'].toString())>=0){
|
||||
currentList[i]['checked'] = true
|
||||
}else{
|
||||
currentList[i]['checked'] = false
|
||||
}
|
||||
}
|
||||
this.setData({
|
||||
currentList: item.children
|
||||
currentList: currentList,
|
||||
})
|
||||
|
||||
|
||||
}
|
||||
//将当前的索引存入索引目录中。索引多一个表示目录多一级
|
||||
let indexes = this.data.indexList
|
||||
|
@ -67,7 +76,8 @@ Page({
|
|||
indexList: indexes
|
||||
})
|
||||
//清空上次选中的元素列表,并设置上一层的选中状态给lastTimeSelect
|
||||
// this.setLastTimeSelectList();
|
||||
|
||||
this.setLastTimeSelectList();
|
||||
|
||||
}
|
||||
},
|
||||
|
@ -79,12 +89,10 @@ Page({
|
|||
if (indexList.length > 0) {
|
||||
//返回时删掉最后一个索引
|
||||
indexList.pop()
|
||||
let currentList = []
|
||||
if (indexList.length == 0) {
|
||||
//indexList长度为0说明回到了最顶层
|
||||
this.setData({
|
||||
currentList: this.data.originalList,
|
||||
indexList: indexList
|
||||
})
|
||||
currentList = this.data.originalList
|
||||
} else {
|
||||
//循环将当前索引的对应数组赋值给currentList
|
||||
let list = this.data.originalList
|
||||
|
@ -92,14 +100,25 @@ Page({
|
|||
let index = indexList[i]
|
||||
list = list[index].children
|
||||
}
|
||||
this.setData({
|
||||
currentList: list,
|
||||
indexList: indexList
|
||||
})
|
||||
currentList = list
|
||||
}
|
||||
//清空上次选中的元素列表,并设置上一层的选中状态给lastTimeSelect
|
||||
//this.setLastTimeSelectList();
|
||||
|
||||
let selectids = []
|
||||
for (var i=0;i<this.data.selectList.length;i++){
|
||||
selectids.push(this.data.selectList[i].id)
|
||||
}
|
||||
for(var i =0;i<currentList.length;i++){
|
||||
if (currentList[i].isPeople && selectids.indexOf(currentList[i]['id'].toString())>=0){
|
||||
currentList[i]['checked'] = true
|
||||
}else{
|
||||
currentList[i]['checked'] = false
|
||||
}
|
||||
}
|
||||
this.setData({
|
||||
currentList: currentList,
|
||||
indexList: indexList
|
||||
})
|
||||
this.setLastTimeSelectList();
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -107,7 +126,7 @@ Page({
|
|||
setLastTimeSelectList() {
|
||||
this.lastTimeSelect = []
|
||||
this.data.currentList.forEach(item => {
|
||||
if (item.checked) {
|
||||
if (item.checked && item.isPeople) {
|
||||
this.lastTimeSelect.push(item)
|
||||
}
|
||||
})
|
||||
|
@ -193,21 +212,19 @@ Page({
|
|||
break;
|
||||
}
|
||||
|
||||
this.setData({
|
||||
originalList: originalList
|
||||
})
|
||||
this.data.originalList = originalList
|
||||
},
|
||||
|
||||
//选框变化回调
|
||||
checkChange(res) {
|
||||
let values = res.detail.value
|
||||
let selectItems = []
|
||||
|
||||
//将值取出拼接成 id,name 格式
|
||||
values.forEach(value => {
|
||||
let arrs = value.split(",")
|
||||
selectItems.push({ id: arrs[0], name: arrs[1] })
|
||||
})
|
||||
|
||||
//将本次选择的与上次选择的比对,本次比上次多说明新增了,本次比上次少说明删除了,找出被删除的那条数据,在footer中也删除
|
||||
if (selectItems.length > this.lastTimeSelect.length) {
|
||||
//将 selectList 与 selectItems 拼接并去重
|
||||
|
@ -246,7 +263,7 @@ Page({
|
|||
selectList: list
|
||||
})
|
||||
}
|
||||
//更新 currentList 选中状态并重新挂载在数据树上,以保存选择状态
|
||||
this.lastTimeSelect = selectItems
|
||||
this.updateCurrentList(this.data.currentList, this.data.selectList)
|
||||
},
|
||||
|
||||
|
@ -290,6 +307,5 @@ Page({
|
|||
currentList: currentList
|
||||
})
|
||||
this.addList2DataTree()
|
||||
this.setLastTimeSelectList()
|
||||
}
|
||||
})
|
Loading…
Reference in New Issue