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