<%@ page contentType="text/html; charset=utf-8"
         pageEncoding="utf-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
    <meta name="renderer" content="webkit">
    <!-- 移动设备 viewport -->
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
    <jsp:include page="../../common.jsp"/>
    <style>
        .layui-btn+.layui-btn {
            margin-left: -4px;
        }
    </style>
</head>
<body>
<div class="row animated fadeInRight" style="margin: 0;">
    <div class="wrapper wrapper-content mt5 right-content ml5 mr5">
        <div class="toolbar-panel bdd">
            <div class="toolbar-box">
                <div class="toolbar-head clearfix lgraybg pt5 pb10 pl10 bdbd">
                    <!-- 顶部按钮 -->
                    <div class="fl">
                        查询条件
                    </div>
                    <div class="tools fr">
                        <a href="javascript:void(0);" class="collapse dblock f14 dgray mr5">
                            <i class="fa-2x fa fa-angle-double-up"></i>
                        </a>
                    </div>
                </div>
            </div>
            <!--搜索条件 -->
            <div class="toolbar-body">
                <form class="layui-form" id="form1" action="" style="margin-top: 10px">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">用户ID</label>
                            <div class="layui-input-block">
                                <input type="text" name="userId" id="userId" placeholder="请输入用户ID"
                                       autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">上级ID</label>
                            <div class="layui-input-block">
                                <input type="text" name="parentId" id="parentId" placeholder="上级用户ID"
                                       autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">日期</label>
                            <div class="layui-input-inline">
                                <input type="text" placeholder="日期" id="date1" readonly name="profitDate" autocomplete="off"
                                       class="layui-input">
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <div class="mb50 mt10">
        <div class="whitebg pl10 pr10">
            <table class="layui-hide" id="userFlowTab" lay-filter="userFlowTab"></table>
        </div>
    </div>
</div>
<script type="text/html" id="leftBar">
    <a class="layui-btn layui-btn-sm" lay-event="search">
        <i class="layui-icon layui-icon-search"></i>查询
    </a>
</script>

