<%--
  Created by IntelliJ IDEA.
  User: wuxuan
  Date: 2025/6/3
  Time: 10:34
  To change this template use File | Settings | File Templates.
--%>
<%@ page pageEncoding="UTF-8" %>
<%@ include file="../common/common.jsp" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<html>
<head>
    <title>Title</title>
    <style>
        .panel label {
            font-weight: bolder;
        }
    </style>
</head>
<body>
<div class="page_container">
    <div class="page_head">
        <h3>分级审核</h3>
        <div class="breadcrumb">
            <a href="#">首页</a> > <a href="#">账号管理</a> > 分级审核
        </div>
    </div>
    <div class="row">
        <div class="col-xs-12">
            <form action="${basepage}/levelAudit/spAudit.html" method="post">
                <div class="panel">
                    <div class="table_operate">
                        <div>
                            <div class="query_item">
                                <label>审核来源:
                                    <select id="auditSource" name="auditSource" class="form_control form_white">
                                        <option value="">请选择</option>
                                        <option
                                                <c:if test="${queryVO.auditSource eq 1}">selected</c:if> value="1">
                                            签名报备-公司信息审核
                                        </option>
                                        <option
                                                <c:if test="${queryVO.auditSource eq 2}">selected</c:if> value="2">
                                            签名报备-公司签名信息审核
                                        </option>
                                        <option
                                                <c:if test="${queryVO.auditSource eq 3}">selected</c:if> value="3">
                                            签名报备-报备信息审核
                                        </option>
                                        <option
                                                <c:if test="${queryVO.auditSource eq 4}">selected</c:if> value="4">
                                            下载中心导出审核
                                        </option>
                                    </select>
                                </label>
                            </div>
                            <button type="submit" class="btn btn_orange btn_icon">
                                <span class="ico_16px ico_search"></span><span>查询</span>
                            </button>
                        </div>
                    </div>
                    <div class="modal fade" id="ajax" role="basic" aria-hidden="true">
                        <div class="modal-dialog">
                            <div class="modal-content">
                            </div>
                        </div>
                    </div>

                    <div class="table_wrap">
                        <table class="datatable">
                            <thead>
                            <tr>
                                <th>待审核主体</th>
                                <th>审核来源</th>
                                <th>提审时间</th>
                                <th>扩展信息</th>
                                <th class="align_c">操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <c:choose>
                                <c:when test="${not empty auditList}">
                                    <c:forEach items="${auditList}" var="item" varStatus="vs">
                                        <tr>
                                            <td>${item.spId} ${item.spName}</td>
                                            <td>
                                                <c:choose>
                                                    <c:when test="${item.auditSource == 1}">签名报备-公司信息审核</c:when>
                                                    <c:when test="${item.auditSource == 2}">签名报备-公司签名信息审核</c:when>
                                                    <c:when test="${item.auditSource == 3}">签名报备-报备信息审核</c:when>
                                                    <c:when test="${item.auditSource == 4}">下载中心导出审核</c:when>
                                                    <c:otherwise>未知</c:otherwise>
                                                </c:choose>
                                            </td>
                                            <td>${item.createTime}</td>
                                            <td>${item.extendMessage}</td>
                                            <td class="align_c">
                                                <a class="btn btn_small btn_navy"
                                                   href="${basepage}/levelAudit/showAuditDetail.html?id=${item.id}&auditSource=${item.auditSource}"
                                                   data-target="#ajax" data-toggle="modal">数据源详情</a>
                                                <button type="button" class="btn btn_blue btn_small"
                                                        onclick="auditPass('${item.id}', '${item.auditSource}')">通过
                                                </button>
                                                <button type="button" class="btn btn_red btn_small"
                                                        onclick="auditReject('${item.id}', '${item.auditSource}')">驳回
                                                </button>
                                            </td>
                                        </tr>
                                    </c:forEach>
                                </c:when>
                            </c:choose>
                            </tbody>
                            <tfoot>
                            <tr>
                                <td>
                                    ${queryVO.page.pageStr}
                                </td>
                            </tr>
                            </tfoot>
                        </table>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
</body>
<script>
    $(function () {
        $("#ajax").on("hidden.bs.modal", function () {
            $(this).removeData("bs.modal");
        });
    })

    function auditPass(auditId, auditSourceType) {
        Dialog.confirm('是否确认审核通过?', () => {
            $.ajax({
                url: '${basepage}/levelAudit/spAuditPass.html',
                type: 'POST',
                data: {
                    id: auditId,
                    auditSourceType: auditSourceType
                },
                success: function (res) {
                    if (res.code === 0) {
                        Dialog.alertSucc(res.msg)
                        setTimeout(() => {
                            window.location.reload()
                        }, 1500)
                    } else {
                        Dialog.alertError(res.msg);
                    }
                },
                error: function () {
                    Dialog.alertError('网络异常，请稍后重试');
                }
            })
        })
    }

    function auditReject(auditId, auditSourceType) {
        Dialog.ajaxOpen('${basepage}/levelAudit/spAuditRejectView.html', '分级审核驳回', () => {
            const reason = $('#reason').val();
            if (!reason) {
                Dialog.alertError('请输入驳回原因')
                return
            }
            $.ajax({
                url: '${basepage}/levelAudit/spAuditReject.html',
                type: 'POST',
                data: {
                    id: auditId,
                    rejectReason: reason,
                    auditSource: auditSourceType
                },
                success: function (res) {
                    if (res.code === 0) {
                        Dialog.alertSucc(res.msg)
                        setTimeout(() => {
                            window.location.reload()
                        }, 1500)
                    } else {
                        Dialog.alertError(res.msg);
                    }
                },
                error: function () {
                    Dialog.alertError('网络异常，请稍后重试');
                }
            })
        })
    }
</script>
</html>
