• 微信公众号:美女很有趣。 工作之余,放松一下,关注即送10G+美女照片!

根据某些值为一组重新组装数组

开发技术 开发技术 4小时前 1次浏览
 let arr = [
            {
                fenl: '1',
                bumen: '5',
                bianm: 'B003020201000005',
                name: '菠菜',
                pinp: '首农',
                guig: '200g',
                baoz: '袋',
                danjia: '12',
                num: '100',
                xiaoj: '1300',
                money: '12000',
                remark: '备注备注',
                people: '张三',
                supplier: 'DB',
                createTime: '2020-12-01 11:11:11',
                danhao: 'SYCGQ202012010001',
                shuilv: '1'
            },
            {
                fenl: '1',
                bumen: '5',
                bianm: 'B003020201000005',
                name: '菠菜',
                pinp: '首农',
                guig: '200g',
                baoz: '袋',
                danjia: '12',
                num: '100',
                xiaoj: '1200',
                money: '12000',
                remark: '备注备注',
                people: '张三',
                supplier: 'DB',
                createTime: '2020-12-01 11:11:11',
                danhao: 'SYCGQ202012010001',
                shuilv: '1'
            },
            {
                fenl: '1',
                bumen: '5',
                bianm: 'XNB003020201000005',
                name: '菠菜',
                pinp: '首农',
                guig: '200g',
                baoz: '袋',
                danjia: '12',
                num: '100',
                xiaoj: '1200',
                money: '12000',
                remark: '备注备注',
                people: '张三',
                supplier: 'DB',
                createTime: '2020-12-01 11:11:11',
                danhao: 'SYCGQ202012010001',
                shuilv: '1'
            },
            {
                fenl: '2',
                bumen: '5',
                bianm: 'B003020201000005',
                name: '菠菜',
                pinp: '首农',
                guig: '200g',
                baoz: '袋',
                danjia: '12',
                num: '100',
                xiaoj: '1200',
                money: '12000',
                remark: '备注备注',
                people: '张三',
                supplier: 'DB',
                createTime: '2020-12-01 11:11:11',
                danhao: 'SYCGQ202012010001',
                shuilv: '1'
            },
            {
                fenl: '1',
                bumen: '6',
                bianm: 'B003020201000005',
                name: '菠菜',
                pinp: '首农',
                guig: '200g',
                baoz: '袋',
                danjia: '12',
                num: '100',
                xiaoj: '1200',
                money: '12000',
                remark: '备注备注',
                people: '张三',
                supplier: 'B',
                createTime: '2020-12-01 11:11:11',
                danhao: 'SYCGQ202012010001',
                shuilv: '1'
            },
            {
                fenl: '2',
                bumen: '5',
                bianm: 'B003020201000005',
                name: '菠菜',
                pinp: '首农',
                guig: '200g',
                baoz: '袋',
                danjia: '12',
                num: '100',
                xiaoj: '1200',
                money: '12000',
                remark: '备注备注',
                people: 'lisi',
                supplier: 'DB',
                createTime: '2020-12-01 11:11:11',
                danhao: 'SYCGQ202012010001',
                shuilv: '1'
            }
        ];
        var map = {},
            dest = [];
        for (var i = 0; i < arr.length; i++) {
            var ai = arr[i];
            // 分类,部门,供应商一样为一组
            if (!map[ai.fenl + ai.bumen + ai.supplier]) {
                dest.push({
                    fenl: ai.fenl,
                    bumen: ai.bumen,
                    supplier: ai.supplier,
                    data: [ai]
                });
                map[ai.fenl + ai.bumen + ai.supplier] = ai;
            } else {
                for (var j = 0; j < dest.length; j++) {
                    var dj = dest[j];
                    if (dj.fenl == ai.fenl && dj.bumen == ai.bumen && dj.supplier == ai.supplier) {
                        dj.data.push(ai);
                        break;
                    }
                }
            }
        }
        console.log(map);
        console.log(dest);
        let tableArr = [];
        dest.forEach(item => {
            let total = 0;
            item.data.forEach(val => {
                total += val.xiaoj * 1;
            });
            tableArr.push({
                fenl: item.fenl,
                bumen: item.bumen,
                supplier: item.supplier,
                total: total,
                hetong: '',
                lxr: '',
                lxfs: '',
                shdi: '',
                beizhu: ''
            });
        });
        // 最终展示的关联合同弹出框
        console.log(tableArr);

 


程序员灯塔
转载请注明原文链接:根据某些值为一组重新组装数组
喜欢 (0)