<%--
  Created by IntelliJ IDEA.
  User: wuxuan
  Date: 2024/4/9
  Time: 16:08
  To change this template use File | Settings | File Templates.
--%>
<%@ page pageEncoding="UTF-8" language="java" %>
<%@ 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" %>
<%@ include file="../common/common.jsp" %>
<c:set var="basePage"><%=request.getContextPath() %>
</c:set>
<html>
<head>
    <title>非直签客户列表</title>
    <link rel="stylesheet" type="text/css" href="${basePage}/web/chatbot/static/css/noSignCustomerList.css">
</head>
<body>
<div class="page_container" id="app" style="overflow: auto">
    <div class="page_head">
        <h3>CSP非直签客户列表</h3>
        <div class="breadcrumb">
            <a href="#">首页</a> > <a href="#">CSP业务</a> > CSP非直签客户列表
        </div>
    </div>
    <div class="container-fluid bg-body-tertiary config-content">
        <div class="row row-panel form-panel">
            <form id="form" method="post" action="${basePage}/chatbot/noSignCustomerList.html">
                <div class="col-lg-2">
                    <label class="form-label"> 接口类型:
                        <select id="apiType" class="form_control form_white singleSelect" name="apiType">
                            <option value="">请选择</option>
                            <option value="mobile5G" <c:if test="${cspNoSignCustomer.apiType == 'mobile5G'}">selected</c:if>>移动5G</option>
                            <option value="telecom5G" <c:if test="${cspNoSignCustomer.apiType == 'telecom5G'}">selected</c:if>>电信5G</option>
                            <option value="unicom5G" <c:if test="${cspNoSignCustomer.apiType == 'unicom5G'}">selected</c:if>>联通5G</option>
                        </select>
                    </label>
                </div>
                <div class="col-lg-2">
                    <label class="form-label"> 代理商:
                        <select class="form_control form_white singleSelect" name="agentId">
                            <option value="">请选择</option>
                            <c:forEach items="${agentList}" var="item">
                                <option
                                        <c:if test="${cspNoSignCustomer.agentId == item.id}">selected </c:if>
                                        value="${item.id}">${item.agentName}</option>
                            </c:forEach>
                        </select>
                    </label>
                </div>
                <%--                <div class="col-lg-2">--%>
                <%--                    <label class="form-label"> 客户编码: </label>--%>
                <%--                    <input type="text" class="form_control form_white" placeholder="请输入客户编码"--%>
                <%--                           aria-label="请输入客户编码" value="${cspNoSignCustomer.contractCode}">--%>
                <%--                </div>--%>
                <div class="col-lg-2">
                    <label class="form-label"> 客户名称: </label>
                    <input type="text" class="form_control form_white" placeholder="请输入客户名称" name="name"
                           aria-label="请输入客户名称" value="${cspNoSignCustomer.name}">
                </div>
                <div class="col-lg-2">
                    <label class="form-label"> 状态:
                        <select id="cspStatus" class="form_control form_white singleSelect" name="status">
                            <option value="">请选择</option>
                            <c:forEach items="${statusList}" var="item">
                                <option
                                        <c:if test="${cspNoSignCustomer.status == item.value}">selected </c:if>
                                        value="${item.key}">${item.value}</option>
                            </c:forEach>
                        </select>
                    </label>
                </div>

                <div class="modal fade" id="groupajax" role="basic" aria-hidden="true">
                    <div class="modal-dialog">
                        <div class="modal-content">
                        </div>
                    </div>
                </div>
                <div class="col-lg-2">
                    <div class="my-btn-group">
                        <button onclick="doQuery()" type="button" class="btn btn_blue">查询</button>
                        <a href="${basePage}/chatbot/noSignCustomerConfigInfo.html"
                           class="btn btn_green">创建非直签客户</a>
                        <a class=" btn btn_navy" href="${basePage}/chatbot/jumpToImportNoSignCustomerPage.html" data-target="#groupajax"
                           data-toggle="modal">导入</a>
                    </div>
                </div>
            </form>
        </div>

        <div class="row row-panel">
            <div class="col-12">
                <div class="my-table-container page_container">
                    <table class="table table-hover datatable" style="width: 100%;table-layout: fixed">
                        <thead>
                        <tr>
                            <th style="width: 15%">代理商名字</th>
                            <th style="width: 15%">客户名称</th>
                            <th style="width: 15%">运营商</th>
                            <th style="width: 15%">客户编码</th>
                            <th style="width: 15%">备注</th>
                            <th style="width: 10%">创建时间</th>
                            <th style="width: 10%">状态</th>
                            <th style="width: 20%">操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <c:choose>
                        <c:when test="${empty noSignCustomerList}">
                            <tr>
                                <td colspan="7" class="text-center">暂无数据</td>
                            </tr>
                        </c:when>
                        <c:otherwise>
                        <c:forEach items="${noSignCustomerList}" var="item">
                            <tr>
                                <td>
                                    <div class="col-over-hide">
                                            ${item.agentName}
                                    </div>
                                </td>
                                <td>
                                    <div class="col-over-hide">
                                            ${item.name}
                                    </div>
                                </td>
                                <td>
                                    <div class="col-over-hide">
                                        <c:choose>
                                            <c:when test="${empty item.apiType || item.apiType == 'mobile5G'}">
                                                移动
                                            </c:when>
                                            <c:when test="${item.apiType == 'telecom5G'}">
                                                电信
                                            </c:when>
                                            <c:when test="${item.apiType == 'unicom5G'}">
                                                联通
                                            </c:when>
                                            <c:otherwise>
                                                未知
                                            </c:otherwise>
                                        </c:choose>
                                    </div>
                                </td>
                                <td>
                                    <div class="col-over-hide">
                                        <c:choose>
                                            <c:when test="${not empty item.apiType and item.apiType != 'mobile5G'}">
                                                ${item.cspEcNo}
                                            </c:when>
                                            <c:otherwise>
                                                ${item.customerNum}
                                            </c:otherwise>
                                        </c:choose>
                                    </div>
                                </td>
                                <td>
                                    <div class="col-over-hide">
                                            ${item.remark}
                                    </div>
                                </td>
                                <td title="${item.createTime}">
                                    <div class="col-over-hide">
                                            ${item.createTime}
                                    </div>
                                </td>
                                <td>
                                    <c:choose>
                                        <c:when test="${item.status == null}">
                                            未知
                                        </c:when>
                                        <c:otherwise>
                                            ${statusList.getOrDefault(item.status, '未知')}
                                        </c:otherwise>
                                    </c:choose>
                                </td>
                                <td>
                                    <c:if test="${empty item.apiType || item.apiType == 'mobile5G'}">
                                        <button onclick="assignServiceCode('${item.id}')" type="button"
                                                class="btn btn_small-sm btn_blue">服务代码
                                        </button>
                                    </c:if>
                                    <a type="button" class="btn btn_small btn_blue"
                                       href="${basePage}/chatbot/noSignCustomerConfigInfo.html?id=${item.id}">编辑</a>
                                        <%--                                    <button type="button" class="btn btn_small-sm btn_green"--%>
                                        <%--                                            onclick="doCopyCustomer('${item.id}')">复制--%>
                                        <%--                                    </button>--%>
                                    <c:choose>
                                        <c:when test="${empty item.apiType || item.apiType == 'mobile5G'}">
                                            <button type="button" class="btn btn_small btn_red"
                                                    onclick="doDeleteCustomer('${item.id}')">
                                                删除
                                            </button>
                                        </c:when>
                                        <c:otherwise>
                                            <c:choose>
                                                <c:when test="${item.status == 60}">
                                                    <!-- 状态=60 → 只显示删除按钮 -->
                                                    <button type="button" class="btn btn_small btn_red"
                                                            onclick="doDeleteCustomer('${item.id}')">
                                                        删除
                                                    </button>
                                                </c:when>
                                                <c:when test="${item.status == 61}">
                                                    <!-- 状态=61 → 不显示按钮 -->
                                                </c:when>
                                                <c:otherwise>
                                                    <!-- 状态≠60且≠61 → 只显示注销按钮 -->
                                                    <button type="button" class="btn btn_small btn_red"
                                                            onclick="doDeleteTelecomCustomer('${item.id}')">
                                                        注销
                                                    </button>
                                                </c:otherwise>
                                            </c:choose>
                                        </c:otherwise>
                                    </c:choose>
                                </td>
                            </tr>
                        </c:forEach>
                        </tbody>
                        <tfoot>
                            ${cspNoSignCustomer.page.pageStr}
                        </tfoot>
                        </c:otherwise>
                        </c:choose>
                    </table>
                </div>
            </div>
        </div>
    </div>

