选人插件修改完毕

This commit is contained in:
caoqianming 2020-12-08 22:12:48 +08:00
parent 38f7bdfe8f
commit 0a48f6fb50
2 changed files with 98 additions and 82 deletions

View File

@ -11,7 +11,6 @@ Page({
selectList: [], //已选择的元素列表
originalList: [], //最原始的数据列表
indexList: [], //存储目录层级的数组,用于准确的返回上一层
selectList: [], //已选中的人员列表
},
onLoad: function (options) {
@ -36,7 +35,7 @@ Page({
let list = res.data.data
this.setData({
currentList: list,
originalList:list
originalList: list
})
}
}
@ -53,11 +52,21 @@ Page({
this._getUserByGroup(item)
} else {
//children的长度不为0时更新 currentList
this.setData({
currentList: item.children
})
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: 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 = []
//将值取出拼接成 idname 格式
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()
}
})

View File

@ -1,59 +1,59 @@
{
"description": "项目配置文件。",
"setting": {
"urlCheck": false,
"es6": true,
"postcss": true,
"minified": true,
"newFeature": true,
"coverView": true,
"nodeModules": true,
"autoAudits": false,
"showShadowRootInWxmlPanel": true,
"scopeDataCheck": false,
"checkInvalidKey": true,
"checkSiteMap": true,
"uploadWithSourceMap": true,
"babelSetting": {
"ignore": [],
"disablePlugins": [],
"outputPath": ""
},
"useIsolateContext": true,
"useCompilerModule": false,
"userConfirmedUseCompilerModuleSwitch": false,
"enhance": false,
"preloadBackgroundData": false,
"uglifyFileName": false,
"compileHotReLoad": false,
"useMultiFrameRuntime": false,
"useApiHook": true,
"packNpmManually": false,
"packNpmRelationList": []
},
"compileType": "miniprogram",
"libVersion": "2.9.4",
"appid": "wx5c39b569f01c27db",
"projectname": "aqyj",
"isGameTourist": false,
"simulatorType": "wechat",
"simulatorPluginLibVersion": {},
"condition": {
"search": {
"current": -1,
"list": []
},
"conversation": {
"current": -1,
"list": []
},
"game": {
"currentL": -1,
"list": []
},
"miniprogram": {
"current": -1,
"list": []
}
}
"description": "项目配置文件。",
"setting": {
"urlCheck": false,
"es6": true,
"postcss": true,
"minified": true,
"newFeature": true,
"coverView": true,
"nodeModules": true,
"autoAudits": false,
"showShadowRootInWxmlPanel": true,
"scopeDataCheck": false,
"checkInvalidKey": true,
"checkSiteMap": true,
"uploadWithSourceMap": true,
"babelSetting": {
"ignore": [],
"disablePlugins": [],
"outputPath": ""
},
"useIsolateContext": true,
"useCompilerModule": false,
"userConfirmedUseCompilerModuleSwitch": false,
"enhance": false,
"preloadBackgroundData": false,
"uglifyFileName": false,
"compileHotReLoad": false,
"useMultiFrameRuntime": false,
"useApiHook": true,
"packNpmManually": false,
"packNpmRelationList": []
},
"compileType": "miniprogram",
"libVersion": "2.9.4",
"appid": "wx5c39b569f01c27db",
"projectname": "aqyj",
"isGameTourist": false,
"simulatorType": "wechat",
"simulatorPluginLibVersion": {},
"condition": {
"search": {
"current": -1,
"list": []
},
"conversation": {
"current": -1,
"list": []
},
"game": {
"currentL": -1,
"list": []
},
"miniprogram": {
"current": -1,
"list": []
}
}
}