<%@ 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"/>

    <style>
    </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 pb5 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" lay-filter="condition">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">mcc编码</label>
                            <div class="layui-input-inline">
                                <input type="text" class="layui-input" name="mccCode">
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>

        <table class="layui-hide" id="demo" lay-filter="test"></table>
    </div>
</div>

<script id="barDemo" type="text/html">
    <a href="javascript:void(0);" lay-event="edit"
       class="layui-btn layui-btn-xs">
        <i class="layui-icon layui-icon-edit"></i>编辑</a>
    <a href="javascript:void(0);" lay-event="del"
       class="layui-btn layui-btn-xs layui-btn-danger">
        <i class="layui-icon layui-icon-delete"></i>删除</a>
</script>

<script type="text/html" id="imgTemp">
    <img src="{{d.icon}}" width="50px" height="50px" alt=""/>
</script>

<script type="text/html" id="toolBar">
    <a class="layui-btn layui-btn-sm" href="javascript:void(0);"
       lay-event="search"><i class="layui-icon layui-icon-search"></i><span>搜索</span></a>

</script>

<script type="text/html" id="operation2">
    <a class="layui-btn layui-btn-xs" href="javascript:void(0);"
       lay-event="editRyx">
        <i class="layui-icon layui-icon-edit"></i>
        <span>编辑</span>
    </a>
</script>

<script type="text/html" id="operation3">
    <a class="layui-btn layui-btn-xs" href="javascript:void(0);"
       lay-event="editYs">
        <i class="layui-icon layui-icon-edit"></i>
        <span>编辑</span>
    </a>
</script>

<script>

    var laypage, layer, table, form;
    let cData = {};
    layui.config({
        version: '1598935358933' //为了更新 js 缓存，可忽略
    });

    layui.use(['laypage', 'layer', 'table', 'upload', 'element'], function () {
        laypage = layui.laypage;
        layer = layui.layer; //弹层
        table = layui.table; //表格
        form = layui.form;

        //执行一个 table 实例
        table.render({
            elem: '#demo'
            , id: 'idTest'
            , url: ctx + '/mccInfo/mccReflect/page' //数据接口
            , autoSort: false
            , 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.total, //解析数据长度
                    "data": res.data.records //解析数据列表
                };
            }
            , request: {
                pageName: 'current' //页码的参数名称，默认：page
                , limitName: 'size' //每页数据量的参数名，默认：limit
            }
            , title: 'app首页菜单表'
            , page: true //开启分页
            , toolbar: '#toolBar' //开启工具栏，此处显示默认图标，可以自定义模板，详见文档
            , defaultToolbar: ['filter']
            , cols: [[ //表头
                {type: 'checkbox'}
                , { field: 'standardMccCode', title: 'mcc编码(随行付)', minWidth: 40}
                , { field: 'sxfMccDesc', title: '随行付mcc编码描述', minWidth: 200 }
                , { field: 'ryxMcc', title: '瑞银信mcc', minWidth: 40}
                , { field: 'ryxMccDesc', title: '瑞银信mcc编码描述', minWidth: 40}
                , { field: '', title: '操作', minWidth: 80, templet: '#operation2' }
                , { field: 'ysMcc', title: '银盛mcc', minWidth: 200 }
                , { field: 'ysMccDesc', title: '随行付mcc编码描述', minWidth: 200 }
                , { field: '', title: '操作', minWidth: 80, templet: '#operation3' }
            ]]
        });

        //监听头工具栏事件
        table.on('toolbar(test)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id)
                , data = checkStatus.data; //获取选中的数据
            switch (obj.event) {
                case 'search':
                    search();
                    break;
            }
        });

        //监听行工具事件
        table.on('tool(test)', function (obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            var data = obj.data //获得当前行数据
                , layEvent = obj.event; //获得 lay-event 对应的值
            if (layEvent === 'edit') {
                toAdd(obj);
            } else if (layEvent === 'del') {
                layer.confirm('真的删除么?', {icon: 3}, function (index) {
                    del(obj)
                    layer.close(index);
                });
            } else if (layEvent === "editRyx") {
                toAdd(data.standardMccCode, 3);
            } else if (layEvent === "editYs") {
                toAdd(data.standardMccCode, 4);
            }
        });

        function del(obj) {
            $.ajax({
                url: ctx + '/mccInfo/mccReflect/del/' + obj.data.id,
                method: 'DELETE',
                dataType: 'JSON',
                contentType: "application/json",
                success: function (res) {
                    let icon = 2;
                    if(res.code == 200){
                        icon = 1;
                        obj.del();
                    }
                    layer.msg(res.message, {
                        icon:icon
                    });
                }
            })
        }

        function toAdd(standardMccCode, channelId) {
            var url = ctx + '/mccInfo/sxfMccEdit';
            if (standardMccCode != null) {
                url = url + "?sxfMcc=" + standardMccCode;
                url = url + "&channelId=" + channelId;
            }

            layer.open({
                type: 2
                , shade: 0.5
                , title: "编辑"
                , maxmin: true
                , content: url
                , area: ['500px', '400px']
                , end: function () {
                }
            });
        }
    });

    function search() {
        var condition = form.val('condition');
        table.reload('idTest', {
            where: condition
        }, true);
    }
</script>
</body>

</html>