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

<form class="layui-form" id="form1" action="" style="margin-top: 30px;">
    <div class="layui-inline">
        <label class="layui-form-label">主商户号</label>
        <div class="layui-input-block">
            <input type="text" name="chieMerchantCode"  placeholder="主商户号" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-inline">
        <label class="layui-form-label">主商户名</label>
        <div class="layui-input-block">
            <input type="text" name="chieMerchantName"  placeholder="主商户名称" autocomplete="off" class="layui-input">
        </div>
    </div>
</form>
<table class="layui-hide" id="mercSplitSettingTab" lay-filter="mercSplitSettingTab"></table>
<script type="text/html" id="leftBar">
    <button type="button" class="layui-btn layui-btn-sm" lay-event="add"><i class="layui-icon">&#xe608;</i>新增</button>
    <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" lay-event="search"><i class="layui-icon">&#xe615;</i>查询</button>
</script>

<script type="text/html" id="toolBar">
    <button type="button" class="layui-btn layui-btn-sm" lay-event="edit"><i class="layui-icon">&#xe642;</i>编辑</button>
    <button type="button" class="layui-btn layui-btn-sm layui-btn-danger" lay-event="del"><i class="layui-icon">&#xe640;</i>删除</button>
</script>

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

        var tableIns = table.render({
            elem: '#mercSplitSettingTab'
            ,url:'${ctx}/mercSplitSetting/selectPage'
            ,id: 'mercSplitSetting'
            ,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:'chieMerchantName', title:'主商户名'}
                ,{field:'chieMerchantCode', title:'主商户号'}
                ,{field:'diviMerchantName', title:'分账商户名'}
                ,{field:'diviMerchantCode', title:'分账商户号'}
                // ,{field:'chieMerchantId', title:'通道商户号'}
                ,{field:'isDivistion', title:'是否分账',templet: function (d) {
                    return d.isDivistion === '01' ? "是" : "否";
                }}
                ,{field:'divisionMode', title:'分账模式',templet: function (d) {
                        return d.isDivistion === '01' ? "比例" : "金额";
                }}
                // ,{field:'diviMerchantCode', title:'分账通道商编'}
                ,{field:'divAmt', title:'分账金额',templet: function (d) {
                    return d.divAmt ? d.divAmt.toFixed(2) : "-";
                }}
                ,{field:'divRatio', title:'分账比例'}
                // ,{field:'isChargeFee', title:'收取手续费',templet: function (d) {
                //     return d.isDivistion === '01' ? "是" : "否";
                // }}

                ,{field:'status', title:'状态',templet: function (d) {
                    if(d.status == '1'){
                        return "<span style='color: green'>正常</span>"
                    }else{
                        return "<span style='color: red'>关闭</span>"
                    }
                 }}
                ,{field: 'createTime', title: '创建时间', width: 160,templet : "<div>{{layui.util.toDateString(d.createTime,'yyyy-MM-dd HH:mm:ss')}}</div>"}
                ,{fixed: 'right', title:'操作',width:200, toolbar: '#toolBar'}
            ]]
            ,request: {
                pageName: 'current' //页码的参数名称，默认：page
                ,limitName: 'size' //每页数据量的参数名，默认：limit
            }
            ,page: true
        });
        table.on('tool(mercSplitSettingTab)', function(obj){ //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            if(layEvent === 'del'){ //删除
                layer.confirm('真的删除么?',{icon:3},function(index){
                    obj.del(); //删除对应行（tr）的DOM结构，并更新缓存
                    layer.close(index);
                    del(data);
                    //向服务端发送删除指令
                });
            } else if(layEvent === 'edit'){ //编辑
                //do something
                toAdd(obj.data);
                //同步更新缓存对应的值
                // obj.update({
                //     username: '123'
                //     ,title: 'xxx'
                // });
            }
        });

        //监听头工具栏事件
        table.on('toolbar(mercSplitSettingTab)', function (obj) {
            switch (obj.event) {
                case 'add':
                    // 添加
                    toAdd();
                    break;
                case 'search':
                    var params= serialize($('#form1'));
                    table.reload('mercSplitSetting', {
                        where: params
                        , page: {
                            size: 10
                            , current: 1
                        }
                    });
                    break;
            }
        });
        function toAdd(obj) {
            let csId = '${csId}';
            var url = '${ctx}/mercSplitSetting/detail/'+csId;
            var title = "新增";
            if(obj != undefined){
                url = "${ctx}/mercSplitSetting/detail/"+csId+"/"+obj.id;
                title = "编辑"
            }
            var index = layer.open({
                type: 2
                ,shade: 0.5
                ,title: title
                ,maxmin: true
                , content: url
                , area: ['450px', '620px']
                ,end:function () {

                }
            });
        }
        function del(obj) {
            $.ajax({
                url: '${ctx}/mercSplitSetting/del/'+obj.id,
                method: 'DELETE',
                dataType: 'JSON',
                contentType:"application/json",
                success: function(res) {
                    if(res.code == 200) {
                        layer.msg(res.data, {
                            icon: 1
                        });
                    } else {
                        layer.msg(res.data, {
                            icon: 2
                        });
                    }
                }
            })
        }
    });
</script>
</body>
</html>
