<!DOCTYPE html>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html lang="zh">
<head>
    <meta charset="utf-8">
    <meta name="referrer" content="no-referrer">
    <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"/>
    <jsp:include page="base.jsp"/>
    <script type="text/javascript">
        require("promoter/userAppList.js");
    </script>
    <style>
        .layui-input, .layui-textarea {
            border-radius: 6px;
            height: 34px;
        }

        .u-icon {
            display: inline-block;
            margin: 10px;
            background: #fff;
            color: dodgerblue;
            width: 30px;
            height: 30px;
            text-align: center;
            border-radius: 50%;
            margin-top: -40px;
            cursor: pointer;
        }

        .u-icon i {
            margin-top: 7px;
            display: block;
        }

        .cover {
            display: none;
        }

        .dlblock:hover .cover {
            display: block;
        }

        layui-tab-title li {
            display: block !important;
        }

        @media screen and (min-width: 768px) {
            .layui-col-auto {
                width: auto;
            }
        }

        ul li {
            text-align: center;
        }

        .layui-form-label {
            width: 84px !important;
            padding: 9px 10px;
        }
    </style>
</head>
<body style="float: left; width: 100%; padding: 0 5px; box-sizing: border-box;">
<div class="layui-col-md8">
    <div class="layui-tab layui-tab-brief" lay-filter="tabBrief">
        <ul class="layui-tab-title">
            <li id="titleAudit" lay-id="auditData" class="layui-this">实名认证信息</li>
            <li id="titleMerchBaseInfo" lay-id="merchBaseData">商户基本信息</li>
            <li id="titleMerchLicense" lay-id="merchLicenseData">营业执照信息</li>
            <li id="titleSettlement" lay-id="settlementData">结算信息</li>
            <li id="titleMerchAudit" lay-id="merchAuditData">通道进件信息</li>
        </ul>
        <div class="layui-tab-content">
            <div id="tabAudit" class="layui-tab-item layui-show">实名认证信息</div>
            <div id="tabMerchBaseInfo" class="layui-tab-item">商户基本信息</div>
            <div id="tabMerchLicense" class="layui-tab-item">营业执照内容</div>
            <div id="tabSettlement" class="layui-tab-item">结算信息</div>
            <div id="tabMerchAudit" class="layui-tab-item">通道进件信息</div>
        </div>
    </div>
</div>

<div class="layui-col-md4 layui-col-xs12 layui-col-sm12" style="overflow-y: scroll; background: #ffffff;">
    <div id="connectContent"></div>
</div>

<script>
    $(document).ready(function () {
        $('iframe').height($('body')[0].clientHeight);


        $(window.frameElement).load(function() {
            adjustWidthHeight();
        })
    });

    function adjustWidthHeight() {
        var height = $(window).height();
        console.log("iframe height: " + height);
        $('.layui-layer-iframe1').height($('.layui-layer-iframe1').body.scroll);
    }

    let userId = "${userId}";

    let layer;

    let element;

    let form;

    layui.use(['element', 'layer', 'upload', 'form'], function () {
        layer = layui.layer;
        element = layui.element; //Tab的切换功能，切换事件监听等，需要依赖element模块
        form = layui.form;
        onStart();

        element.on('tab(tabBrief)', function (data) {
        });

        $('#connectContent').load(ctx + '/promoter/connectInfo?userId=' + userId);
    });

    function promoterInit() {
        $("#titleMerchBaseInfo").remove();
        $("#tabMerchBaseInfo").remove();
        $("#titleMerchLicense").remove();
        $("#tabMerchLicense").remove();
        $("#titleSettlement").remove();
        $("#tabSettlement").remove();
        $("#titleMerchAudit").remove();
        $("#tabMerchAudit").remove();

        // 填充商户认证信息页面
        auditInfoInit();
    }

    function microMerchInit() {
        $("#titleMerchLicense").remove();
        $("#tabMerchLicense").remove();

        auditInfoInit();
        merchBaseInfoInit();
        settlementInfoInit();
        channelAuditInfoInit();
    }

    function licenseMerchInit() {
        auditInfoInit()
        merchBaseInfoInit();
        merchLicenseInfoInit();
        settlementInfoInit();
        channelAuditInfoInit();
    }

    function auditInfoInit() {
        $("#tabAudit").load(ctx + "/promoter/detail/audit/" + userId);
    }

    function merchBaseInfoInit() {
        $("#tabMerchBaseInfo").load(ctx + "/promoter/detail/merchBaseInfo/" + userId);
    }

    function merchLicenseInfoInit() {
        $("#tabMerchLicense").load(ctx + "/promoter/detail/merchLicense/" + userId);
    }

    function settlementInfoInit() {
        $("#tabSettlement").load(ctx + "/promoter/detail/settlementV2/" + userId)
    }

    function channelAuditInfoInit() {
        $("#tabMerchAudit").load(ctx + "/promoter/detail/channelAuditInfo/" + userId)
    }

    function onStart() {
        $.ajax({
            url: ctx + "/merchantBaseInfo/" + userId
            , type: 'GET'
            , async: true
            , success: function (d) {
                if (d.code == 200) {
                    if (d.data == null) {
                        merchLicenseLoading = 1;
                        merchBaseInfoLoading = 1;
                        settlementLoading = 1;
                        promoterInit();
                        return;
                    }

                    if (d.data.merchantType == 1) {
                        merchLicenseLoading = 1;
                        microMerchInit()
                        return;
                    }

                    licenseMerchInit();
                } else {
                    layer.confirm(d.message, {icon: 3, title: '提示'}, function (index) {
                        layer.close(index)
                    });
                }
            }
        });
    }
</script>
</body>
</html>