<script>
    layui.use(['table', 'layer','laydate','form'], function () {
        let table = layui.table;
        let laydate = layui.laydate;
        let fmt = "YYYY-mm-dd";
        let date = new Date();
        let dateTime = dateChange(-1,dateFormat(fmt,date));
        $("#date1").val(dateTime);
        laydate.render({
            elem: '#date1', //指定元素
            format: 'yyyy-MM-dd',
            btns: ['now','confirm']
        });
        var tableIns = table.render({
            elem: '#userFlowTab'
            , url: '${ctx}/userProft/pageData'
            , id: 'userFlow'
            , where: {
                profitDate:dateTime,
            }
            , response: {
                statusName: 'code' //数据状态的字段名称，默认：code
                , countName: 'count' //数据总数的字段名称，默认：count
                , dataName: 'data' //默数据列表的字段名称，认：data
                , statusCode: 200
            }
            , parseData: function (res) { //res 即为原始返回的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.message, //解析提示文本
                    "count": res.data.count, //解析数据长度
                    "data": res.data.data //解析数据列表
                };
            }
            , toolbar: '#leftBar' //开启头部工具栏，并为其绑定左侧模板
            , defaultToolbar: ['filter']
            , defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
                title: '提示'
                , layEvent: 'LAYTABLE_TIPS'
                , icon: 'layui-icon-tips'
            }]
            , title: '用户日流水数据统计'
            , cols: [[
                {type: 'checkbox', fixed: 'left', hidden: true}
                , {field: 'numbers', title: '序号', fixed: 'left', unresize: true, width: 80, type: 'numbers'}
                , {field: 'userId', title: '用户ID'}
                , {field: 'parentId', title: '上级ID',templet:function (d){
                    if(d.parentId){
                        return d.parentId;
                    }else{
                        return "-";
                    }
                }}
                , {field: 'userName', title: '用户名称'}
                , {field: 'roleCode', title: '用户角色',templet:function (d){
                        if(d.roleCode == "ZY_BST"){
                            return "<span style='color: blue' '>倍斯特</span>"
                        }else if(d.roleCode == "SV2"){
                            return "<span style='color: green' '>官方</span>"
                        }else{
                            return "未知"
                        }
                    }}
                , {field: 'teamTransFlow', title: '团队流水',templet:function (d){
                        if(d.teamTransFlow){
                            return d.teamTransFlow.toFixed(2);
                        }
                        return "-";
                    }}
                , {field: 'transNum', title: '团队笔数'}
                , {field: 'directTransFlow', title: '直推流水',templet:function (d){
                        if(d.directTransFlow){
                            return d.directTransFlow.toFixed(2);
                        }
                        return "-";
                    }}
                , {field: 'indirectTransFlow', title: '间推流水',templet:function (d){
                        if(d.indirectTransFlow){
                            return d.indirectTransFlow.toFixed(2);
                        }
                        return "-";
                    }}
                , {field: 'ownTransFlow', title: '自有流水',templet:function (d){
                        if(d.ownTransFlow){
                            return d.ownTransFlow.toFixed(2);
                        }
                        return "-";
                    }}
                , {field: 'totalProfitAmt', title: '总分润',templet:function (d){
                        if(d.totalProfitAmt){
                            return d.totalProfitAmt.toFixed(2);
                        }
                        return "-";
                    }}
                , {field: 'directProfitAmt', title: '直推分润',templet:function (d){
                        if(d.directProfitAmt){
                            return d.directProfitAmt.toFixed(2);
                        }
                        return "-";
                    }}
                , {field: 't2ProfitAmt', title: 't2收益',templet:function (d){
                        if(d.t2ProfitAmt){
                            return d.t2ProfitAmt.toFixed(2);
                        }
                        return "-";
                    }}
                , {field: 't3ProfitAmt', title: 't3收益',templet:function (d){
                        if(d.t3ProfitAmt){
                            return d.t3ProfitAmt.toFixed(2);
                        }
                        return "-";
                    }}
                , {
                    field: 'profitDate',
                    title: '分润日期',
                    templet: "<div>{{layui.util.toDateString(d.profitDate,'yyyy-MM-dd')}}</div>"
                }
            ]]
            , request: {
                pageName: 'current' //页码的参数名称，默认：page
                , limitName: 'size' //每页数据量的参数名，默认：limit
            }
            , page: true
        });
        table.on('toolbar(userFlowTab)', function (obj) {
            switch (obj.event) {
                case 'search':
                    var params = serialize($('#form1'));
                    table.reload('userFlow', {
                        where: params
                        , page: {
                            size: 10
                            , current: 1
                        }
                    });
                    break;
            }
        });
        //触发排序事件
        table.on('sort(userFlowTab)', function(obj){ //注：sort 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            var params = serialize($('#form1'));
            params["field"] = obj.field;
            params["order"] = obj.type;
            table.reload('userFlow', {
                initSort: obj //记录初始排序，如果不设的话，将无法标记表头的排序状态。
                ,where: params
            });
            layer.msg('服务端排序。order by '+ obj.field + ' ' + obj.type);
        });
        function dateFormat(fmt, date) {
            let ret;
            const opt = {
                "Y+": date.getFullYear().toString(),        // 年
                "m+": (date.getMonth() + 1).toString(),     // 月
                "d+": date.getDate().toString(),            // 日
                "H+": date.getHours().toString(),           // 时
                "M+": date.getMinutes().toString(),         // 分
                "S+": date.getSeconds().toString()          // 秒
                // 有其他格式化字符需求可以继续添加，必须转化成字符串
            };
            for (let k in opt) {
                ret = new RegExp("(" + k + ")").exec(fmt);
                if (ret) {
                    fmt = fmt.replace(ret[1], (ret[1].length == 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, "0")))
                };
            };
            return fmt;
        }
        function dateChange(num = 1,date = false) {
            if (!date) {
                date = new Date();//没有传入值时,默认是当前日期
                date = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate();
            }
            date += " 00:00:00";//设置为当天凌晨12点
            date = Date.parse(new Date(date))/1000;//转换为时间戳
            date += (86400) * num;//修改后的时间戳
            var newDate = new Date(parseInt(date) * 1000);//转换为时间
            return dateFormat("YYYY-mm-dd",newDate);
        }
    });
</script>
</body>
</html>
