<%@ page 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="width=device-width, initial-scale=1.0, maximum-scale=1.0">
    <jsp:include page="../../common.jsp"/>
    <script type="text/javascript">
        require("promoter/userAppList.js");
    </script>

    <style>
        .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-7,
        .layui-table-cell.laytable-cell-1-0-1,
        .layui-table-cell.laytable-cell-1-0-3,
        .layui-table-cell.laytable-cell-1-0-8,
        .layui-table-cell.laytable-cell-1-1-0,
        .layui-table-cell.laytable-cell-1-1-2,
        .layui-table-cell.laytable-cell-1-1-3,
        .layui-table-cell.laytable-cell-1-1-4,
        .layui-table-cell.laytable-cell-1-0-10,
        .layui-table-cell.laytable-cell-1-0-11,
        .layui-table-cell.laytable-cell-1-0-14 {
            vertical-align: middle;
            height: auto;
            overflow: hidden;
            text-overflow: inherit;
            white-space: nowrap;
        }

        hr {
            margin: 3px 0 !important;
        }

    </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" lay-filter="formCondition">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">用户ID</label>
                            <div class="layui-input-inline">
                                <input type="text" id="userId" name="userId" placeholder="请输入用户ID" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label">同IP用户</label>
                            <div class="layui-input-inline">
                                <input type="checkbox" id="sameIp" lay-skin="switch" value="1" name="sameIp" disabled>
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label">用户名称</label>
                            <div class="layui-input-inline">
                                <input type="text" id="userName" name="userName" placeholder="请输入名称"
                                       class="layui-input">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label">商户简称</label>
                            <div class="layui-input-inline">
                                <input type="text" id="alias" name="alias" placeholder="请输入商户简称" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label">商户编号</label>
                            <div class="layui-input-inline">
                                <input type="text" id="merchantCode" name="merchantCode" placeholder="商户编号"
                                       class="layui-input">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label">推广码</label>
                            <div class="layui-input-inline">
                                <input type="text" id="inviteNum" name="inviteNum" placeholder="请输入名称"
                                       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="phone" name="phone" 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="parentPhone" name="parentPhone"
                                       class="layui-input">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label">审核状态</label>
                            <div class="layui-input-inline">
                                <select id="status" 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 class="layui-inline">--%>
                        <%--                            <label class="layui-form-label">用户类型</label>--%>
                        <%--                            <div class="layui-input-inline">--%>
                        <%--                                <select id="userType" name="userType">--%>
                        <%--                                    <option value="">请选择</option>--%>
                        <%--                                    <option value="promoter">普通</option>--%>
                        <%--                                    <option value="agent_staff">业务员</option>--%>
                        <%--                                    <option value="agent_agency">代理</option>--%>
                        <%--                                    <option value="agent">超级</option>--%>
                        <%--                                </select>--%>
                        <%--                            </div>--%>
                        <%--                        </div>--%>

                        <div class="layui-inline">
                            <label class="layui-form-label">进件审核状态</label>
                            <div class="layui-input-inline">
                                <select id="mcsStatus" name="mcsStatus">
                                    <option value="">请选择</option>
                                    <option value="0">待审核</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 id="ppStatus" name="ppStatus">--%>
                        <%--                                    <option value="">请选择</option>--%>
                        <%--                                    <option value="0">插件待审核</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 id="merchantType" name="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">
                                <input type="text" placeholder="请输入内容" id="merchantId" name="merchantId"
                                       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="wxMercNo" name="wxMercNo"
                                       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="zfbMercNo" name="zfbMercNo"
                                       class="layui-input">
                            </div>
                        </div>

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

        <!-- 表单数据 -->
        <table class="layui-hide" id="userAppList" lay-filter="userAppList"></table>
    </div>
</div>

