From 0a48f6fb5045f4108cb2dc7f5cdb6f18eaca1d88 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Tue, 8 Dec 2020 22:12:48 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=89=E4=BA=BA=E6=8F=92=E4=BB=B6=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E5=AE=8C=E6=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/userSelect/userSelect.js | 66 +++++++++++-------- project.config.json | 114 ++++++++++++++++----------------- 2 files changed, 98 insertions(+), 82 deletions(-) diff --git a/pages/userSelect/userSelect.js b/pages/userSelect/userSelect.js index 8c807a8..212bed7 100644 --- a/pages/userSelect/userSelect.js +++ b/pages/userSelect/userSelect.js @@ -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=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=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() } }) \ No newline at end of file diff --git a/project.config.json b/project.config.json index a86adbf..df17f0e 100644 --- a/project.config.json +++ b/project.config.json @@ -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": [] + } + } } \ No newline at end of file