layui表格 后端统计汇总 前端呈现的技术实现

ref:table 数据表格文档 - Layui

layui的table组件自带汇总统计的功能,但是这个统计只能做当前页的统计,无法做跨页面的汇总统计。这里给出一种基于后端进行统计,前端进行呈现的方案

1.后端返回数据demo,这里进行了分页,result是分页数据,totalrow是汇总行,code是状态码(table默认0是成功),count是总计记录数

{
    "result": [
        {
            "id": 17,
            "code": "KFP20231123172337819",
            "typeA": null,
            "typeB": null,
            "department": "运营中心",
            "orgA": "如约数据科技有限公司",
            "orgB": "张东建",
            "orgid": null,
            "personid": 1580,
            "title": "张东建",
            "isTemp": 0,
            "TotalAmount": 100.00,
            "TotalInvoice": 0.00,
            "ReverseAmount": 0.00,
            "ReturnedAmount": 0.00,
            "TransferInAmount": 0.00,
            "TransferOutInAmount": 0.00,
            "BalanceAmount": 0.00,
            "month": null,
            "content": null,
            "saleman": "肖腾",
            "tel": "13318730345",
            "settlement": null,
            "deadline": 60,
            "needaudit": 1,
            "invoiceregisttime": null,
            "estimatetime": null,
            "remark": null,
            "nextplan": null,
            "createtime": "\/Date(1700731637000)\/"
        },
        {
            "id": 16,
            "code": "KFP20231123170649038",
            "department": null,
            "orgA": "如约数据科技有限公司",
            "orgB": "广州市第三建筑工程有限公司",
            "personid": null,
            "title": "广州市第三建筑工程有限公司",
            "isTemp": 0,
            "TotalAmount": 6000.00,
            "TotalInvoice": 0.00,
            "ReverseAmount": 0.00,
            "ReturnedAmount": 0.00,
            "TransferInAmount": 0.00,
            "TransferOutInAmount": 0.00,
            "saleman": "肖腾(13318730345)",
            "tel": "13318730345",
            "deadline": 0,
            "needaudit": 1,
            "createtime": "\/Date(1700730663000)\/",
            "typeA": "外部单位",
            "typeB": "市国资委(研发、运营)",
            "orgid": 1952,
            "month": "2023年11月-2024年3月",
            "invoiceregisttime": null,
            "estimatetime": null,
            "remark": null,
            "nextplan": null,
            "content": null,
            "settlement": null,
            "BalanceAmount": 0.00
        },
        {
            "id": 15,
            "code": "KFP20231123151447117",
            "department": null,
            "orgA": "如约数据科技有限公司",
            "orgB": "广州市第三建筑工程有限公司",
            "personid": null,
            "title": "广州市第三建筑工程有限公司",
            "isTemp": 1,
            "TotalAmount": 30000.00,
            "TotalInvoice": 30000.00,
            "ReverseAmount": 0.00,
            "ReturnedAmount": 1.00,
            "TransferInAmount": 5000.00,
            "TransferOutInAmount": 0.00,
            "saleman": null,
            "tel": "13318730345",
            "deadline": 0,
            "needaudit": 1,
            "createtime": "\/Date(1700723763000)\/",
            "typeA": null,
            "typeB": null,
            "orgid": 1952,
            "month": "202312",
            "invoiceregisttime": "\/Date(1700409600000)\/",
            "estimatetime": null,
            "remark": null,
            "nextplan": null,
            "content": null,
            "settlement": null,
            "BalanceAmount": -24999.00
        },
        {
            "id": 14,
            "code": "KFP20231123085015370",
            "department": null,
            "orgA": "如约数据科技有限公司",
            "orgB": "广州市第三建筑工程有限公司",
            "personid": null,
            "title": "广州市第三建筑工程有限公司",
            "isTemp": 0,
            "TotalAmount": 3000.00,
            "TotalInvoice": 3000.00,
            "ReverseAmount": 0.00,
            "ReturnedAmount": 0.00,
            "TransferInAmount": 0.00,
            "TransferOutInAmount": 0.00,
            "saleman": "肖腾(13318730345)",
            "tel": "13318730345",
            "deadline": 0,
            "needaudit": 1,
            "createtime": "\/Date(1700700699000)\/",
            "typeA": "外部单位",
            "typeB": "市国资委(研发、运营)",
            "orgid": 1952,
            "month": null,
            "invoiceregisttime": "\/Date(1700496000000)\/",
            "estimatetime": "\/Date(1700582400000)\/",
            "remark": "客户放假",
            "nextplan": "假期后联系",
            "content": null,
            "settlement": null,
            "BalanceAmount": -3000.00
        },
        {
            "id": 13,
            "code": "KFP20231121202046164",
            "department": null,
            "orgA": "如约数据科技有限公司",
            "orgB": "广州市第三建筑工程有限公司",
            "personid": null,
            "title": "广州市第三建筑工程有限公司",
            "isTemp": 0,
            "TotalAmount": 5000.00,
            "TotalInvoice": 5000.00,
            "ReverseAmount": 5000.00,
            "ReturnedAmount": 5000.00,
            "TransferInAmount": 0.00,
            "TransferOutInAmount": 5000.00,
            "saleman": "肖腾(13318730345)",
            "tel": "13318730345",
            "deadline": 0,
            "needaudit": 1,
            "createtime": "\/Date(1700569286000)\/",
            "typeA": "外部单位",
            "typeB": "市国资委(研发、运营)",
            "orgid": 1952,
            "month": "手动阀手动阀",
            "invoiceregisttime": "\/Date(1700496000000)\/",
            "estimatetime": null,
            "remark": null,
            "nextplan": null,
            "content": null,
            "settlement": null,
            "BalanceAmount": 0.00
        },
        {
            "id": 12,
            "code": "KFP20231121173133801",
            "department": null,
            "orgA": "如约数据科技有限公司",
            "orgB": "广州市第三建筑工程有限公司",
            "personid": null,
            "title": "广州市第三建筑工程有限公司",
            "isTemp": 0,
            "TotalAmount": 3000.00,
            "TotalInvoice": 3000.00,
            "ReverseAmount": 3000.00,
            "ReturnedAmount": 0.00,
            "TransferInAmount": 0.00,
            "TransferOutInAmount": 0.00,
            "saleman": "肖腾(13318730345)",
            "tel": "13318730345",
            "deadline": 0,
            "needaudit": 1,
            "createtime": "\/Date(1700559151000)\/",
            "typeA": "外部单位",
            "typeB": "市国资委(研发、运营)",
            "orgid": 1952,
            "month": null,
            "invoiceregisttime": "\/Date(-62135596800000)\/",
            "estimatetime": null,
            "remark": null,
            "nextplan": null,
            "content": null,
            "settlement": null,
            "BalanceAmount": 0.00
        },
        {
            "id": 11,
            "code": "KFP20231121172736180",
            "department": null,
            "orgA": "如约数据科技有限公司",
            "orgB": "广州市第三建筑工程有限公司",
            "personid": null,
            "title": "广州市第三建筑工程有限公司",
            "isTemp": 0,
            "TotalAmount": 0.00,
            "TotalInvoice": 0.00,
            "ReverseAmount": 0.00,
            "ReturnedAmount": 0.00,
            "TransferInAmount": 0.00,
            "TransferOutInAmount": 0.00,
            "saleman": "肖腾(13318730345)",
            "tel": "13318730345",
            "deadline": 0,
            "needaudit": 1,
            "createtime": "\/Date(1700558911000)\/",
            "typeA": "外部单位",
            "typeB": "市国资委(研发、运营)",
            "orgid": 1952,
            "month": null,
            "invoiceregisttime": null,
            "estimatetime": null,
            "remark": null,
            "nextplan": null,
            "content": null,
            "settlement": null,
            "BalanceAmount": 0.00
        },
        {
            "id": 1,
            "code": "YY2021060300001",
            "department": "运营中心",
            "orgA": "广州如约数据科技有限公司",
            "orgB": "常德中车新能源汽车有限公司",
            "personid": null,
            "title": "常德中车新能源汽车有限公司",
            "isTemp": 0,
            "TotalAmount": 196760.73,
            "TotalInvoice": 196760.73,
            "ReverseAmount": 0.00,
            "ReturnedAmount": 196760.73,
            "TransferInAmount": 0.00,
            "TransferOutInAmount": 0.00,
            "saleman": null,
            "tel": "15876584149",
            "deadline": 60,
            "needaudit": 0,
            "createtime": "\/Date(1698221761000)\/",
            "typeA": null,
            "typeB": null,
            "orgid": 1906,
            "month": "202106",
            "invoiceregisttime": null,
            "estimatetime": null,
            "remark": null,
            "nextplan": null,
            "content": "安全带项目11",
            "settlement": "打法",
            "BalanceAmount": 0.00
        },
        {
            "id": 2,
            "code": "YY2021060300002",
            "department": "运营中心",
            "orgA": "广州如约数据科技有限公司",
            "orgB": "常德中车新能源汽车有限公司",
            "personid": null,
            "title": "常德中车新能源汽车有限公司",
            "isTemp": 0,
            "TotalAmount": 196760.73,
            "TotalInvoice": 196760.73,
            "ReverseAmount": 0.00,
            "ReturnedAmount": 196760.73,
            "TransferInAmount": 0.00,
            "TransferOutInAmount": 0.00,
            "saleman": "如约用户",
            "tel": "15876584149",
            "deadline": 60,
            "needaudit": 0,
            "createtime": "\/Date(1698221761000)\/",
            "typeA": "外部单位",
            "typeB": "私人单位",
            "orgid": 1906,
            "month": "202106",
            "invoiceregisttime": null,
            "estimatetime": null,
            "remark": null,
            "nextplan": null,
            "content": "安全带项目",
            "settlement": null,
            "BalanceAmount": 0.00
        },
        {
            "id": 3,
            "code": "YY2021060300003",
            "department": "运营中心",
            "orgA": "广州如约数据科技有限公司",
            "orgB": "常德中车新能源汽车有限公司",
            "personid": null,
            "title": "常德中车新能源汽车有限公司",
            "isTemp": 0,
            "TotalAmount": 196760.73,
            "TotalInvoice": 196760.73,
            "ReverseAmount": 0.00,
            "ReturnedAmount": 196760.73,
            "TransferInAmount": 0.00,
            "TransferOutInAmount": 0.00,
            "saleman": "如约用户",
            "tel": "15876584149",
            "deadline": 60,
            "needaudit": 0,
            "createtime": "\/Date(1698221761000)\/",
            "typeA": "外部单位",
            "typeB": "私人单位",
            "orgid": 1906,
            "month": "202106",
            "invoiceregisttime": null,
            "estimatetime": null,
            "remark": null,
            "nextplan": null,
            "content": "安全带项目",
            "settlement": null,
            "BalanceAmount": 0.00
        }
    ],
    "totalRow": {
        "id": 0,
        "code": null,
        "department": null,
        "orgA": null,
        "orgB": null,
        "personid": null,
        "title": null,
        "isTemp": 0,
        "TotalAmount": 834142.92,
        "TotalInvoice": 828042.92,
        "ReverseAmount": 8000.00,
        "ReturnedAmount": 701762.73,
        "TransferInAmount": 5000.00,
        "TransferOutInAmount": 5000.00,
        "saleman": null,
        "tel": null,
        "deadline": 0,
        "needaudit": 0,
        "createtime": "\/Date(-62135596800000)\/",
        "typeA": null,
        "typeB": null,
        "orgid": null,
        "month": null,
        "invoiceregisttime": null,
        "estimatetime": null,
        "remark": null,
        "nextplan": null,
        "content": null,
        "settlement": null,
        "BalanceAmount": -118280.19
    },
    "code": 1,
    "count": 11,
    "detailMessage": null,
    "message": null
}

