jianping li
2019-06-24 a28534cdb89f7930b70f3d570e40200f5237b983
分组排序服务
1 files added
57 ■■■■■ changed files
frontdesk/src/app/service/common/listSort.service.ts 57 ●●●●● patch | view | raw | blame | history
frontdesk/src/app/service/common/listSort.service.ts
New file
@@ -0,0 +1,57 @@
import { Injectable } from '@angular/core';
@Injectable()
export class ListSort {
    groupingSort(list:any){
        let relationListX = list;
        let destX:any;
        let newRelationListX = [];
        let noRelationListX = [];
        newRelationListX = relationListX.filter(x => x.AccountVoucherNumber);
        let map = {},
            dest = [];
        for(var i = 0; i < newRelationListX.length; i++){
            var ai = newRelationListX[i];
            if(!map[ai.AccountVoucherNumber]){
                dest.push({
                    AccountVoucherNumber: ai.AccountVoucherNumber,
                    CREATE_DATE: ai.CREATE_DATE,
                    ServiceNumber: ai.ServiceNumber,
                    Accounting: ai.Accounting,
                    FinanceDirector: ai.FinanceDirector,
                    Cashier: ai.Cashier,
                    ToReview: ai.ToReview,
                    data: [ai]
                });
                map[ai.AccountVoucherNumber] = ai;
            }else{
                for(var j = 0; j < dest.length; j++){
                    var dj = dest[j];
                    if(dj.AccountVoucherNumber === ai.AccountVoucherNumber){
                        dj.data.push(ai);
                        break;
                    }
                }
            }
        }
        function sortNumber(a: any,b: any){return parseInt(a.AccountVoucherNumber) - parseInt(b.AccountVoucherNumber)}
        destX = dest.sort(sortNumber);
        newRelationListX = [];
        noRelationListX = relationListX.filter(x => !x.AccountVoucherNumber);
        if(noRelationListX.length!=0){
                destX.push({
                    AccountVoucherNumber: "",
                    CREATE_DATE: "",
                    ServiceNumber: "",
                    Accounting: "",
                    FinanceDirector: "",
                    Cashier: "",
                    ToReview: "",
                    data:noRelationListX
                })
        }
        console.log(noRelationListX);
        console.log(destX);
        return destX
    }
}