<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page contentType="text/html;charset=UTF-8" %>

<c:set var="ctx" value="${pageContext.request.contextPath}" scope="request"/>
<c:set var="resourcePath" value="${ctx}/resources" scope="request"/>

<c:forEach items="${channelStatusList}" var="channelStatus" varStatus="status">
    <div class="w1000" style="background: white">
        <fieldset class="w1000 fc layui-elem-field layui-field-title" style="margin-top: 20px;">
            <legend>通道进件组${status.index + 1}</legend>
        </fieldset>
    </div>

    <form class="layui-form mb100" action="">
        <input type="hidden" name="id" value="${channelStatus.channel}"/>
        <input type="hidden" name="userId" value="${userId}"/>
        <input type="hidden" name="merchantCode" value="${channelStatus.merchantCode}"/>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">审核备注组</label>
                <div class="layui-input-inline" style="width: 600px">
                    <select id="errMsg" lay-search lay-filter="changeAudit" data-dom="remark${status.index}"
                    <c:if test="${channelStatus.status ne '1' || channelStatus.thirdStatus ne '-100'}">
                            class="layui-disabled"
                    </c:if>
                    <option value=""></option>
                    <c:forEach items="${listMerchantRejectDesc}" var="mrd">
                        <option value="${mrd.rejectName}">${mrd.rejectName}</option>
                    </c:forEach>
                    </select>
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">审核备注</label>
                <div class="layui-input-inline" style="width: 600px">
                        <textarea name="errMsg" id="remark${status.index}"
                                <c:if test="${channelStatus.status ne '1' || channelStatus.thirdStatus ne '-100'}">
                                    disabled
                                </c:if>
                                  class="layui-textarea">${channelStatus.remark}</textarea>
                </div>
            </div>
        </div>

        <c:if test="${channelStatus.status eq '2' or (channelStatus.status eq '0' and channelStatus.thirdStatus eq '-100')}">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">驳回时间：</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input layui-font-black"
                               value="<fmt:formatDate value="${channelStatus.updateTime}" pattern="yyyy-MM-dd HH:mm:ss"/>" disabled />

                    </div>
                </div>
            </div>
        </c:if>

        <div class="layui-form-item">
            <label class="layui-form-label">通道选择</label>
            <div class="layui-input-block" style="margin-left: 110px">
                <c:forEach items="${channel}" var="channelItem">
                    <input type="radio" name="id" value="${channelItem.id}"
                           title="${channelItem.channelName}"
                            <c:if test="${channelStatus.channel ne null || channelStatus.status ne 1 || channelStatus.thirdStatus ne -100 || channelStatus.status eq 3}">
                                disabled
                            </c:if>
                            <c:if test="${channelStatus.channel eq channelItem.id}">
                                checked
                            </c:if>
                            <c:if test="${channelStatus.channel eq null and channelStatusList.size() le 1}">
                                <c:if test="${mbi.merchantType eq '1' and channelItem.id eq '3'}">
                                    checked
                                </c:if>
                                <c:if test="${mbi.merchantType ne '1' and channelItem.id eq '1'}">
                                    checked
                                </c:if>
                            </c:if>
                    />
                </c:forEach>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">审核状态</label>
                <div class="layui-input-inline">
                    <c:if test='${(channelStatus.status eq "0" && channelStatus.thirdStatus eq "-100") || channelStatus.status eq "2"}'>
                        <input type="text" class="layui-input layui-font-black" value="审核驳回" disabled/>
                    </c:if>
                    <c:if test='${(channelStatus.status eq "1" && channelStatus.thirdStatus eq "-100")}'>
                        <input type="text" class="layui-input layui-font-black" value="待后台审核" disabled/>
                    </c:if>
                    <c:if test='${channelStatus.status eq "3"}'>
                        <input type="text" class="layui-input layui-font-black" value="审核通过" disabled/>
                    </c:if>
                    <c:if test='${channelStatus.status eq "7"}'>
                        <input type="text" class="layui-input layui-font-black" value="快付审核中" disabled/>
                    </c:if>
                </div>
            </div>
        </div>

        <c:if test="${channelStatus.status eq '1' && channelStatus.thirdStatus eq '-100'}">
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <div class="layui-inline">
                        <button class="layui-btn" lay-submit lay-filter="consent">通过</button>
                    </div>

                    <div class="layui-inline">
                        <button class="layui-btn layui-btn-danger" lay-submit lay-filter="reject">驳回</button>
                    </div>

                    <div class="layui-inline">
                        <button class="layui-btn layui-btn-danger" lay-submit lay-filter="reject2">驳回并禁止进件</button>
                    </div>
                </div>
            </div>
        </c:if>

        <c:if test="${channelStatus.status eq '1' && channelStatus.status eq '-100'}">
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="consent">重审</button>
                </div>
            </div>
        </c:if>
    </form>

</c:forEach>

