<%@ page language="java" contentType="text/html; charset=utf-8"
         pageEncoding="utf-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!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="minWidth=device-minWidth, initial-scale=1.0, maximum-scale=1.0">
    <jsp:include page="../../common.jsp"/>
    <script type="text/javascript">
        require("js/merchantStore/merchantStoreList.js");
        require("js/jquery.qrcode.min.js");
    </script>
    <style type="text/css">
        .layui-table th {
            text-align: center;
        }

        .layui-dropdown {
            min-minWidth: 0px !important;
        }

        /*.layui-dropdown-item*/
        .layui-dropdown-item .layui-menu {
            background-color: #fff;
            border: none;
        }

        .layui-dropdown-item .layui-menu li {
            color: #fff;
            padding: 0;
        }

        .layui-menu {
            margin: 5px;
        }

        .layui-menu li, .layui-menu-body-title a {
            padding: 0;
        }

        .layui-menu-body-title a {
            display: block;
            margin: 0 !important;
            color: rgba(255, 255, 255, .8);
        }

        .c1 {
            position: fixed;
            top: 0;
            bottom: 0;
            left: 0;
            right: 0;
            background: rgba(0, 0, 0, .5);
            z-index: 2;
        }

        .c5 {
            position: fixed;
            minWidth: 350px;
            height: 250px;
            top: 50%;
            left: 50%;
            z-index: 3;
            margin-top: -125px;
            margin-left: -175px;
        }

        .img {
            minWidth: 100%;
            height: 100%;
            background-size: 100% 100%;
        }

        .layui-form-item {
            margin-bottom: 5px;
        }

        .layui-form-label {
            padding: 9px 7px;
            minWidth: 96px;
        }

        .layui-layer-content {
            padding: 10px;
        }

        .allopatry-btn {
            text-align: center;
            margin-top: 10px;
        }

        .layui-table th {
            text-align: center;
        }

        .layui-form-label {
            padding: 9px 7px;
            width: 96px;
        }


        .site-dropdown-demo,
        .site-dropdown-demo .layui-menu {
            background-color: #000;
            border: none;
        }

        .site-dropdown-demo .layui-menu li {
            color: #fff;
        }

        .site-dropdown-demo .layui-menu li:hover {
            background-color: #333;
        }

        .layui-table-cell.laytable-cell-1-0-5,
        .layui-table-cell.laytable-cell-1-0-1,
        .layui-table-cell.laytable-cell-1-0-8,
        .layui-table-cell.laytable-cell-1-1-0,
        .layui-table-cell.laytable-cell-1-1-1,
        .layui-table-cell.laytable-cell-1-1-2,
        .layui-table-cell.laytable-cell-1-0-11 {
            vertical-align: middle;
            height: auto;
            overflow: hidden;
            text-overflow: inherit;
            white-space: nowrap;
        }

        hr {
            margin: 3px 0 !important;
        }

        .layui-menu-body-title {
            padding: 0 15px;
        }

        .layui-menu-body-title > .layui-icon {
            position: absolute;
            left: 0;
            top: 0;
            font-size: 14px;
        }
    </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="" lay-filter="form" id="form1" style="margin-top: 10px">
                    <div class="layui-form-item">
                        <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>

                        <div class="layui-inline">
                            <label class="layui-form-label">所属商户</label>
                            <div class="layui-input-inline">
                                <input type="text" placeholder="请输入内容" id="merchantName" name="merchantName"
                                       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>

                        <div class="layui-inline">
                            <label class="layui-form-label">进件状态</label>
                            <div class="layui-input-inline">
                                <select name="mcsStatus" id="mcsStatus">
                                    <option value="">请选择</option>
                                    <option value="0">待进件</option>
                                    <option value="1">审核中</option>
                                    <option value="2">审核不通过</option>
                                    <option value="3">审核通过</option>
                                    <option value="4">秒审通过</option>
                                    <option value="5">复审不通过</option>
                                    <option value="7">快付审核中</option>

                                </select>
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label">商户类型</label>
                            <div class="layui-input-inline">
                                <select name="merchantType" id="merchantType">
                                    <option value="">请选择</option>
                                    <option value="1">小微</option>
                                    <option value="2">个体</option>
                                    <option value="3">企业</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">营销商户</label>
                            <div class="layui-input-inline">
                                <select name="isMarket" id="isMarket">
                                    <option value="">请选择</option>
                                    <option value="0">否</option>
                                    <option value="1">是</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">交易状态</label>
                            <div class="layui-input-inline">
                                <select name="status" id="status">
                                    <option value="">请选择</option>
                                    <option value="1">开通</option>
                                    <option value="2">禁用</option>
                                </select>
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label">异地支付</label>
                            <div class="layui-input-inline">
                                <select name="payEcdemicSwitch" id="payEcdemicSwitch">
                                    <option value="">请选择</option>
                                    <option value="1">开启</option>
                                    <option value="2">关闭</option>
                                </select>
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label">开始日期</label>
                            <div class="layui-input-inline">
                                <input type="text" placeholder="开始日期" id="date1" name="startTime" 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="date2" name="endTime" 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="location" name="location"
                                       class="layui-input">
                            </div>
                        </div>
                    </div>
                    <!-- <span class="dlblock w100 textr">门店状态</span>
                    <span class="bdc pt6 pb6 pl6 pr5 w180 dlblock">
                        <input type="text" placeholder="请输入名称">
                    </span>  -->
                    <div class="layui-form-item">


                    </div>
                    <div class="layui-form-item">

                    </div>
                </form>
            </div>
        </div>

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

