选人插件修改完毕

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

View File

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