<%@ page import="com.lightinit.hsdataplatform.dictionary.DicResourceState" %>
<%@ page language="java" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" %>
<%@ page isELIgnored="false" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
    String basePath = request.getContextPath();
%>
<!DOCTYPE html>
<html>
<head>
    <jsp:include page="../../../common/admin/head.jsp"></jsp:include>
</head>
<body>
<jsp:include page="../../../common/admin/body_pre.jsp"></jsp:include>
<div class="row hidden-print">
    <div class="col-lg-12">
        <div class="ibox">
            <div class="ibox-title">
                <h2>发布微服务</h2>
                <ol class="breadcrumb">
                    <li>
                        <a href="javascript:void(0);">资源活化</a>
                    </li>
                    <li>
                        <a href="javascript:void(0);">资源</a>
                    </li>
                    <li>
                        <a href="<%=basePath%>/admin/data_register_api/index.htm">API注册</a>
                    </li>
                    <li class="active">
                        <strong>发布微服务</strong>
                    </li>
                </ol>
            </div>
        </div>
    </div>

    <div class="col-md-12 column">
        <form class="form-horizontal" id="apiAudit" role="form"
              action="<%=basePath%>/admin/data_register_api/auditAddService.action">
            <input type="hidden" name="api_badge" id="api_badge" value=0>
            <input type="hidden" name="id" id="resource_id" value="${resource.id}">
            <input type="hidden" name="outId1" id="outId1" value="${resource.outId1}">
            <div class="form-group">
                <label for="resourceName" class="col-lg-2  text-right">服务名称</label>
                <div id="resourceName">
                    ${resource.resourceName}
                </div>
            </div>
            <div class="form-group">
                <label for="resourceIdentity" class="col-lg-2  text-right">服务标识</label>
                <div id="resourceIdentity">
                    ${resource.resourceIdentity}
                </div>
            </div>
            <div class="form-group">
                <label for="resourceSummary" class="col-lg-2  text-right">服务简介</label>
                <div id="resourceSummary">
                    ${resource.resourceSummary}
                </div>
            </div>
            <div class="form-group">
                <label for="registerDate" class="col-lg-2  text-right">注册日期</label>
                <div id="registerDate">
                    <fmt:formatDate value="${resource.registerDate}" pattern="yyyy-MM-dd"/>
                </div>
            </div>
            <div class="form-group">
                <label for="provider" class="col-lg-2  text-right">提供单位</label>
                <div id="provider">
                    ${resource.providerName}
                </div>
                <span class="field-validation-valid help-block"></span>
            </div>
            <div class="form-group">
                <%--TODO 目录分类暂未完成--%>
                <label for="resourceSummary" class="col-lg-2  text-right">目录分类</label>
            </div>
            <div class="form-group">
                <label for="catelogBasic" class="col-lg-2  text-right">基础分类</label>
                <div id="catelogBasic">
                    ${resource.catelogBasicName}
                </div>
                <span class="field-validation-valid help-block"></span>
            </div>
            <div class="form-group">
                <label for="catelogSector" class="col-lg-2  text-right">部门分类</label>
                <div id="catelogSector">
                    ${resource.catelogSectorName}
                </div>
                <span class="field-validation-valid help-block"></span>
            </div>
            <div class="form-group">
                <label for="catelogTheme" class="col-lg-2  text-right">主题分类</label>
                <div id="catelogTheme">
                    ${resource.catelogThemeName}
                </div>
                <span class="field-validation-valid help-block"></span>
            </div>
            <div class="form-group">
                <label for="catelogCustom" class="col-lg-2  text-right">自定义分类</label>
                <div id="catelogCustom">
                    ${resource.catelogCustomName}
                </div>
                <span class="field-validation-valid help-block"></span>
            </div>
            <div class="form-group">
                <label for="shareType" class="col-lg-2  text-right">共享类型</label>
                <div id="shareType">
                    ${resource.shareType}
                </div>
                <span class="field-validation-valid help-block"></span>
            </div>
            <div class="form-group">
                <label for="openType" class="col-lg-2  text-right">开放类型</label>
                <div id="openType">
                    ${resource.openType}
                </div>
                <span class="field-validation-valid help-block"></span>
            </div>
            <div class="form-group">
                <label for="allowDeal" class="col-lg-2  text-right">是否可交易</label>
                <div id="allowDeal">
                    <c:if test="${resource.allowDeal==0}">否</c:if>
                    <c:if test="${resource.allowDeal==1}">是</c:if>
                </div>
                <span class="field-validation-valid help-block"></span>
            </div>
            <div class="form-group">
                <label for="serviceType" class="col-lg-2  text-right">服务类型</label>
                <div id="serviceType">
                    ${resource.serviceType}
                </div>
                <span class="field-validation-valid help-block"></span>
            </div>
            <div class="form-group">
                <label for="serviceTag" class="col-lg-2  text-right">服务标签</label>
                <div id="serviceTag">
                    ${resource.serviceTag}
                </div>
                <span class="field-validation-valid help-block"></span>
            </div>
            <div class="form-group">
                <label for="component" class="col-lg-2  text-right">组成接口</label>
                <div id="component">
                    ${resource.component}
                </div>
                <span class="field-validation-valid help-block"></span>
            </div>
            <div class="form-group">
                <table id="testaaa" class="table table-hover  table-condensed table-bordered "
                       style="width: 70%;margin-left:10%" align="center">
                    <thead>
                    <tr>
                        <th>接口名称</th>
                        <th>接口标识</th>
                        <th>接口地址</th>
                        <th>操作</th>
                    </tr>
                    <c:if test="${resourceApiInterface.size()>0}">
                        <c:forEach items="${resourceApiInterface}" var="apiInterface">
                            <tr>
                                <td>${apiInterface.interfaceName}</td>
                                <td>${apiInterface.interfaceIdentity}</td>
                                <td>${apiInterface.url}</td>
                                <td><a onclick='resourceviewById(${apiInterface.id});'>&nbsp;查看</a></td>
                            </tr>
                        </c:forEach>
                    </c:if>
                    </thead>
                </table>
            </div>

            <%@ include file="registerService.jsp" %>

            <div class="form-group">
                <label for="lesseeId" class="col-sm-2 control-label">租户</label>
                <div class="col-md-7 col-sm-7">
                    <input id="namespace" name="namespace" type="hidden">
                    <select id="lesseeId" name="lesseeId" class="form-control" onchange="selectOnchang(this)">
                        <option></option>
                        <c:if test="${lessList.data.size()>0}">
                            <c:forEach items="${lessList.data}" var="item" >
                                <option value="${item.id}">${item.namespaceName}</option>
                            </c:forEach>
                        </c:if>
                    </select>
                </div>
                <span class="field-validation-valid help-block"></span>
            </div>


            <div class="form-group">
                <label for="auditOpinion" class="col-lg-2  text-right">审核意见</label>
                <div class="col-sm-7">
                    <textarea type="text" id="auditOpinion" name="auditOpinion" class="form-control"
                              value=""></textarea>
                </div>
            </div>



            <div class="form-group">
                <div class="col-sm-offset-2 col-sm-7 text-center">
                    <button type="button" id="passButton" class="btn btn-primary"><i class="fa fa-check"></i>审核通过</button>
                    <button type="button" id="unPassButton" class="btn btn-warning"><i class="fa fa-exclamation"></i>审核未通过</button>
                    <button type="button" id="cancel" class="btn btn-default" data-dismiss="modal"><i class="fa fa-close"></i>返回</button>
                </div>
            </div>
            <input type="hidden" id="resourceState" name="resourceState">
        </form>
    </div>
