<%@ page contentType="text/html; charset=utf-8"
         pageEncoding="utf-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE 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"/>
</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">状态</label>
                            <div class="layui-input-block">
                                <select name="status">
                                    <option value="">请选择</option>
                                    <option value="0">审核中</option>
                                    <option value="1">已完成</option>
                                    <option value="2">审核驳回</option>
                                    <option value="3">审核过待生效</option>
                                </select>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <div class="mb50 mt10">
        <div class="whitebg pl10 pr10">
            <table class="layui-hide" id="table" lay-filter="table"></table>
        </div>
    </div>
</div>
<script type="text/html" id="leftBar">
    <%-- <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" lay-event="search"><i class="layui-icon">&#xe615;</i>查询
     </button>--%>
    <a class="layui-btn layui-btn-sm" lay-event="search">
        <i class="layui-icon layui-icon-search"></i>查询
    </a>
    <a class="layui-btn layui-btn-sm layui-btn-normal" lay-event="batchPass">
        <i class="layui-icon layui-icon-auz"></i>D0批量审核通过
    </a>
</script>
<script type="text/html" id="toolBar">
    {{# if (d.status == '0') { }}
    <button type="button" class="layui-btn layui-btn-xs layui-btn-normal" lay-event="edit">
        <i class="layui-icon layui-icon-auz"></i>
        D0审核通过
    </button>
    {{# } }}
</script>

<script>
    layui.use(['table', 'layer'], function () {
        var table = layui.table;
        var layer = layui.layer;

        table.render({
            elem: '#table'
            , url: ctx + '/merchantRate/page'
            , id: 'table'
            , request: {
                pageName: 'current'
                , limitName: 'size'
            }
            , response: {
                statusCode: 200
            }
            , parseData: function (res) { //res 即为原始返回的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.message, //解析提示文本
                    "count": res.data.total, //解析数据长度
                    "data": res.data.records //解析数据列表
                };
            }
            , toolbar: '#leftBar' //开启头部工具栏，并为其绑定左侧模板
            , defaultToolbar: ['filter']
            , title: '商户付款页二维码展示表'
            , cols: [[
                {type: 'checkbox', hidden: true}
                , {field: 'numbers', title: '序号', unresize: true, width: 80, type: 'numbers'}
                , {field: 'userId', title: '用户ID', width: 80}
                , {field: 'alias', title: '商户简称', minWith: 100}
                , {
                    field: 'merchantId', title: '银盛商编', minWith: 150, templet: function (d) {
                        if (d.merchantId == null) {
                            return '-';
                        } else {
                            return d.merchantId;
                        }
                    }
                }
                , {field: 'aliRateD1', title: '支付宝D1', minWith: 100}
                , {field: 'wxRateD1', title: '微信D1', minWith: 100}
                , {
                    field: 'bankRateD1', title: '银联D1', minWith: 100, templet: function (d) {
                        if (!Number(d.bankRateD1)) {
                            return '-';
                        }
                        return (Number(d.bankRateD1) + 2);``
                    }
                }
                , {field: 'bankRateLargeD1', title: '银联大额D1', minWith: 100}
                , {
                    field: 'aliRateD0', title: '支付宝D0', minWith: 100, templet: function (d) {
                        if (d.status == 0) {
                            return d.aliRateD0 + " -> " + d.aliRateEditD0
                        } else {
                            return d.aliRateD0
                        }
                    }
                }
                , {
                    field: 'wxRateD0', title: '微信D0', minWith: 100, templet: function (d) {
                        if (d.status == 0) {
                            return d.wxRateD0 + " -> " + d.wxRateEditD0
                        } else {
                            return d.wxRateD0
                        }
                    }
                }
                , {
                    field: 'bankRateD0', title: '银联D0', minWith: 100, templet: function (d) {
                        if (d.status == 0) {
                            return (Number(d.bankRateD0) + 2) + " -> " + (Number(d.bankRateEditD0) + 2)
                        } else if (d.status == -1) {
                            return d.bankRateD0
                        } else {
                            return (Number(d.bankRateD0) + 2)
                        }
                    }
                }
                , {
                    field: 'bankRateLargeD0', title: '银联大额D0', minWith: 120, templet: function (d) {
                        if (d.status == 0) {
                            return ((d.bankRateLargeD0 - 21) / 2.0 + 53) + " -> " + ((d.bankRateLargeEditD0 - 21) / 2.0 + 53)
                        } else if (d.status == -1) {
                            return d.bankRateLargeD0;
                        } else {
                            return ((d.bankRateLargeD0 - 21) / 2.0 + 53)
                        }
                    }
                }
                , {
                    field: 'status', title: 'D0编辑状态', minWith: 100, templet: function (d) {
                        if (d.status == 0) {
                            return "审核中";
                        } else if (d.status == 1) {
                            return "已生效";
                        } else {
                            return "未开通";
                        }
                    }
                }
                , {
                    field: 'createTime',
                    title: '创建时间',
                    width: 160,
                    templet: "<div>{{layui.util.toDateString(d.createTime,'yyyy-MM-dd HH:mm:ss')}}</div>"
                }
                , {fixed: 'right', title: '操作', width: 150, toolbar: '#toolBar'}
            ]]
            , page: true
        });

        table.on('tool(table)', function (obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            if (layEvent === 'edit') { //编辑
                ratePass(obj.data);
            } else if (layEvent === 'reject') {

            }
        });

        //监听头工具栏事件
        table.on('toolbar(table)', function (obj) {
            switch (obj.event) {
                /*case 'add':
                    // 添加
                    toAdd();
                    break;*/
                case 'search':
                    var params = serialize($('#form1'));
                    table.reload('table', {
                        where: params
                        , page: {
                            size: 10
                            , current: 1
                        }
                    });
                    break;
                case 'batchPass':
                    var checkStatus = table.checkStatus(obj.config.id);
                    var merchantIds = [];
                    checkStatus.data.forEach(function(item) {
                        merchantIds.push(item.merchantId);
                    });
                    batchRatePass(merchantIds)
                    break;
            }
        })

        function batchRatePass(merchantIds) {
            if (merchantIds == null || merchantIds.length === 0) {
                layer.msg("至少选择一条记录");
                return;
            }

            layer.confirm("确认D0费率修改", {
                yes: function (index, layero) {
                    $.ajax({
                        url: ctx + '/merchantRate/batchPass'
                        , type: "post"
                        , data: {
                            merchantId: merchantIds
                        }
                        , success: function (d) {
                            if (d.code == 200) {
                                layer.msg(d.message);
                                layer.close(index);
                                table.reload('table', {}, true);
                            } else {
                                layer.msg(d.message);
                            }
                        }
                    })
                }
            });
        }

        function ratePass(obj) {
            layer.confirm("确认D0费率修改", {
                yes: function (index, layero) {
                    $.ajax({
                        url: ctx + '/merchantRate/pass'
                        , type: "post"
                        , data: {
                            merchantId: obj.merchantId
                        }
                        , success: function (d) {
                            if (d.code == 200) {
                                layer.msg(d.message);
                                layer.close(index);
                                table.reload('table', {}, true);
                            } else {
                                layer.msg(d.message);
                            }
                        }
                    })
                }
            });
        }
    });

</script>
</body>
</html>