<script id="merchantBaseInfo" type="text/html">
    {{# if(d.merchantType == null || d.merchantType == '') { }}
    <span style="color: #c2c2c2">无商户信息</span>
    {{# } else { }}
    <div class="layui-col-md12" style="color: #1E9FFF; text-align: start;">
        {{# if (d.merchantType == "1") { }}
        小微
        {{# } else if (d.merchantType == "2" ) { }}
        个体
        {{# } else if (d.merchantType == "3" ) { }}
        企业
        {{# } }}
        &emsp;&emsp;&emsp;&emsp;
        {{# if (d.isBlack == true) { }}
        <span style="color: #FF5722;">已拉黑</span>
        {{# } }}
    </div>
    <hr/>
    <div class="layui-col-md12" style="color: #393D49; text-align: start;">
        {{d.merchantCode}}
    </div>
    <hr/>
    <div class="layui-col-md12" style="color: #009688; text-align: start;">
        {{d.alias}}
    </div>
    {{# } }}
</script>

<script id="userBaseInfo" type="text/html">
    <div class="layui-col-md12">
        {{d.userId}}
    </div>
    <hr/>
    <div class="layui-col-md12">
        {{# if (d.userName == null || d.userName == '') { }}
        -
        {{# } else { }}
        {{d.userName}}
        {{# } }}
    </div>
    <hr/>
    <div class="layui-col-md12">
        {{ d.phone.substring(0, 11)}}
    </div>
</script>

<script id="parentInfo" type="text/html">
    {{# if(d.parentUserId == null) { }}
    暂无上级
    {{# } else { }}
    <div class="layui-col-md12">
        {{d.parentUserId}}
    </div>
    <hr/>
    <div class="layui-col-md12">
        {{# if (d.parentUserName == null || d.parentUserName == '') { }}
        -
        {{# } else { }}
        {{d.parentUserName}}
        {{# } }}
    </div>
    <hr/>
    <div class="layui-col-md12">
        {{d.parentPhone}}
    </div>
    {{# } }}
</script>

<script id="spreadInfo" type="text/html">
    <div class="layui-col-md12" style="text-align: center">
        {{# if (d.uiStatus == '-2') { }}
            <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="openSpread">
                打开
            </a>
        {{# } else { }}
            <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="banSpread">
                关闭
            </a>
        {{# } }}
    </div>
    <div class="layui-col-md12" style="text-align: center">
        {{d.inviteNum}}
    </div>
</script>

<script id="extensionParentUserType" type="text/html">
    {{# if (d.parentUserType == "agent") { }}
    <span style="color:#FF5722">超级</span>
    {{# } else if (d.parentUserType == "agent_staff") { }}
    <span style="color: blue">业务员</span>
    {{# } else if (d.parentUserType == "agent_agency") { }}
    <span style="color: green">代理</span>
    {{# } else if (d.parentUserType == "promoter") { }}
    <span>普通</span>
    {{# } }}
</script>


<script id="extensionUserType" type="text/html">
    {{# if (d.userType == "agent") { }}
    <span style="color:red">超级</span>
    {{# } else if (d.userType == "agent_staff") { }}
    <span style="color: blue">业务员</span>
    {{# } else if (d.userType == "agent_agency" ) { }}
    <span style="color: green">代理</span>
    {{# } else if (d.userType == "promoter") { }}
    <span>普通</span>
    {{# } }}
</script>

<script id="toolBar" type="text/html">
    <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-danger layui-btn-sm" lay-event="batch2Blacklist">
        <i class="layui-icon layui-icon-close-fill"></i>批量拉黑
    </a>
</script>

<script id="extensionStatus" type="text/html">
    {{# if (d.status=='0') { }}
    <span>未实名</span>
    {{# } else if (d.status=='1') { }}
    <span>审核中</span>
    {{# } else if (d.status=='2') { }}
    <span>审核失败</span>
    {{# } else if (d.status=='3') { }}
    <span>已审核</span>
    {{# } }}
</script>

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

<script id="extensionThirdStatus" type="text/html">
    {{# if (d.mcsStatus == "1" && d.thirdStatus == "-100") { }}
    <span style="color: blue">待审核</span>
    {{# } else if (d.mcsStatus == "1" && d.thirdStatus != "-100") { }}
    <span style="color: green">审核中</span>
    {{# } else if ( (d.mcsStatus == "0" && d.thirdStatus == "-100") || d.mcsStatus == "2" ) { }}
    <span style="color: red">审核驳回</span>
    {{# } else if (d.mcsStatus == "3" ) { }}
    {{# if (d.ppStatus == "1" && d.ppThirdStatus == "-100") { }}
    <span style="color: blue">插件待审核</span>
    {{# } else if (d.ppStatus == "1" && d.ppThirdStatus != "-100") { }}
    <span style="color: green">插件审核中</span>
    {{# } else if ( (d.ppStatus == "0" && d.ppThirdStatus == "-100") || d.ppStatus == "2" ) { }}
    <span style="color: red">插件审核驳回</span>
    {{# } else if (d.ppStatus == "3" ) { }}
    <span>插件审核通过</span>
    {{# } else if (d.ppStatus == "0" || d.ppStatus == '' || d.ppStatus == null ) { }}
    <span>审核通过</span>
    {{# } }}
    {{# } else  { }}
    <span>未进件</span>
    {{# } }}
</script>


<script id="extensionThird3Status" type="text/html">
    {{ thirdStatus('{{=d.msc3Status}}') }}
</script>

<script id="extensionThird4Status" type="text/html">
    {{ thirdStatus('d.msc4Status') }}
</script>

<script id="lineBar2" type="text/html">
    <div class="layui-col-md12">
        <a href="javascript:void(0);" lay-event="sendNotice" class="layui-btn layui-btn-xs">
            <i class="layui-icon layui-icon-release"></i>&nbsp;发送通知
        </a>
    </div>
</script>

<script id="lineBar" type="text/html">
    <div style="text-align: center">
        <div class="layui-col-md12">
            <a href="javascript:void(0);" lay-event="detail2" class="layui-btn layui-btn-xs">
                <i class="layui-icon layui-icon-edit"></i>&nbsp;详情
            </a>
        </div>

        <div class="layui-col-md12">
            <a href="javascript:void(0);" lay-event="toBlacklist" class="layui-btn layui-btn-danger layui-btn-xs">
                <i class="layui-icon layui-icon-close-fill"></i>&nbsp;拉黑
            </a>
        </div>

        <div class="layui-col-md12">
            <a href="javascript:void(0);" lay-event="more" class="layui-btn layui-btn-normal layui-btn-xs">
                更多&nbsp;<i class="layui-icon layui-icon-down"></i>
            </a>
        </div>

        <%--        <a href="javascript:void(0);" lay-event="detail" class="layui-btn layui-btn-xs">--%>
        <%--            <i class="layui-icon layui-icon-edit"></i>详情old--%>
        <%--        </a>--%>


    </div>
</script>


<script type="text/template" id="upgrade">
    <form class="layui-form" id="form2" style="margin-top: 1rem;">
        <div class="layui-form-item" style="width: 300px;">
            <label class="layui-form-label">选择等级</label>
            <div class="layui-input-block">
                <select class="layui-select" id="leveCode" name="leveCode">

                </select>
            </div>
        </div>
    </form>
</script>

<script type="text/javascript">
    var layer;
    var laytpl;
    var form;
    var table;
    var laydate;
    var dropdown;

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

        $("#userId").bind("input propertychange", function (event) {
            if ($("#userId").val() == null || $("#userId").val() == "") {
                $("#sameIp").attr("disabled", true);
                $("#sameIp").removeAttr("checked");
                $("#sameIp").prop({checked: false});
            } else {
                $("#sameIp").attr("disabled", false);
            }

            form.render();
        });

        //执行一个 table 实例
        table.render({
            elem: '#userAppList'
            , id: 'userAppList'
            , url: ctx + '/promoter/queryUserAppByPage' //数据接口
            , autoSort: false
            , where: form.val("formCondition")
            , response: {
                statusCode: 200
            }
            , parseData: function (res) { //res 即为原始返回的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.message, //解析提示文本
                    "count": res.count, //解析数据长度
                    "data": res.userAppList //解析数据列表
                };
            }
            , request: {
                pageName: 'currPage' //页码的参数名称，默认：page
                , limitName: 'size' //每页数据量的参数名，默认：limit
            }
            , even: true
            , title: '推广员列表'
            , page: true //开启分页
            , toolbar: '#toolBar' //开启工具栏，此处显示默认图标，可以自定义模板，详见文档
            , defaultToolbar: ['filter']
            , cols: [[ //表头
                {type: 'checkbox', minWidth: 40, rowspan: 2}
                , {title: '用户基本信息', width: 105, align: "left", rowspan: 2, templet: '#userBaseInfo'}
                , {field: 'levelName', title: '等级', width: 60, align: "left", rowspan: 2}
                , {field: 'inviteNum', title: '推广码', width: 80, align: "left", rowspan: 2, templet: '#spreadInfo'}
                , {
                    field: 'userType',
                    title: '用户类型',
                    minWidth: 83,
                    align: "left",
                    templet: '#extensionUserType',
                    rowspan: 2
                }
                , {
                    field: 'roleCode',
                    title: '用户标签',
                    minWidth: 83,
                    rowspan: 2,
                    templet: function (d) {
                        if (d.roleCode == "ZY_BST") {
                            return '<span style="color: red">倍斯特</span>';
                        } else {
                            return '<span>-</span>';
                        }
                    }
                }
                , {
                    field: 'status',
                    title: '实名状态',
                    align: "left",
                    minWidth: 83,
                    templet: '#extensionStatus',
                    rowspan: 2
                }
                , {title: "上级", align: "center", colspan: 2}
                , {title: '商户基本信息', minWidth: 158, align: 'center', templet: '#merchantBaseInfo', rowspan: 2}
                , {
                    title: '进件审核状态',
                    align: "center",
                    minWidth: 160,
                    templet: '#extensionThirdStatus',
                    rowspan: 1,
                    colspan: 3
                }
                , {
                    title: 'D1微信子商户号<hr/>支付宝子商户号',
                    align: "center",
                    minWidth: 130,
                    field: "wxMercNoD1",
                    rowspan: 2,
                    templet: '<div>{{d.wxMercNoD1}}<hr/>{{zfbMercNoD1}}</div'
                }
                , {
                    title: 'D0微信子商户号<hr/>支付宝子商户号',
                    align: "center",
                    minWidth: 130,
                    field: "wxMercNoD0",
                    rowspan: 2,
                    templet: '<div>{{d.wxMercNoD0}}<hr/>{{zfbMercNoD0}}</div'
                }

                // , {
                //     field: 'channel',
                //     title: '通道',
                //     align: "center",
                //     minWidth: 80
                //     , templet: function (r) {
                //         if (r.channel == 1) {
                //             return '随行付'
                //         } else if (r.channel == 2) {
                //             return '乐刷'
                //         } else if (r.channel == 3) {
                //             return '瑞银信'
                //         } else if (r.channel == 3) {
                //             return '瑞银信'
                //         }
                //     }
                //     , rowspan: 1
                // }
                , {
                    field: 'createDt',
                    title: '创建时间',
                    align: "left",
                    minWidth: 158,
                    rowspan: 2,
                    templet: '<div>{{layui.util.toDateString(d.createDt,"yyyy-MM-dd HH:mm")}}</div'
                }
                , {fixed: 'right', title: '操作', align: "left", minWidth: 100, rowspan: 2, toolbar: '#lineBar2'}
                , {fixed: 'right', title: '操作', minWidth: 80, align: 'center', toolbar: '#lineBar', rowspan: 2}
                , {
                    field: 'merchantCode',
                    fixed: 'right',
                    title: 'M800商编',
                    minWidth: 180,
                    align: 'center',
                    rowspan: 2,
                    hide: true
                }
            ],
                [
                    {
                        title: '上级信息', align: "left", width: 105, rowspan: 1, templet: '#parentInfo'
                        , style: "padding: 0;"
                    }
                    , {
                    field: 'parentUserType',
                    title: '类型',
                    width: 65,
                    templet: '#extensionParentUserType',
                    align: "left"
                    , rowspan: 1
                }
                    ,
                    {
                        field: 'mcsStatus',
                        title: '随行付',
                        align: "left",
                        width: 150,
                        rowspan: 1,
                        templet: function (r) {
                            return thirdStatus(r.channelStatusList, r.ppStatus, r.ppThirdStatus, 1);
                        }
                    }
                    , {
                    field: 'mcs3Status',
                    title: '瑞银信',
                    align: "left",
                    width: 150,
                    rowspan: 1,
                    templet: function (r) {
                        return thirdStatus(r.channelStatusList, r.ppStatus, r.ppThirdStatus, 3);
                    }
                }
                    , {
                    field: 'mcs4Status',
                    title: '银盛',
                    align: "left",
                    width: 190,
                    rowspan: 1,
                    templet: function (r) {
                        return thirdStatus(r.channelStatusList, r.ppStatus, r.ppThirdStatus, 4);
                    }
                }
                ]
            ],
            done: function (index, layero) {
                //表头部分
                //动态监听表头高度变化，冻结行跟着改变高度
                $(".layui-table-header  tr").resize(function () {
                    $(".layui-table-header  tr").each(function (index, val) {
                        $($(".layui-table-fixed .layui-table-header table tr")[index]).height(val.getBoundingClientRect().height);
                    });
                });
                //初始化高度，使得冻结行表头高度一致
                $(".layui-table-header  tr").each(function (index, val) {
                    let initElement = $(".layui-table-fixed .layui-table-header table tr")[index]
                    if (initElement != null) {
                        $(initElement).height(val.getBoundingClientRect().height);
                        $(initElement).find("th").removeAttr("style");
                    }
                });

                //表体部分
                //动态监听表体高度变化，冻结行跟着改变高度
                $(".layui-table-body  tr").resize(function () {
                    $(".layui-table-body  tr").each(function (index, val) {
                        $($(".layui-table-fixed .layui-table-body table tr")[index]).height(val.getBoundingClientRect().height);
                    });
                });
                //初始化高度，使得冻结行表体高度一致
                $(".layui-table-body  tr").each(function (index, val) {
                    $($(".layui-table-fixed .layui-table-body table tr")[index]).height(val.getBoundingClientRect().height);
                });
            }

        });

        table.on('toolbar(userAppList)', function (obj) {
            switch (obj.event) {
                case 'search':
                    queryUserApp();
                    break;
                case 'batch2Blacklist':
                    let checkStatus = table.checkStatus('userAppList');
                    let data = checkStatus.data;
                    if (data.length === 0) {
                        layer.msg("至少选择一行数据");
                        return;
                    }

                    let userIdList = [];
                    let url = ctx + "/riskBlacklist/batchForm?";
                    data.forEach(function (d) {
                        userIdList.push(d.userId);
                        url += "userId=" + d.userId + "&";
                    })

                    layer.open({
                        type: 2,
                        title: '加入黑名单',
                        shadeClose: true,
                        shade: false,
                        maxmin: true, //开启最大化最小化按钮
                        area: ['400px', '400px'],
                        content: url
                    });

                    break;
            }
        });

        function verifyFaceCert(userId) {
            layer.confirm('是否核实用户信息，并确认人脸核验通过?', {icon: 3, title: '提示'}, function (index) {
                $.ajax({
                    url: ctx + "/userInfo/verifyFaceCert"
                    , type: 'POST'
                    , data: {
                        userId: userId
                    }
                    , success: function (d) {
                        layer.alert(d.message);

                        if (d.code === 200) {
                            layer.close(index);
                        }
                    }
                })
            })
        }

        //监听行工具事件
        table.on('tool(userAppList)', function (obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            var data = obj.data //获得当前行数据
                , that = this
                , layEvent = obj.event; //获得 lay-event 对应的值

            switch (layEvent) {
                case 'detail2':
                    showUserAppDetails2(obj.data);
                    break;
                case 'level':
                    goLevel(data.id, data.level);
                    break;
                case 'examine':
                    toExamine(data.id);
                    break;
                case 'clearChannel':
                    showClearChannelTip(obj.data);
                    break;
                case 'allowAudit':
                    showAllowAuditTip(obj.data);
                    break;
                case 'toBlacklist':
                    toBlacklist(data.userId);
                    break;
                case 'sendSignMsg':
                    sendSignMsg(data.merchantCode);
                    break;
                case 'openD0':
                    openD0(data.merchantCode);
                    break;
                case 'banSpread':
                    banSpread(data.userId);
                    break;
                case 'openSpread':
                    openSpread(data.userId);
                    break;
                case 'createAuditingData':
                    createAuditingData(data.merchantCode);
                    break;
                case 'outBlack':
                    debugger;
                    outBlack(data);
                    break;
                case 'sendNotice':
                    sendNotice(data)
                    break;
                case 'more':
                    let itemData = [{
                        title: '重进/进件银盛'
                        , id: 'reAuditYs'
                    }, {
                        title: '实名审核'
                        , id: 'examine'
                    }, {
                        title: '通道数据清理'
                        , id: 'clearChannel'
                    }, {
                        title: '允许进件'
                        , id: 'allowAudit'
                    }, {
                        title: '人脸识别通过'
                        , id: 'verifyFaceCert'
                    },{
                        title: '生成待审核数据'
                        , id: 'createAuditingData'
                    }];
                    if (data.status == '3') {
                        itemData.push({
                            title: '升级'
                            , id: 'level'
                        });
                    }

                    if (data.isBlack === true) {
                        itemData.push({
                            title: '解除拉黑'
                            , id: 'outBlack'
                        });
                    }

                    dropdown.render({
                        elem: that
                        , show: true //外部事件触发即显示
                        , data: itemData
                        , className: 'site-dropdown-demo'
                        , click: function (mData, othis) {
                            switch (mData.id) {
                                case 'level':
                                    goLevel(data.id, data.level);
                                    break;
                                case 'examine':
                                    toExamine(data.id);
                                    break;
                                case 'clearChannel':
                                    showClearChannelTip(obj.data);
                                    break;
                                case 'allowAudit':
                                    showAllowAuditTip(obj.data);
                                    break;
                                case 'reAuditYs':
                                    reAuditYs(obj.data);
                                    break;
                                case 'outBlack':
                                    outBlack(obj.data);
                                    break;
                                case 'createAuditingData':
                                    createAuditingData(data.merchantCode);
                                    break;
                                case 'closeSpreadPerm':
                                    closeSpreadPerm(data.userId);
                                    break;
                                case 'verifyFaceCert':
                                    verifyFaceCert(data.userId);
                                    break;
                            }
                        }
                        , align: 'right' //右对齐弹出（v2.6.8 新增）
                        , style: 'box-shadow: 1px 1px 10px rgb(0 0 0 / 12%);' //设置额外样式
                    });
                    break;
            }
        });
    });

    function sendNotice(obj) {
        var url = ctx + '/notice/detail?userId=' + obj.userId;
        var index = layer.open({
            type: 2
            , title: "通知详情"
            , shade: 0.5
            , maxmin: true
            , content: url
            , area: ['753px', '700px']
            , end: function () {
                time: 1000
            }
        });
    }

    function closeSpreadPerm(userId) {
        layer.confirm('是否关闭' + userId + '推广权限?', {icon: 3, title: '提示'}, function (index) {
            var url = ctx + "/userApp/closeSpreadPerm";

            layer.load(2);
            $.ajax({
                url: url
                , type: "POST"
                , data: {
                    userId: userId
                }
                , complete: function () {
                    layer.closeAll('loading');
                }
                , success: function (d) {
                    layer.close(index);
                    layer.alert(d.message);
                }
            })
        });
    }

    function createAuditingData(merchantCode) {
        layer.confirm('是否生成进件审核信息?', {icon: 3, title: '提示'}, function (index) {
            var url = ctx + "/channelStatus/createNewAuditData";

            layer.load(2);
            $.ajax({
                url: url
                , type: "POST"
                , data: {
                    merchantCode: merchantCode
                }
                , complete: function () {
                    layer.closeAll('loading');
                }
                , success: function (d) {
                    layer.close(index);
                    layer.alert(d.message);
                }
            })
        });
    }

    function reAuditYs(data) {
        layer.confirm('是否(重新)进件银盛?', {icon: 3, title: '提示'}, function (index) {
            var url = ctx + "/merchantStore/reAuditYs/" + data.merchantCode;

            layer.load(2);
            $.ajax({
                url: url
                , type: "POST"
                , complete: function () {
                    layer.closeAll('loading');
                }
                , success: function (d) {
                    layer.close(index);
                    layer.alert(d.msg);
                }
            })
        });
    }

    function showAllowAuditTip(data) {
        layer.confirm('是否允许提交进件?', {icon: 3, title: '提示'}, function (index) {
            var url = ctx + "/merchantStore/canAudit";

            $.ajax({
                url: url,
                type: "POST",
                data: {
                    userId: data.userId
                },
                success: function (d) {
                    layer.alert(d.msg);
                }
            })

            layer.close(index);
        });
    }

    function showClearChannelTip(data) {
        layer.confirm('是否清理进件驳回、待审核数据的通道信息?', {icon: 3, title: '提示'}, function (index) {
            var url = ctx + "/channelStatus/clearRejectedChannel";

            $.ajax({
                url: url,
                type: "POST",
                data: {
                    merchantCode: data.merchantCode
                },
                success: function (d) {
                    layer.alert(d.message);
                }
            });

            layer.close(index);
        });
    }

    function showUserAppDetails(obj) {
        var url = ctx + "/promoter/queryUserAppBaseInfo/" + obj.userId;
        var index = layer.open({
            type: 2
            , title: "详情"
            , shade: 0.5
            , maxmin: true
            , content: url
            , area: ['100%', '95%']
            , resize: true
        });
        layer.full(index);
    }

    function showUserAppDetails2(obj) {
        var url = ctx + "/promoter/detail/" + obj.userId;
        parent.layui.index.openTabsPage(url, obj.userId + "-详情")

        // var index = layer.open({
        //     type: 2
        //     , title: "详情"
        //     , shade: 0.5
        //     , maxmin: true
        //     , content: url
        //     , area: ['100%', '95%']
        // });
        // layer.full(index);
        //
        // window.onresize = function () {
        //     layer.style(index, {
        //         width: '100%'
        //         , height: '95%'
        //     })
        //     layer.full(index);
        // }
    }

    //查询
    function queryUserApp() {
        console.log($("#userId").val())
        table.reload('userAppList', {
            page: {
                curr: 1
            }
            , where: form.val("formCondition")
        });
    }

    function thirdStatus(channelStatusList, ppStatus, ppThirdStatus, channel) {

        // 结果信息
        let result = '<div class="layui-col-md12">';
        let flag = false;
        let undefinedChannel;

        /**
         * forEach无法通过return中断
         */
        for (let i = 0; i < channelStatusList.length; i++) {
            let item = channelStatusList[i];

            if (item.channel == null) {
                undefinedChannel = item;
            }

            if (item.channel == channel) {
                flag = true;
                // 只操作指定的通道信息
                if ((item.status == "0" && item.thirdStatus == "-100") || item.status == "2") {
                    result += '<span style="color: #FF5722;">审核驳回</span>';
                }

                if (item.status == '1' && item.thirdStatus == '-100') {
                    result += '<span style="color: blue">待审核</span>';
                }

                if (item.status == "1" && item.thirdStatus != "-100") {
                    if (channel == '3' && item.thirdStatus == '5') {
                        result += '<span style="color: green">待商户签约</span>';
                    } else {
                        if (item.thirdStatus == '-999') {
                            result += '<span style="color: green">后台进件中...</span>';
                        } else {
                            result += '<span style="color: green">审核中</span>';
                        }
                    }
                }

                if (item.status == "3") {
                    result += '<span style="color: green">审核通过</span>'
                }

                if (item.status == "6") {
                    result += '<span style="color: green">结算信息变更中</span>'
                }

                if (item.status == '8') {
                    result += '<span style="color: green">待商户签约</span>'
                }

                if (item.status == '9') {
                    result += '<span style="color: green">已签约, 待复审</span>'
                }

                if (item.status == "7") {
                    result += '<span style="color: green">快付审核中</span>'
                }

                if ((item.status == "3" || item.status == "6") && channel == '3') {
                    // 瑞银信，需要判断插件
                    if (ppStatus == "1" && ppThirdStatus == "-100") {
                        result += ' <span style="color: blue">插件待审核</span>';
                    } else if (ppStatus == "1" && ppThirdStatus != "-100") {
                        result += ' <span style="color: green">插件审核中</span>';
                    } else if ((ppStatus == "0" && ppThirdStatus == "-100") || ppStatus == "2") {
                        result += ' <span style="color: red">插件审核驳回</span>';
                    } else if (ppStatus == "3") {
                        result += ' <span style="color: green">插件审核通过</span>';
                    } else if (ppStatus == "0" || ppStatus == '' || ppStatus == null) {
                        result += '';
                    } else {
                        result += ' <span style="color: #c2c2c2;">插件未知状态</span>';
                    }
                }

                if (item.status == '8' && channel == '4') {
                    result += '<a class="layui-btn layui-btn-normal layui-btn-xs" style="float:right;" lay-event="sendSignMsg">' +
                        '<i class="layui-icon layui-icon-release"></i>签约短信' +
                        '</a>';
                }

                if (item.status == '3' && channel == '4') {
                    result += '<a class="layui-btn layui-btn-normal layui-btn-xs" style="float:right;" lay-event="openD0">' +
                        '<i class="layui-icon layui-icon-release"></i>开通DO' +
                        '</a>';
                }

                if (item.merchantId != null && item.merchantId != '') {
                    result += '</div><hr/>';
                    result += '<div class="layui-col-md12">';
                    result += item.merchantId;
                }

                result += '</div><hr/>';
                result += '<div class="layui-col-md12">';
                result += layui.util.toDateString(item.updateTime, 'yyyy-MM-dd HH:mm:ss');
            }
        }

        if (undefinedChannel != null && !flag) {
            if (undefinedChannel.status == '1' && undefinedChannel.thirdStatus == '-100') {
                result += '<span style="color: blue">待审核</span>';
                result += '</div><hr/>';
                result += '<div class="layui-col-md12">';
                result += layui.util.toDateString(undefinedChannel.updateTime, 'yyyy-MM-dd HH:mm:ss');
            }

            if (undefinedChannel.status == '0' && undefinedChannel.thirdStatus == '-100' || undefinedChannel.status == '2') {
                result += '<span style="color: blue">审核驳回</span>';
                result += '</div><hr/>';
                result += '<div class="layui-col-md12">';
                result += layui.util.toDateString(undefinedChannel.updateTime, 'yyyy-MM-dd HH:mm:ss');
            }

        } else if (!flag) {
            if (channel == '3' && ppStatus != null && ppStatus != '') {
                // 瑞银信，需要判断插件
                if (ppStatus == "1" && ppThirdStatus == "-100") {
                    result += ' <span style="color: blue">插件待审核</span>';
                } else if (ppStatus == "1" && ppThirdStatus != "-100") {
                    result += ' <span style="color: green">插件审核中</span>';
                } else if ((ppStatus == "0" && ppThirdStatus == "-100") || ppStatus == "2") {
                    result += '<span style="color: red">插件审核驳回</span>';
                } else if (ppStatus == "3") {
                    result += ' <span style="color: green">插件审核通过</span>';
                } else if (ppStatus == "0" || ppStatus == '' || ppStatus == null) {
                    result += '';
                } else {
                    result += ' <span style="color: #c2c2c2;">插件未知状态</span>';
                }
            } else {
                result += '<span style="color: #c2c2c2">-</span>';
            }
        }

        // if (mscStatus == "1" && mscStatus != "-100") {
        //     return '<span style="color: green">审核中</span>';
        // }

        result += '</div>';
        return result;
    }

    function toBlacklist(userId) {
        layer.open({
            type: 2,
            title: '加入黑名单',
            shadeClose: true,
            shade: false,
            maxmin: true, //开启最大化最小化按钮
            area: ['400px', '400px'],
            content: ctx + "/riskBlacklist/simpleForm?userId=" + userId
        });
    }

    function outBlack(obj) {
        layer.confirm('是否解除黑名单?', {icon: 3, title: '提示'}, function (index) {
            $.ajax({
                url: ctx + "/riskBlacklist/relieve"
                , type: 'POST'
                , data: {
                    userId: obj.userId
                }
                , success: function (d) {
                    layer.alert(d.message);

                    if (d.code == 200) {
                        layer.close(index);
                    }
                }
            })
        })
    }

    function sendSignMsg(merchantCode) {
        layer.confirm('发送签约短信及通知', {icon: 3, title: '提示'}, function (index) {
            var url = ctx + "/channelStatus/sendSignMsg";

            $.ajax({
                url: url,
                type: "POST",
                data: {
                    merchantCode: merchantCode
                },
                success: function (d) {
                    layer.alert(d.message);
                    layer.close(index);
                }
            });


        });
    }

    function openD0(merchantCode) {
        layer.confirm('开通线上支付以及D0权限？', {icon: 3, title: '提示'}, function (index) {
            var url = ctx + "/channelStatus/openOnlinePay";

            $.ajax({
                url: url,
                type: "POST",
                data: {
                    merchantCode: merchantCode
                },
                success: function (d) {
                    layer.alert(d.message);
                }
            });

            layer.close(index);
        });
    }

    function banSpread(userId) {
        layer.confirm('是否关闭' + userId + '推广权限?', {icon: 3, title: '提示'}, function (index) {
            var url = ctx + "/userApp/closeSpreadPerm";

            layer.load(2);
            $.ajax({
                url: url
                , type: "POST"
                , data: {
                    userId: userId
                }
                , complete: function () {
                    layer.closeAll('loading');
                }
                , success: function (d) {
                    layer.close(index);
                    layer.alert(d.message);
                }
            })
        });
    }

    function openSpread(userId) {
        layer.confirm('是否打开' + userId + '推广权限?', {icon: 3, title: '提示'}, function (index) {
            var url = ctx + "/userApp/openSpreadPerm";

            layer.load(2);
            $.ajax({
                url: url
                , type: "POST"
                , data: {
                    userId: userId
                }
                , complete: function () {
                    layer.closeAll('loading');
                }
                , success: function (d) {
                    layer.close(index);
                    layer.alert(d.message);
                }
            })
        });
    }
</script>
</body>
</html>