</div>
<jsp:include page="../../../common/admin/body_post.jsp"></jsp:include>
<script type="text/javascript">

    $(".input-group.date").datetimepicker({
        format: "YYYY-MM-DD",
        locale: "zh-cn"
    });

    $("#cancel").click(function () {
        window.location.href="<%=basePath%>/admin/data_register_api/index.htm" ;
    });

    $("#passButton").click(function () {
        $('input[name="resourceState"]').val("<%=DicResourceState.APPROVED%>");
        $('#apiAudit').ajaxValSubmit({
            ajaxSubmitOptions: {
                onSuccess: function () {
                    window.location.href = "<%=basePath%>/admin/data_register_api/index.htm";
                }
            }
        });
    });
    $("#unPassButton").click(function () {
        $('input[name="resourceState"]').val("<%=DicResourceState.REJECTED%>");
        $('#apiAudit').ajaxValSubmit({
            ajaxSubmitOptions: {
                onSuccess: function () {
                    window.location.href = "<%=basePath%>/admin/data_register_api/index.htm";
                }
            }
        });
    });

    function resourceviewById(id) {
        $.popBsPartial({url: "<%=basePath%>/admin/data_register_api/apiInterface_view.htm/" + id});
    }

    function selectOnchang(choose){
        //获取被选中的option标签选项
        debugger ;
        $('#namespace').val(choose.options[choose.selectedIndex].text) ;
    }
</script>
</body>
</html>