其他分享
首页 > 其他分享> > Layui 通过计算后得出的值在合计中的加载

Layui 通过计算后得出的值在合计中的加载

作者:互联网

 table.render({
        even: 'true',
        elem: '#test',
        id: 'PrivateCarUtilityTable',
        url: '/VehicleManagement/GetPrivateCarUtilityDB', //数据接口
        page: true,
        totalRow: true,
        where: {
            UserId: $("#UserId option:selected").val(),
            start: $("[name='start']").val(),
            end: $("[name='end']").val(),
        },
        done: function (res) {
            var SumMileage = 0;//统计结算后余额
            var Sumkilometers = 0;
            layui.each(res.data, function (index, d) {
                //汽车总价开始
                var num = Number(d.Displacement);
                var kilometers = d.Endkilometers - d.Strartkilometers;
                var sum = 0;
                if (num < 1.8) {
                    sum=(0.8 * kilometers);
                } else {
                    sum=(1.2 * kilometers);
                }
                SumMileage += sum;
               //汽车总价结束
                //总公里数开始
                Sumkilometers += kilometers;
                //总公里数结束

            })

            this.elem.next().find('.layui-table-total td[data-field="TotalPrice"] .layui-table-cell').text(SumMileage);
            this.elem.next().find('.layui-table-total td[data-field="Sumkilometers"] .layui-table-cell').text(Sumkilometers);
        }, 
        count: 50,
        request: {
            pageName: 'offset' //页码的参数名称,默认:page
            , limitName: 'limit' //每页数据量的参数名,默认:limit
        },
        cols: contractCols,
        cellMinWidth: 120
    });
View Code
 1 var contractCols = [[
 2     {
 3         checkbox: true,
 4        
 5     },
 6     {
 7         align: 'center', type: "numbers",
 8         title: '序号',  totalRowText: '合计',
 9     }, {
10         align: 'center', field: 'Date',
11         title: '日期', sort: true,
12     },
13     {
14         align: 'center', field: 'ProjectName',
15         title: '用途',
16     },
17     {
18         align: 'center', field: 'UserId',
19         title: '申请人',
20         templet: function (d) {
21             return AllTById(AllUsers, d.UserId,"UserName");//[0]
22         }, sort: true,
23     },
24     {
25         align: 'center', field: 'UserId',
26         title: '部门',
27         templet: function (d) {
28             var id = AllTById(AllUsers, d.UserId, "DepartmentId");//[0]
29             return AllvnameById(GetAllDepartment,"DepartmentId", id, "DepartmentName");//[0]
30         }, sort: true,
31     },
32     {
33         align: 'center', field: 'LicensePlateNumber',
34         title: '车牌号',
35     },
36     {
37         align: 'center', field: 'Displacement',
38         title: '排量'
39     },
40     {
41         align: 'center', field: 'Parking',
42         title: '过路费/停车费'
43     },
44     {
45         align: 'center', field: 'Strartkilometers',
46         title: '开始里程数', sort: true,
47     },
48     {
49         align: 'center', field: 'Endkilometers',
50         title: '终止公里数'
51     },
52     {
53         align: 'center', field: 'Sumkilometers',
54         title: '总公里数', templet: function (d) {
55             return Number(d.Endkilometers) - Number(d.Strartkilometers);
56         }, totalRow: true
57     },
58     {
59         align: 'center', field: 'UnitPrice',
60         title: '单价',
61         templet: function (d) {
62             var num = Number(d.Displacement);
63             if (num < 1.8) {
64                 return 0.8
65             } else {
66                 return 1.2
67             }
68         }
69     },
70     {
71         align: 'center', field: 'TotalPrice',
72         title: '总价'
73         ,templet: function (d) {
74             var num = Number(d.Displacement);
75             var kilometers = d.Endkilometers - d.Strartkilometers;
76             if (num < 1.8) {
77                 return(0.8 * kilometers);
78             } else {
79                 return(1.2 * kilometers);
80             }
81         },totalRow: true
82     },
83     {
84         align: 'center', field: 'Remarks',
85         title: ' 备注', 
86     },
87     {
88         align: 'center', field: 'State',
89         title: '汽车相册', event: 'EvensetSign',
90         templet: function (d) {
91             return "<span style='color:#1E90FF'>相册</span>";
92         }
93     },
94     { align: 'center', title: '操作', toolbar: '#barDemo', fixed: 'right' },
95 ]];
View Code

 

标签:center,title,Layui,align,field,var,true,得出,加载
来源: https://www.cnblogs.com/YZM97/p/12532192.html