<c:if test="${ppStatus eq '1' && ppThirdStatus eq '-100' }">
    <fieldset class="w1000 fc layui-elem-field layui-field-title mt100">
        <legend>瑞银信插件进件</legend>
    </fieldset>
    <form class="layui-form" action="">
        <input type="hidden" name="userId" value="${userId}"/>
        <div class="w1000 fc" style="background: white">
            <div class=" pd10 textl pl50 pb20 fw800 f16 pb20 bdbe mb20 ch">插件审核</div>
            <div class="clearfix mb20">
                <div class="fl textc wp50">
                    <label class="layui-form-label">审核备注：</label>
                    <div class="layui-input-block" style="margin-left:0px">
                        <div class="layui-input-block">
                            <textarea name="errMsg" id="remark2" style="margin-top: -13px;width: 372px"
                                      class="bdc w320 pd7 radius5"></textarea>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="plugin">插件进件通过</button>
                    <button class="layui-btn layui-btn-danger" lay-submit lay-filter="pluginReject">驳回</button>
                </div>
            </div>
        </div>
    </form>
</c:if>

<script>
    $(function () {
        form.render();
    });

    /*提交通过备注信息*/
    form.on('submit(consent)', function (data) {
        layer.confirm('确认通过?', function (index) {
            var index = layer.load(1, {shade: [0.1, '#000']});
            $.ajax({
                url: ctx + '/merchantStore/manualMerchantIncom/' + data.field.userId + '/' + data.field.id + '/' + data.field.merchantCode,
                method: 'get',
                timeout: 0, // 此处将超时时间设为30秒
                data: data.field,
                dataType: 'JSON',
                success: function (res) {
                    layer.close(index);
                    if (res.code == 1) {
                        layer.alert(res.msg, function (index) {
                            layer.close(index);
                        })
                    } else {
                        layer.alert(res.msg, function (index) {
                            layer.close(index);
                        })
                    }
                },
                error: function () {
                    layer.close(index);
                    layer.alert("服务器错误", function (index) {
                        layer.close(index);
                    })
                }
            })
        });
        return false;
    });

    /*提交通过备注信息*/
    form.on('submit(plugin)', function (data) {
        layer.confirm('确认通过?', function (index) {
            var index = layer.load(1, {shade: [0.1, '#000']});
            $.ajax({
                url: '${ctx}/merchantStore/audit/' + data.field.userId,
                method: 'get',
                data: data.field,
                dataType: 'JSON',
                success: function (res) {
                    layer.close(index);
                    if (res.code == 200) {
                        layer.msg(res.msg, {
                            icon: 1
                        });
                    } else {
                        layer.msg(res.msg, {
                            icon: 5
                        });
                    }
                },
                error: function () {
                    layer.close(index);
                    layer.msg("服务器错误", {
                        icon: 5
                    });
                }
            })
        });
        return false;
    });

    /*提交驳回备注信息*/
    form.on('submit(reject)', function (data) {
        var index = layer.load(1, {shade: [0.1, '#000']});
        $.ajax({
            url: ctx + '/merchantStore/rejectAudit/' + data.field.userId,
            method: 'get',
            data: data.field,
            dataType: 'JSON',
            success: function (res) {
                layer.close(index);
                if (res.code == 1) {
                    layer.msg(res.msg, {
                        icon: 1
                    });
                } else {
                    layer.msg(res.msg, {
                        icon: 5
                    });
                }
            }
        })
        return false;
    });

    /*提交驳回备注信息*/
    form.on('submit(reject2)', function (data) {
        var index = layer.load(1, {shade: [0.1, '#000']});
        $.ajax({
            url: '${ctx}/merchantStore/rejectAudit2/' + data.field.userId,
            method: 'get',
            data: data.field,
            dataType: 'JSON',
            success: function (res) {
                layer.close(index);
                if (res.code == 1) {
                    layer.msg(res.msg, {
                        icon: 1
                    });
                } else {
                    layer.msg(res.msg, {
                        icon: 5
                    });
                }
            }
        })
        return false;
    });

    /*提交驳回备注信息*/
    form.on('submit(pluginReject)', function (data) {
        var index = layer.load(1, {shade: [0.1, '#000']});
        $.ajax({
            url: '${ctx}/merchantStore/rejectPluginAudit/' + data.field.userId,
            method: 'get',
            data: data.field,
            dataType: 'JSON',
            success: function (res) {
                layer.close(index);
                if (res.code == 1) {
                    layer.msg(res.msg, {
                        icon: 1
                    });
                } else {
                    layer.msg(res.msg, {
                        icon: 5
                    });
                }
            }
        })
        return false;
    });

    form.on('select(changeAudit)', function (obj) {
        let name = obj.value;
        let elem = obj.elem;
        let domId = $(elem).attr('data-dom');
        debugger
        let remark = $('#' + domId);
        remark.val(remark.val() + name + ';');
    })
</script>