diff --git a/src/views/modules/shequzhili/event/cpts/add.vue b/src/views/modules/shequzhili/event/cpts/add.vue index aa4820a8d..4e063fd7a 100644 --- a/src/views/modules/shequzhili/event/cpts/add.vue +++ b/src/views/modules/shequzhili/event/cpts/add.vue @@ -326,11 +326,11 @@ export default { } }, async getCategoryList() { - const url = "/governance/issueprojectcategorydict/list"; + const url = "/governance/icEvent/getCategoryTree"; let params = {}; const { data, code, msg } = await requestPost(url, params); if (code === 0) { - let treeDataNew = this.filterTree(data); + let treeDataNew = this.deepTree(data, "children"); // this.categrayList = data //组织级联数据 ++this.iscascaderShow; @@ -343,18 +343,19 @@ export default { }, //重构树,去除网格 - filterTree(arr) { - let childs = arr; - for (let i = childs.length; i--; i > 0) { - if (childs[i].subCategory) { - if (childs[i].subCategory.length) { - this.filterTree(childs[i].subCategory); - } else { - delete childs[i].subCategory; - } - } + deepTree(arr, children) { + if (Array.isArray(arr) && arr.length > 0) { + return arr.map((item) => { + return { + ...item, + [children]: + (item[children] && + item[children].length > 0 && + this.deepTree(item[children], children)) || + null, + }; + }); } - return arr; }, handleChangeAgency(value) { diff --git a/src/views/modules/shequzhili/event/cpts/event-info.vue b/src/views/modules/shequzhili/event/cpts/event-info.vue index c83666aa3..3b0283f1b 100644 --- a/src/views/modules/shequzhili/event/cpts/event-info.vue +++ b/src/views/modules/shequzhili/event/cpts/event-info.vue @@ -366,7 +366,6 @@ export default { }, async handelAdd() { - debugger this.$refs.ref_add.getEventInfo(); if (this.$refs.ref_add.okflag) { this.eventInfoData = this.$refs.ref_add.formData; diff --git a/src/views/modules/shequzhili/event/cpts/process-form-designate.vue b/src/views/modules/shequzhili/event/cpts/process-form-designate.vue index 81ff219b3..f1ebf59f9 100644 --- a/src/views/modules/shequzhili/event/cpts/process-form-designate.vue +++ b/src/views/modules/shequzhili/event/cpts/process-form-designate.vue @@ -87,8 +87,8 @@ export default { optionProps: { multiple: false, value: "id", - label: "name", - children: "subCategory", + label: "categoryName", + children: "children", }, dataRule: { content: [ @@ -163,12 +163,11 @@ export default { } }, async getCategoryList() { - const url = "/governance/issueprojectcategorydict/list"; + const url = '/governance/icEvent/getCategoryTree'; let params = {}; const { data, code, msg } = await requestPost(url, params); if (code === 0) { - let treeDataNew = this.filterTree(data); - //组织级联数据 + let treeDataNew = this.deepTree(data, "children"); ++this.iscascaderShow; this.casOptions = []; this.casOptions = treeDataNew; @@ -182,7 +181,6 @@ export default { this.formData.orgType = obj.level === 'grid' ? 'grid' : 'agency' this.formData.deptId = obj.agencyId this.formData.deptName = obj.agencyName - } else { this.form.orgType = '' this.form.orgId = '' @@ -198,18 +196,19 @@ export default { } }, //重构树,去除网格 - filterTree(arr) { - let childs = arr; - for (let i = childs.length; i--; i > 0) { - if (childs[i].subCategory) { - if (childs[i].subCategory.length) { - this.filterTree(childs[i].subCategory); - } else { - delete childs[i].subCategory; - } - } + deepTree(arr, children) { + if (Array.isArray(arr) && arr.length > 0) { + return arr.map((item) => { + return { + ...item, + [children]: + (item[children] && + item[children].length > 0 && + this.deepTree(item[children], children)) || + null, + }; + }); } - return arr; }, async getReplayInfo() { this.okflag = false; diff --git a/src/views/modules/shequzhili/event/cpts/process-form-replay-end.vue b/src/views/modules/shequzhili/event/cpts/process-form-replay-end.vue index 2a001ba74..9cad30838 100644 --- a/src/views/modules/shequzhili/event/cpts/process-form-replay-end.vue +++ b/src/views/modules/shequzhili/event/cpts/process-form-replay-end.vue @@ -64,9 +64,9 @@ export default { iscascaderShow: 0, optionProps: { multiple: false, - value: 'id', - label: 'name', - children: 'subCategory', + value: "id", + label: "categoryName", + children: "children", }, dataRule: { content: [ @@ -115,11 +115,11 @@ export default { methods: { async getCategoryList() { - const url = '/governance/issueprojectcategorydict/list'; + const url = '/governance/icEvent/getCategoryTree'; let params = {}; const { data, code, msg } = await requestPost(url, params); if (code === 0) { - let treeDataNew = this.filterTree(data); + let treeDataNew = this.deepTree(data, "children"); //组织级联数据 ++this.iscascaderShow; this.casOptions = []; @@ -136,18 +136,19 @@ export default { } }, //重构树,去除网格 - filterTree(arr) { - let childs = arr; - for (let i = childs.length; i--; i > 0) { - if (childs[i].subCategory) { - if (childs[i].subCategory.length) { - this.filterTree(childs[i].subCategory); - } else { - delete childs[i].subCategory; - } - } + deepTree(arr, children) { + if (Array.isArray(arr) && arr.length > 0) { + return arr.map((item) => { + return { + ...item, + [children]: + (item[children] && + item[children].length > 0 && + this.deepTree(item[children], children)) || + null, + }; + }); } - return arr; }, async getReplayInfo() { this.okflag = false; diff --git a/src/views/modules/shequzhili/event/cpts/process-form-replay.vue b/src/views/modules/shequzhili/event/cpts/process-form-replay.vue index 99e59b87e..770c697cc 100644 --- a/src/views/modules/shequzhili/event/cpts/process-form-replay.vue +++ b/src/views/modules/shequzhili/event/cpts/process-form-replay.vue @@ -61,9 +61,10 @@ export default { iscascaderShow: 0, optionProps: { multiple: false, - value: 'id', - label: 'name', - children: 'subCategory', + value: "id", + label: "categoryName", + children: "children", + level: 'categoryType' }, dataRule: { content: [ @@ -110,20 +111,19 @@ export default { if (this.eventId) { this.eventDetailCopy = JSON.parse(JSON.stringify(this.eventDetailData)); // 这一步接收到eventDetailCopy在这里回填 - if (this.eventDetailCopy.parentCategoryId && this.eventDetailCopy.categoryId) { + if (this.eventDetailCopy.categoryId) { this.formData.categoryId = this.eventDetailCopy.categoryId - this.selCategoryArray.push(this.eventDetailCopy.parentCategoryId, this.eventDetailCopy.categoryId) } } }, methods: { async getCategoryList() { - const url = '/governance/issueprojectcategorydict/list'; + const url = '/governance/icEvent/getCategoryTree'; let params = {}; const { data, code, msg } = await requestPost(url, params); if (code === 0) { - let treeDataNew = this.filterTree(data); + let treeDataNew = this.deepTree(data, "children"); //组织级联数据 ++this.iscascaderShow; this.casOptions = []; @@ -131,6 +131,26 @@ export default { } else { this.$message.error(msg); } + if (this.eventDetailCopy.parentCategoryId) { + let pids = this.eventDetailCopy.parentCategoryId.split(','); + pids.push(this.eventDetailCopy.categoryId) + pids.forEach(id => { + let node = this.buildTree(this.casOptions, toString(id)); + this.selCategoryArray.push(node) + }); + let node = this.buildTree(this.casOptions, this.eventDetailCopy.categoryId); + this.selCategoryArray.push(node); + console.log(this.selCategoryArray); + } + }, + buildTree(nodes, treeId) { + nodes.forEach(item => { + if (treeId === item.id) { + return item; + } else { + this.buildTree(item.children, treeId) + } + }) }, handleChangeCate() { if (this.selCateObj = this.$refs['myCascader'].getCheckedNodes()[0]) { @@ -140,18 +160,19 @@ export default { } }, //重构树,去除网格 - filterTree(arr) { - let childs = arr; - for (let i = childs.length; i--; i > 0) { - if (childs[i].subCategory) { - if (childs[i].subCategory.length) { - this.filterTree(childs[i].subCategory); - } else { - delete childs[i].subCategory; - } - } + deepTree(arr, children) { + if (Array.isArray(arr) && arr.length > 0) { + return arr.map((item) => { + return { + ...item, + [children]: + (item[children] && + item[children].length > 0 && + this.deepTree(item[children], children)) || + null, + }; + }); } - return arr; }, async getReplayInfo() { this.okflag = false; diff --git a/src/views/modules/shequzhili/event/eventList.vue b/src/views/modules/shequzhili/event/eventList.vue index 86a1d013b..7a5e4dbdb 100644 --- a/src/views/modules/shequzhili/event/eventList.vue +++ b/src/views/modules/shequzhili/event/eventList.vue @@ -27,8 +27,8 @@ multiple: true, checkStrictly: false, emitPath: false, - children: 'subCategory', - label: 'name', + children: 'children', + label: 'categoryName', value: 'id', }" clearable class="u-item-width-normal" @change="handleEventType" />