2.前端解析json,parseData是layui表格组件的异步请求回调解析的方法,后端返回的json不一定符合table解析数据的格式要求,通过该方法转换成table组件的标准格式

parseData: function (res) {
                return {
                    "code": res.code,
                    "msg": res.detailMessage,
                    "count": res.count,
                    "data": res.result,
                    "totalRow": res.totalRow
                }
            },

3.列表渲染,主要有两个,第一在render时设置totalRow: true,第二就是在需要统计的col设置totalRow: true

cols: [[ //表头

                { field: 'code', title: '自编号', align: 'center', width: 100, totalRowText: '合计:', templet:'<div><a href="/Finance/Edit?id={{d.id}}" title="编辑应回款" class="layui-table-link tablink">{{d.code}}</a></div>' },
                { field: 'department', title: '所属中心', align: 'center', width: 100 },
                { field: 'typeA', title: '分类1', align: 'center', width: 100 },
                { field: 'typeB', title: '分类2', align: 'center', width: 100 },
                { field: 'orgA', title: '销售方', align: 'center', width: 150 },
                { field: 'orgB', title: '客户方', align: 'center', width: 150 },
                { field: 'title', title: '开票单位', align: 'center', width: 150 },
                { field: 'TotalAmount', title: '应收金额', align: 'center', width: 100, totalRow: true },
                { field: 'TotalInvoice', title: '开票金额', align: 'center', width: 100, totalRow: true },
                { field: 'ReverseAmount', title: '冲红金额', align: 'center', width: 100, totalRow: true },
                { field: 'ReturnedAmount', title: '已回款金额', align: 'center', width: 100, totalRow: true },
                { field: 'TransferInAmount', title: '转结金额(转入)', align: 'center', width: 100, totalRow: true },
                { field: 'TransferOutInAmount', title: '转结金额(转出)', align: 'center', width: 100, totalRow: true },
                {
                    field: 'BalanceAmount',title: '待回款金额', align: 'center', width: 100
                },
                { field: 'month', title: '款项所属期', align: 'center', width: 100 },
                { field: 'content', title: '款项内容', align: 'center', width: 150 },
                { title: '款项追缴人', align: 'center', width: 150, templet: function (d) { return d.saleman + '(' + d.tel + ')'; } },
                { field: 'settlement', title: '结算方式', align: 'center', width: 100 },
                { field: 'deadline', title: '回款限期', align: 'center', width: 100 },
                {
                    field: 'needaudit', title: '开票是否审核', align: 'center', width: 100, templet: function (d) {
                        if (d.needaudit == 1)
                            return "是";
                        else
                            return "否";
                    }
                },
                {
                    field: 'invoiceregisttime', title: '开票时间', align: 'center', width: 100, templet: function (d) {
                        if (d.invoiceregisttime != null) {
                            var timestamp = d.invoiceregisttime.replace(/\D/igm, "");
                            var date = new Date(parseInt(timestamp));
                            return util.toDateString(date, 'yyyy-MM-dd')
                        } else {
                            return "";;
                        }
                    }
                },
                {
                    field: 'estimatetime', title: '预计回款时间', align: 'center', width: 100, templet: function (d) {
                        if (d.estimatetime != null) {
                            var timestamp = d.estimatetime.replace(/\D/igm, "");
                            var date = new Date(parseInt(timestamp));
                            return util.toDateString(date, 'yyyy-MM-dd')
                        } else {
                            return "";
                        }
                    }
                },
                { field: 'remark', title: '未回款原因', align: 'center', width: 150 },
                { field: 'nextplan', title: '下一步计划', align: 'center', width: 150 },
                { title: '操作', align: 'center', toolbar: '#controls', width: "440", fixed: "right" },
            ]]

3.效果

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值