提交 2ebfd867 编写于 作者: zhujiamin's avatar zhujiamin

添加自动分组情况

上级 aabf76ee
...@@ -157,13 +157,21 @@ ...@@ -157,13 +157,21 @@
public isEnableGroup:boolean = <#if ctrl.isEnableGroup?? && ctrl.isEnableGroup()??> ${ctrl.isEnableGroup()?c}<#else>false</#if>; public isEnableGroup:boolean = <#if ctrl.isEnableGroup?? && ctrl.isEnableGroup()??> ${ctrl.isEnableGroup()?c}<#else>false</#if>;
/** /**
* 分组细节 * 代码表分组细节
* *
* @type {boolean} * @type {Object}
* @memberof ${srfclassname('${ctrl.codeName}')} * @memberof ${srfclassname('${ctrl.codeName}')}
*/ */
public group_detail:any = <#if ctrl.getGroupPSCodeList?? && ctrl.getGroupPSCodeList()?? && ctrl.getGroupPSCodeList().getAllPSCodeItems?? && ctrl.getGroupPSCodeList().getAllPSCodeItems()??> <#assign codelist = ctrl.getGroupPSCodeList().getAllPSCodeItems()> [<#list codelist as item> <#if item.getValue?? && item.getValue()?? && item.getName?? && item.getName()??>{"value":'${item.getValue()}',"text":'${item.getName()}'},</#if></#list>]<#else>[]</#if>; public group_detail:any = <#if ctrl.getGroupPSCodeList?? && ctrl.getGroupPSCodeList()?? && ctrl.getGroupPSCodeList().getAllPSCodeItems?? && ctrl.getGroupPSCodeList().getAllPSCodeItems()??> <#assign codelist = ctrl.getGroupPSCodeList().getAllPSCodeItems()> [<#list codelist as item> <#if item.getValue?? && item.getValue()?? && item.getName?? && item.getName()??>{"value":'${item.getValue()}',"text":'${item.getName()}'},</#if></#list>]<#else>[]</#if>;
/**
* 分组模式
*
* @type {string}
* @memberof ${srfclassname('${ctrl.codeName}')}
*/
public group_mode = <#if ctrl.getGroupMode?? && ctrl.getGroupMode()??>'${ctrl.getGroupMode()}'<#else>''</#if>;
/** /**
* 分组数据 * 分组数据
* *
...@@ -551,45 +559,67 @@ ...@@ -551,45 +559,67 @@
this.setSlidingDisabled(item); this.setSlidingDisabled(item);
}); });
if(this.isEnableGroup){ if(this.isEnableGroup){
this.getGroupData(this.items); if (this.group_mode == 'AUTO') {
this.getGroupDataAuto(this.items);
}else{
this.getGroupDataByCodeList(this.items);
}
} }
return response; return response;
} }
/** /**
* 获取分组数据 * 代码表分组,获取分组数据
* *
* @memberof Mob * @memberof ${srfclassname('${ctrl.codeName}')}
*/ */
public getGroupData(items:any){ public getGroupDataByCodeList(items:any){
let data:any = []; let group:Array<any> = [];
let iobj:any = {};
this.group_detail.forEach((obj:any,index:number)=>{ this.group_detail.forEach((obj:any,index:number)=>{
let idata let data:any = [];
items.forEach((item:any,i:number)=>{ items.forEach((item:any,i:number)=>{
if (item[this.group_field] === obj.value) { if (item[this.group_field] === obj.value) {
if(!iobj[ item[this.group_field] ]){ data.push(item);
iobj[ item[this.group_field] ] = item[this.group_field];
data.push(this.filterByTag(items,item[this.group_field]));
}
} }
}) })
group.push(data);
}) })
data.forEach((arr:any,index:number)=>{ group.forEach((arr:any,index:number)=>{
this.group_data[index] = {}; this.group_data[index] = {};
this.group_data[index].text = this.group_detail[ index ].text; this.group_data[index].text = this.group_detail[index].text;
this.group_data[index].items = arr; this.group_data[index].items = arr;
}) })
this.group_data.forEach((item:any,i:number)=>{
if (item.items.length == 0) {
this.group_data.splice(i,1);
}
})
} }
/** /**
* 单条件过滤数组数据 *
* 自动分组,获取分组数据
* *
* @memberof ${srfclassname('${ctrl.codeName}')} * @memberof ${srfclassname('${ctrl.codeName}')}
*/ */
public filterByTag(arr:Array<number>, tag:any) { public getGroupDataAuto(items:any){
return arr.filter((item:any) => item[this.group_field] == tag); let groups:Array<any> = [];
items.forEach((item:any)=>{
if(item.hasOwnProperty(this.group_field)){
groups.push(item[this.group_field]);
}
})
groups = [...new Set(groups)];
groups.forEach((group:any,index:number)=>{
this.group_data[index] = {};
this.group_data[index].items = [];
items.forEach((item:any,i:number)=>{
if (group == item[this.group_field]) {
this.group_data[index].text = group;
this.group_data[index].items.push(item);
}
})
})
} }
/** /**
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册