<%@ page language="java" contentType="text/html; charset=utf-8"
         pageEncoding="utf-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<!DOCTYPE html>
<html lang="en">
<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"/>
    <script type="text/javascript">
        require("js/merchantBaseInfo/merchantBaseInfoList.js");
    </script>

    <style>
        .layui-table th {
            text-align: center;
        }
    </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" action="" style="margin-top: 10px">
                    <div class="layui-form-item">
                        <c:if test="${admin eq 'admin'}">
                            <div class="layui-inline">
                                <label class="layui-form-label">用户名称</label>
                                <div class="layui-input-inline">
                                    <input type="text" placeholder="请输入用户名称" id="userName" name="userName"
                                           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="alias" name="alias"
                                           class="layui-input">
                                </div>
                            </div>
                        </c:if>

                        <div class="layui-inline">
                            <label class="layui-form-label">用户ID</label>
                            <div class="layui-input-inline">
                                <input type="text" placeholder="请输入用户ID" id="userId" name="userId"
                                       class="layui-input">
                            </div>
                        </div>
                        <c:if test="${admin ne 'admin'}">
                            <div class="layui-inline">
                                <label class="layui-form-label">商户简称</label>
                                <div class="layui-input-inline">
                                    <input type="text" placeholder="请输入商户简称" id="alias" name="alias"
                                           class="layui-input">
                                </div>
                            </div>
                        </c:if>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <div class="mb50 mt10">
        <div class="whitebg pl10 pr10">
            <table class="layui-hide" id="merchantBaseInfoList" lay-filter="merchantBaseInfoList"></table>
        </div>
    </div>
</div>
</body>

<script id="lineBar" type="text/html">
    <button class="layui-btn layui-btn-xs"
            lay-mDropdown="{template: '#toolbarMenu'}">
        <span>操作</span>
        <i class="layui-icon layui-icon-triangle-d"></i>
    </button>
</script>

<script id="toolbarMenu" type="text/html">
    <a href="javascript:void(0);" lay-event="detail"
       class="layui-btn layui-btn-xs layui-btn-danger fa fa-detail ops_more f12">乐刷修改费率</a>
</script>

<script id="toolBar" type="text/html">
    <a class="layui-btn layui-btn-sm fa fa-search f13" href="javascript:void(0);"
       onclick="queryMerchantBaseInfo()"><span>搜索</span></a>
</script>

<script type="text/javascript">
    var layer;
    var form;
    var table;
    var laydate;
    var dropdown;
    //form表单样式
    layui.use(['table', 'layer', 'form', 'laydate', 'mDropdown'], function () {
        layer = layui.layer;
        form = layui.form;
        table = layui.table;
        laydate = layui.laydate;
        dropdown = layui.mDropdown;
        form.render();

        //执行一个 table 实例
        table.render({
            elem: '#merchantBaseInfoList'
            , autoSort: false
            , id: 'merchantBaseInfoList'
            , url: '${ctx}/merchantBaseInfo/queryMerchantBaseInfoPage' //数据接口
            , where: { //请求参数（注意：这里面的参数可任意定义，并非下面固定的格式）
                userName: $('#userName').val()
                , phone: $('#phone').val()
                , parentIdPhone: $('#parentIdPhone').val()
                , alias: $('#alias').val()
                , userId: $("#userId").val()
            }
            , 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.count, //解析数据长度
                    "data": res.merchantBaseInfoList //解析数据列表
                };
            }
            , title: '商户详情'
            , toolbar: '#toolBar' //开启工具栏，此处显示默认图标，可以自定义模板，详见文档
            , defaultToolbar: ['filter']
            , cols: [[ //表头
                {type: 'numbers'}
                , {type: 'checkbox'}
                , {field: 'userId', title: '用户ID', align: "center"}
                <c:if test="${admin eq 'admin' }">
                , {field: 'userName', title: '用户名称', minWidth: 100}
                , {field: 'phone', title: '用户手机号', hide: true, minWidth: 110}
                , {field: 'parentIdPhone', title: '直属上级手机号', hide: true, minWidth: 130}
                </c:if>
                , {field: 'alias', title: '商户简称', minWidth: 100}
                , {field: 'earnings', title: '交易总流水', sort: true, minWidth: 120}
                , {field: 'toDayEarnings', title: '今日流水', sort: true, minWidth: 100}
                , {field: 'yestDayEarnings', title: '昨日流水', sort: true, minWidth: 100}
                , {field: 'orderCount', title: '总笔数', sort: true, minWidth: 100}
                , {field: 'yesterdayOrderCount', title: '昨日笔数', sort: true, minWidth: 100}
                , {field: 'yesterdaySpreadCount', title: '昨日推广', sort: true, minWidth: 100}
                , {field: 'menber', title: '已有会员', sort: true, minWidth: 100}
                , {field: 'toDayMenber', title: '今日新增会员', hide: true, sort: true, minWidth: 120}
                , {field: 'yestDayMenber', title: '昨日新增会员', sort: true, minWidth: 120}
                <c:if test="${admin != 'admin'}">
                , {
                    field: 'sumDifference', title: '会员总余额', minWidth: 110, templet: function (d) {
                        return (d.sumDifference - 0).toFixed(2);
                    }
                }
                , {field: 'sumNumber', title: '交易总数', sort: true, minWidth: 100}
                </c:if>
                , {field: 'toDayFansCount', title: '今日粉丝', sort: true, hide: true, minWidth: 100}
                , {field: 'yesterDayFansCount', title: '昨日粉丝', sort: true, minWidth: 100}
                , {field: 'fansMoney', title: '粉丝奖励', minWidth: 100}
                , {
                    field: 'createDt', title: '创建日期', hide: true, width: 160,
                    templet: "<div>{{layui.util.toDateString(d.createDt, 'yyyy-MM-dd HH:mm:ss')}}</div>"
                }
                <c:if test="${admin eq 'admin'}">
                , {fixed: 'right', title: '操作', align: 'center', width: 90, toolbar: '#lineBar'}
                </c:if>
            ]]
            , page: true //开启分页
            , request: {
                pageName: 'currPage' //页码的参数名称，默认：page
                , limitName: 'size' //每页数据量的参数名，默认：limit
            }
            , done: function (res) {
                dropdown.suite();
            }
        });
        table.on('tool(merchantBaseInfoList)', function (obj) {
            var data = obj.data;
            if (obj.event === 'detail') {
                updateBaseInfoLeshuaRate(data.id)
            }
        });

        table.on('sort(merchantBaseInfoList)', function (obj) {
            console.log(obj.field); //当前排序的字段名
            console.log(obj.type); //当前排序类型：desc（降序）、asc（升序）、null（空对象，默认排序）
            console.log(this); //当前排序的 th 对象

            //尽管我们的 table 自带排序功能，但并没有请求服务端。
            //有些时候，你可能需要根据当前排序的字段，重新向服务端发送请求，从而实现服务端排序，如：
            table.reload('merchantBaseInfoList', {
                initSort: obj
                , where: {
                    column: obj.field //排序字段
                    , asc: (obj.type === "asc") //排序方式
                }
            });
        });
    });

    //查询
    function queryMerchantBaseInfo() {
        table.reload('merchantBaseInfoList', {
            page: {
                curr: 1
            }
            , where: { //请求参数（注意：这里面的参数可任意定义，并非下面固定的格式）
                userName: $('#userName').val()
                , phone: $('#phone').val()
                , parentIdPhone: $('#parentIdPhone').val()
                , alias: $('#alias').val()
                , userId: $("#userId").val()
            }
        });
    }
</script>
</html>