<script type="text/template" id="audit">
    <form class="layui-form" id="form2" style="margin-top: 2rem;">
        <input  name="merchantCode" id="merchantCode" hidden>
        <input  name="channelId" id="channelId" hidden>
        <div class="layui-form-item" style="width: 300px;">
            <label class="layui-form-label">审核原因</label>
            <div class="layui-input-block">
                <textarea placeholder="请输入禁用原因" name="remark" id="banRemark" lay-verify="required"  required autocomplete="off" class="layui-textarea"></textarea>
            </div>
        </div>
    </form>
</script>

</body>
<script id="storeStatus" type="text/html">
    {{# if (d.status == '2') { }}
    <div style="color: red">禁用</div>
    {{# } else { }}
    <div style="color: green">开通</div>
    {{# } }}
</script>

<script id="storeIsMarket" type="text/html">
    {{# if (d.isMarket == '1') { }}
    <div style="color: green">是</div>
    {{# } else { }}
    <div style="color: red">否</div>
    {{# } }}
</script>

<script id="storeMerchantType" type="text/html">
    {{# if (d.merchantType == "1") { }}
    小微
    {{# } else if (d.merchantType == "2") { }}
    个体
    {{# } else if (d.merchantType == "3") { }}
    企业
    {{# } }}
</script>

<script id="lineBar" type="text/html">
    <div style="text-align: left">
        <a class="layui-btn layui-btn-xs" lay-event="openQrcode">
            <i class="layui-icon layui-icon-ok"></i>收款码
        </a>
        {{# if (d.mcsStatus == '3') { }}
        {{# if (d.validStatus == '-1') { }}
        <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="validStatus">
            启用该通道
        </a>
        {{# } else { }}
        <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="invalidStatus">
            禁用该通道
        </a>
        {{# } }}
        {{# } }}
        <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="more">
            更多&nbsp;<i class="layui-icon layui-icon-down"></i>
        </a>
    </div>
</script>
<%--<script id="lineBar" type="text/html">--%>
<%--    <a class="layui-btn layui-btn-xs" lay-event="openQrcode">--%>
<%--        <i class="layui-icon layui-icon-ok"></i>--%>
<%--        收款码--%>
<%--    </a>--%>
<%--    {{# if (d.mcsStatus == "7") { }}--%>
<%--    <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="quickAudit">--%>
<%--        <i class="layui-icon layui-icon-note"></i>--%>
<%--        快付审核--%>
<%--    </a>--%>
<%--    {{# } }}--%>
<%--    {{# if (d.channel == "4") { }}--%>
<%--    <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="splitSetting">--%>
<%--        <i class="layui-icon layui-icon-note"></i>--%>
<%--        分账设置--%>
<%--    </a>--%>
<%--    {{# } }}--%>

<%--</script>--%>
<%--<script id="barDemo" type="text/html">--%>
<%--    {{# if (d.status=='0') { }}--%>
<%--    <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="auditPass">--%>
<%--        <i class="layui-icon layui-icon-ok"></i>--%>
<%--        通过并打款--%>
<%--    </a>--%>
<%--    <a class="layui-btn layui-btn-xs" lay-event="auditSuccess">--%>
<%--        <i class="layui-icon layui-icon-edit"></i>--%>
<%--        通过--%>
<%--    </a>--%>
<%--    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="auditRefuse">--%>
<%--        <i class="layui-icon layui-icon-close"></i>--%>
<%--        拒绝--%>
<%--    </a>--%>
<%--    {{# } }}--%>
<%--</script>--%>

<script id="toolBar" type="text/html">
    <a class="layui-btn layui-btn-sm" href="javascript:void(0);" onclick="reload()">
        <i class="layui-icon layui-icon-search"></i>查询
    </a>
    <a class="layui-btn layui-btn-sm layui-btn-danger" href="javascript:void(0);" data-index="1"
       onclick="disableMerchantStore()">
        <i class="layui-icon layui-icon-edit"></i>禁用
    </a>
    <a class="layui-btn layui-btn-sm" href="javascript:void(0);" data-index="1"
       onclick="payEcdemicSwitchMerchantStore()">
        <i class="layui-icon layui-icon-edit"></i>异地支付
    </a>
    <a class="layui-btn layui-btn-sm" href="javascript:void(0);" data-index="1"
       onclick="isMarket()">
        <i class="layui-icon layui-icon-edit"></i>营销商户
    </a>
    <a class="layui-btn layui-btn-sm" href="javascript:void(0);"
       onclick="batchMerchantIncom()">
        <i class="layui-icon layui-icon-edit"></i>批量进件
    </a>
    <a class="layui-btn layui-btn-sm layui-btn-warm upload">
        <i class="layui-icon layui-icon-upload-drag"></i>D0快付导入
    </a>
    <a class="layui-btn layui-btn-sm layui-btn-normal download">
        <i class="layui-icon layui-icon-download-circle"></i>D0快付导出
    </a>
</script>

<script id="toolbarMenu" type="text/html">

</script>

<script id="storePayEcdemicSwitch" type="text/html">
    {{# if (d.payEcdemicSwitch == "1") { }}
    <span style='color: red;'>开启</span>
    {{# } else { }}
    <span style='color: green;'>关闭</span>
    {{# } }}
</script>

<script id="transmitStatus" type="text/html">
    {{# if (d.mcsStatus == "1") { }}
    <span style='color: red;'>审核中</span>
    {{# } else if (d.mcsStatus == "2") { }}
    <span style='color: red;'>审核不通过</span>
    {{# } else if (d.mcsStatus == "3") { }}
    <span style='color: green;'>审核通过</span>
    {{# } else if (d.mcsStatus == "4") { }}
    <span style='color: green;'>秒审通过</span>
    {{# } else if (d.mcsStatus == "5") { }}
    <span style='color: red;'>复审不通过</span>
    {{# } else if (d.mcsStatus == "7") { }}
    <span style='color: red;'>快付审核中</span>
    {{# } else { }}
    <span style='color: blue;'>待进件</span>
    {{# } }}
</script>


<script type="text/template" id="desc">
    <form class="layui-form" action="" style="minWidth: 80%; margin-top: 20px">
        <input type="hidden" name="id" id="id">
        <input type="hidden" name="payEcdemicSwitch" id="allopatry">
        <div class="layui-form-item">
            <label class="layui-form-label">备注：</label>
            <div class="layui-input-block" style="margin-left:0px">
                <div class="layui-input-block">
                    <textarea name="remark" id="remark" placeholder="备注说明" class="layui-textarea"></textarea>
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="remarkForm">确认更改</button>
                <button type="button" id="remarkClose" class="layui-btn layui-btn-primary">关闭</button>
            </div>
        </div>
    </form>
</script>


<script type="text/template" id="setApiParam">
    <form class="layui-form" action="">
        <input type="hidden" name="id" id="mercId">
        <div class="layui-form-item">
            <label class="layui-form-label">密钥：</label>
            <div class="layui-input-block" style="margin-left:0px">
                <div class="layui-input-block" style="display: flex">
                    <input type="text" placeholder="商户密钥" style="width: 70%" name="md5Key"
                           id="md5Key" autocomplete="off" class="layui-input">
                    <button type="button" class="layui-btn layui-btn-primary layui-border-blue" id="createKey">生成
                    </button>
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">小程序Appid：</label>
            <div class="layui-input-block" style="margin-left:0px">
                <div class="layui-input-block" style="display: flex">
                    <input type="text" placeholder="小程序Appid" style="width: 70%" name="subAppId"
                           id="subAppId" autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">公众号Appid：</label>
            <div class="layui-input-block" style="margin-left:0px">
                <div class="layui-input-block" style="display: flex">
                    <input type="text" placeholder="公众号appid" style="width: 70%"  name="appid"
                           id="appid" autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>

        <div class="layui-form-item" style="margin-top: 2rem">
            <div class="layui-input-block">
                <button class="layui-btn" id="setApiParamForm" lay-submit lay-filter="setApiParamForm">保存</button>
                <button type="button" id="setApiParamClose" class="layui-btn layui-btn-primary">关闭</button>
            </div>
        </div>
    </form>
</script>

<script type="text/javascript">

    var layer;
    var form;
    var table;
    var laydate;
    var dropdown;

    //form表单样式
    layui.use(['table', 'layer', 'form', 'laydate', 'dropdown', 'upload'], function () {
        layer = layui.layer;
        form = layui.form;
        table = layui.table;
        laydate = layui.laydate;
        dropdown = layui.dropdown;
        var upload = layui.upload;
        form.render();

        laydate.render({
            elem: '#date1' //指定元素
            , format: 'yyyy-MM-dd HH:mm:ss'
            , type: 'datetime'
        });
        laydate.render({
            elem: '#date2' //指定元素
            , format: 'yyyy-MM-dd HH:mm:ss'
            , type: 'datetime'
        });

        //执行一个 table 实例
        table.render({
            elem: '#merchantStoreList'
            , id: 'merchantStoreList'
            , url: ctx + '/merchantStore/queryMerchantStoreByPage' //数据接口
            , 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.count, //解析数据长度
                    "data": res.merchantStoreList //解析数据列表
                };
            }
            , request: {
                pageName: 'currPage' //页码的参数名称，默认：page
                , limitName: 'size' //每页数据量的参数名，默认：limit
            }
            , title: '门店信息表'
            , page: true //开启分页
            , toolbar: '#toolBar' //开启工具栏，此处显示默认图标，可以自定义模板，详见文档
            , defaultToolbar: ['filter']
            , cols: [[ //表头
                {type: 'numbers'}
                , {type: 'checkbox'}
                , {field: 'userId', title: '用户ID', width: 80, align: "center", templet: '#imgTemp'}
                , {field: 'alias', title: '商户简称', minWidth: 86}
                , {field: 'merchantName', title: '所属商户', minWidth: 86}
                , {field: 'status', title: '交易状态', minWidth: 86, templet: '#storeStatus', align: "center"}
                , {field: 'isMarket', title: '营销商户', minWidth: 86, templet: '#storeIsMarket', align: "center"}
                , {field: 'merchantType', title: '门店类型', minWidth: 86, templet: '#storeMerchantType', align: "center"}
                , {
                    field: 'rate', title: '费率%', minWidth: 80, align: "center", templet: function (d) {
                        return (d.rate / 100).toFixed(2);
                    }
                }
                , {
                    title: '结算类型', minWidth: 86, align: "center", templet: (d) => {
                        if (d.settleType === "D1" && d.channel != 4) {
                            return d.settleType
                        } else {
                            return '<input type="checkbox" ' + (d.settleType == "D0" || !d.settleType ? "checked" : "") + ' data-csId="' + d.csId + '" name="switch" lay-skin="switch" lay-filter="switchIsSettleType" lay-text="D0|D1">';
                        }
                    }
                }
                , {
                    field: 'payEcdemicSwitch',
                    title: '异地支付',
                    align: "center",
                    minWidth: 86,
                    templet: '#storePayEcdemicSwitch'
                }
                , {
                    title: '银联支付', minWidth: 95, align: "center", templet: (d) => {
                        return '<input type="checkbox" ' + (d.isUnionPay == "1" ? "checked" : "") + ' data-mercId="' + d.mercId + '" name="switch" lay-skin="switch" lay-filter="switchIsUnionPay" lay-text="开启|关闭">';
                    }
                }
                , {field: 'mcsStatus', title: '进件状态', align: "center", minWidth: 90, templet: '#transmitStatus'}
                , {
                    field: 'incomTime',
                    title: '进件时间',
                    minWidth: 160,
                    templet: "<div>{{layui.util.toDateString(d.incomTime,'yyyy-MM-dd HH:mm:ss')}}</div>"
                }
                , {
                    field: 'location', title: '详细地址', minWidth: 100, templet: function (d) {
                        return d.province + "-" + d.city + "-" + d.district + "-" + d.address;
                    }
                }
                , {field: 'operatRemark', title: '备注', align: "center", minWidth: 100}
                , {fixed: 'right', title: '操作', minWidth: '250', toolbar: '#lineBar'}
            ]]
        });

        upload.render({ //允许上传的文件后缀
            elem: '.upload'
            , url: ctx + '/merchantStore/exportD0Excel' //改成您自己的上传接口
            , accept: 'file' //普通文件
            , acceptMime: 'application/vnd.ms-excel, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
            , exts: 'xlsx|xls' //只允许上传excel
            , before: function () {
                layer.load(1);
            }
            , done: function (res) {
                layer.closeAll();
                var icon = 2;
                if (res.code == 200) {
                    icon = 1;
                    reload();
                }
                layer.msg(res.message, {icon: icon});

            }
        });

        //监听行工具事件
        table.on('tool(merchantStoreList)', function (obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            var data = obj.data //获得当前行数据
                , that = this
                , layEvent = obj.event; //获得 lay-event 对应的值
            switch (layEvent) {
                case 'openQrcode':
                    let isPaySwitch = data.payEcdemicSwitch;
                    if (!isPaySwitch) {
                        isPaySwitch = 0;
                    }
                    showMerchantStoreReceipt(data, isPaySwitch);
                    break;
                case 'invalidStatus':
                    showBanValidStatus(data);
                    break;
                case 'validStatus':
                    showOpenValidStatus(data);
                    break;
                case 'more':
                    let itemData = [
                        {
                            title: '设置api参数'
                            , id: 'setApiParam'
                            , templet: '<i class="layui-icon layui-icon-key"></i> {{d.title}}'
                        },
                    ];
                    if (data.mcsStatus == "7") {
                        itemData.push({
                            title: '快付审核'
                            , id: 'quickAudit'
                        });
                    }
                    if (data.channel == "4") {
                        itemData.push({
                            title: '分账设置'
                            , id: 'splitSetting'
                        });
                    }
                    dropdown.render({
                        elem: that
                        , show: true //外部事件触发即显示
                        , data: itemData
                        , className: 'site-dropdown-demo'
                        , click: function (mData, othis) {
                            switch (mData.id) {
                                case 'quickAudit':
                                    updateChannelStatus(data.csId, "3", data.userId);
                                    break;
                                case 'splitSetting':
                                    splitSetting(data);
                                    break;
                                case 'setApiParam':
                                    setApiParam(data);
                                    break;
                                case 'setAppid':
                                    setAppid(data);
                                    break;
                            }
                        }
                        , align: 'right' //右对齐弹出（v2.6.8 新增）
                        , style: 'box-shadow: 1px 1px 10px rgb(0 0 0 / 12%);' //设置额外样式
                    });
                    break;
            }

            // var data = obj.data //获得当前行数据
            //     , layEvent = obj.event; //获得 lay-event 对应的值
            // if (layEvent === 'openQrcode') {
            //     let isPaySwitch = data.payEcdemicSwitch;
            //     if (!isPaySwitch) {
            //         isPaySwitch = 0;
            //     }
            //     showMerchantStoreReceipt(data.userId, data.settleType, data.id, isPaySwitch);
            // } else if (layEvent === 'quickAudit') {
            //     updateChannelStatus(data.csId, "3", data.userId);
            // }else if (layEvent === 'splitSetting') {
            //     splitSetting(data);
            // }
        });

        $(document).on("click", ".download", function () {
            var startTime = $("#date1").val();
            var endTime = $("#date2").val();
            if (!startTime || !endTime) {
                layer.msg("开始时间和结束时间不能为空！", {icon: 2});
                return;
            }
            var index = layer.load(1);
            window.location.href = ctx + '/merchantStore/dowloadD0QuicklyExcel?startTime=' + startTime + '&endTime=' + endTime;
            setTimeout("layer.closeAll()", 5000);
        })
        var dIndex = 0;
        //监听提交
        var dxStatus = 0;
        form.on('submit(remarkForm)', function (data) {
            var index = layer.load(1, {shade: [0.1, '#000']});
            $.ajax({
                url: ctx + '/merchantStore/payEcdemicSwitchMerchantStore',
                method: 'post',
                data: data.field,
                dataType: 'JSON',
                success: function (res) {
                    layer.close(index);
                    layer.close(dIndex);
                    layer.msg(res.msg);
                    dxStatus = 1;
                    dkStatus = 1;
                }
            })
            return false;
        });

        form.on('submit(setApiParamForm)', function (data) {
            layer.load(1, {shade: [0.1, '#000']});
            $.ajax({
                url: ctx + '/merchantBaseInfo/updateInfo',
                method: 'post',
                data: data.field,
                dataType: 'JSON',
                success: function (res) {
                    layer.closeAll();
                    layer.msg(res.message, {
                        icon: res.code == 200 ? 1 : 2
                    });
                    var params = serialize($('#form1'));
                    table.reload('merchantStoreList', {
                        where: params
                        , page: {
                            size: 10
                            , current: 1
                        }
                    });
                }
            })
            return false;
        });

        function splitSetting(obj) {
            let csId = obj.csId;
            var url = '${ctx}/mercSplitSetting/index/' + csId;
            var title = "商户分账详情";
            var index = layer.open({
                type: 2
                , shade: 0.5
                , title: title
                , maxmin: true
                , content: url
                , area: ['90%', '90%']
                , end: function () {
                }
            });
        }

        function setApiParam(obj) {
            let mercId = obj.mercId;
            let md5Key = obj.md5Key;
            let subAppId = obj.subAppId;
            let appid = obj.appid;
            var title = "api参数";
            var index = layer.open({
                type: 1
                , shade: 0.5
                , title: title
                , maxmin: true
                , content: $("#setApiParam").html()
                , area: ['500px', '300px']
                , success: function () {
                    if (md5Key) {
                        $("#md5Key").val(md5Key);
                        $("#createKey").addClass("layui-btn-disabled");
                        $("#createKey").attr("id","createKey-disabled");
                        $("#createKey").attr("readonly", true);
                    }
                    $("#mercId").val(mercId);
                    $("#subAppId").val(subAppId);
                    $("#appid").val(appid);
                }
            });
        }
        // function setAppid(obj) {
        //     console.log(obj);
        //     let mercId = obj.mercId;
        //     let subAppId = obj.subAppId;
        //     let appid = obj.appid;
        //     var title = "设置商户appid";
        //     var index = layer.open({
        //         type: 1
        //         , shade: 0.5
        //         , title: title
        //         , maxmin: true
        //         , content: $("#setAppid").html()
        //         , area: ['400px', '250px']
        //         , success: function () {
        //             $("#setAppidMercId").val(mercId);
        //             $("#subAppId").val(subAppId);
        //             $("#appid").val(appid);
        //         }
        //     });
        // }


        form.on('switch(switchIsUnionPay)', function (data) {
            let isUnionPay = 0;
            let mercid = $(data.elem).data().mercid;
            if (this.checked) {
                isUnionPay = 1;
                layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅 仅是ON|OFF', data.othis)
            } else {
                isUnionPay = 0
            }
            $.ajax({
                url: ctx + "/merchantBaseInfo/updateInfo",
                data: {"id": mercid, "isUnionPay": isUnionPay},
                method: 'POST',
                dateType: 'json',
                success: res => {
                    layer.msg(res.message, {
                        offset: '6px',
                        icon: res.code == 200 ? 1 : 2
                    });
                }
            })
            //do some ajax opeartiopns;
        });

        form.on('switch(switchIsSettleType)', function (data) {
            layer.confirm('确认修改当前商户的结算类型？', {
                icon: 3, title: '提示',
                btn: ['确认', '取消',] //可以无限个按钮
            }, function (index, layero) {
                let dom = $(data.elem).next("div");
                let classVal = dom.attr("class").indexOf("layui-form-onswitch");
                let settleType = "D1";
                let csid = $(data.elem).data().csid;
                if (classVal > -1) {
                    settleType = "D0";
                    layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅 仅是ON|OFF', data.othis)
                } else {
                    settleType = "D1";
                }
                $.ajax({
                    url: ctx + "/merchantBaseInfo/updateSettleType",
                    data: {"id": csid, "settlementType": settleType},
                    method: 'POST',
                    dateType: 'json',
                    success: res => {
                        layer.msg(res.message, {
                            offset: '6px',
                            icon: res.code == 200 ? 1 : 2
                        });
                    }
                })
            }, function (index, layero) {
                $(data.elem).prop('checked', !data.elem.checked)
                layui.form.render();//刷新表格
                layer.msg('您点击了拒绝！');
            });
            //do some ajax opeartiopns;
        });


        $(document).on("click", "#remarkClose,#setApiParamClose", (res) => {
            layer.closeAll();
        });

        $(document).on("click", "#createKey", (res) => {
            let index = layer.load(1, {shade: [0.1, '#000']});
            let url = ctx + "/merchantBaseInfo/createKey";
            $.get(url, function (res) {
                layer.close(index);
                $("#md5Key").val(res.data);
            })
        })
        $(document).on("click", ".layui-layer-close1", (res) => {
            if (dkStatus == 0 || dkStatus == undefined || dkStatus == '') {
                return;
            }
            let $data = {};
            $data.payEcdemicSwitch = 1;
            $data.id = dkId;
            $.ajax({
                url: ctx + '/merchantStore/payEcdemicSwitchMerchantStore',
                method: 'post',
                data: $data,
                dataType: 'JSON',
                success: function (res) {
                    dxStatus = 0;
                    layer.msg(res.msg, {
                        icon: res.resultCode == 1 ? 1 : 2
                    });
                }
            })
        })
        $(document).on("click", ".allopatry", (res) => {
            let $data = $(res.currentTarget).data();
            let $title = $data.t === "open" ? '开启异地支付' : '关闭异地支付';
            let $value = $data.t === "open" ? 0 : 1;
            if ($value === 0) {
                dIndex = layer.open({
                    type: 1,
                    title: $title,
                    shade: 0.5,
                    maxmin: true,
                    area: ['550px', '300px'],
                    content: $("#desc").html(),
                    success: (res) => {
                        $("#id").val($data.id);
                        $("#allopatry").val($value);
                    }
                });
            } else {
                if ($data.value === 0 && $value === 1 && dxStatus != 1) {
                    layer.close(dkIndex);
                } else {
                    $data.payEcdemicSwitch = $value;
                    $.ajax({
                        url: ctx + '/merchantStore/payEcdemicSwitchMerchantStore',
                        method: 'post',
                        data: $data,
                        dataType: 'JSON',
                        success: function (res) {
                            dxStatus = 0;
                            layer.msg(res.msg);
                        }
                    })
                }

                <%--$.post('${ctx}/merchantStore/payEcdemicSwitchMerchantStore',{data:},(res)=>{--%>
                <%--    layer.msg(res.message, {--%>
                <%--        icon: res.resultCode == 1 ? 1 : 2--%>
                <%--    });--%>
                <%--})--%>
            }
        })
    });

    //查询
    function reload() {
        table.reload('merchantStoreList', {
            page: {
                curr: 1
            }
            , where: form.val('form')
        }, false);
    }

    function showBanValidStatus(data) {
        layer.open({
            type: 1,
            title: '提示',
            offset: 'm', //具体配置参考：offset参数项
            area: ['400px', '300px'],
            content: $("#audit").html(),
            btn: ['确认', '取消'],
            shade: 0.3,
            btn1: function (index, layero) {
                layer.closeAll();
                var index = layer.load(1, {shade: [0.1, '#000']});
                $.ajax({
                    type: 'POST'
                    , url: ctx + "/merchantStore/banChannelValid"
                    , data: {
                        channelId: data.channel,
                        merchantCode: data.merchantCode,
                        remark: $("#banRemark").val()
                    }
                    , success: function (d) {
                        if (d.code == 200) {
                            layer.close(index);
                        } else {
                            layer.close(index);
                        }

                        reload()
                    }
                });
            }
            ,btn2: function(index, layero){
                layer.close(index);
            }
        });
    }

    function showOpenValidStatus(data) {
        layer.open({
            type: 1,
            closeBtn: 1, title: '提示',
            offset: 'm', //具体配置参考：offset参数项
            area: ['300px', '180px'],
            content: '<div style="padding:10px;" class="textc mt20">确认启用' + data.settleType + '支付权限？</div>',
            btn: ['确认', '取消'],
            btnAlign: 'r', //按钮居中
            shade: 0.3,//不显示遮罩
            yes: function () {
                layer.closeAll();
                var index = layer.load(1, {shade: [0.1, '#000']});
                $.ajax({
                    type: 'POST'
                    , url: ctx + "/merchantStore/openChannelValid"
                    , data: {
                        channelId: data.channel,
                        merchantCode: data.merchantCode
                    }
                    , success: function (d) {
                        if (d.code == 200) {
                            layer.close(index);
                        } else {
                            layer.close(index);
                        }

                        reload()
                    }
                });
            }
        });
    }

</script>
</html>