</div>
</body>
<script>
    $(function () {
        $(".singleSelect").select2()

        $("#groupajax").on("hidden.bs.modal", function () {
            $(this).removeData("bs.modal");
        });
    })

    function doQuery() {
        $("#form").submit();
    }

    function doCopyCustomer(id) {
        if (!id) {
            return
        }
        Dialog.confirm('是否复制该客户?', function () {
            $.ajax({
                url: '${basePage}/chatbot/copyNoSignCustomer.html',
                type: 'post',
                data: {id},
                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 doDeleteCustomer(id) {
        if (!id) {
            return
        }
        Dialog.confirm('是否删除该客户?', function () {
            $.ajax({
                url: '${basePage}/chatbot/deleteNoSignCustomer.html',
                type: 'post',
                data: {id},
                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 doDeleteTelecomCustomer(id) {
        if (!id) {
            return
        }
        Dialog.confirm('是否注销该客户?', function () {
            $.ajax({
                url: '${basePage}/chatbot/deleteTelecomNoSignCustomer.html',
                type: 'post',
                data: {id},
                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 assignServiceCode(id) {
        Dialog.ajaxOpen('${basePage}/chatbot/assignServiceCode.html?id=' + id, '分配服务代码', me => {

        }, {width: '650px', height: '300px'})
    }

    function callSaveServiceCode(serviceCode, extCode, customerNum) {
        $.ajax({
            url: '${basePage}/chatbot/saveAssignServiceCode.html',
            type: 'post',
            data: {
                serviceCode: serviceCode,
                extendNum: extCode,
                customerNum: customerNum
            },
            success: function (res) {
                if (res.code === 0) {
                    Dialog.alertSucc(res.msg)
                    setTimeout(() => {
                        window.location.reload()
                    }, 1000)
                } else {
                    Dialog.alertError(res.msg)
                }
            },
            error() {
                Dialog.alertError('请求失败')
            }
        })
    }
</script>
</html>
