<%@ page language="java" pageEncoding="UTF-8"
         contentType="text/html; charset=UTF-8"%>
<%@ page isELIgnored="false"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%
    String basePath = request.getContextPath();
    String resourcePath = basePath + "/resource";
%>
<!doctype html>
<head>
    <title>数据-详情</title>
    <jsp:include page="../common/head.jsp"></jsp:include>
</head>
<body>
<jsp:include page="../common/body_header.jsp"></jsp:include>
<div class="mid">
    <div class="mid0">
        <div class="mid001">
            <div class="mid01">
                <div class="mid01-left">
                    <div class="kuang">
                        <img src="${outputModel.resourceImg}" class="icon00">
                    </div>
                    <div class="left-bottom">
                        &nbsp;<span class="bottom0">
                                  <img src="<%=resourcePath%>/images/share/icon_chakan.png" class="bottomimg">&nbsp;(${outputModel.viewTimes})
                              </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <span class="bottom0">
                                  <img src="<%=resourcePath%>/images/share/icon_xiazai.png" class="bottomimg"> &nbsp;(0)
                              </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <span class="bottom0">
                                  <img src="<%=resourcePath%>/images/share/icon_wenben.png" class="bottomimg"> &nbsp;(${outputModel.followTotalCount})
                              </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    </div>
                </div>
                <div class="mid01-right">
                    <div>
                        <input type="hidden" id="publishSettingId" name="id" value="${outputModel.publishSettingId}"/>
                        <input type="hidden" id="resourceFollowId" name="id" value="${outputModel.resourceFollowId}"/>
                        <span class="mingchen">${outputModel.resourceName}</span>
                        <span class="biaoqian">${outputModel.dataTag}</span>
                    </div>
                    <div class="clearfix"></div>
                    <div class="jianjie">${outputModel.resourceSummary}</div>
                    <div class="jiage0">
                        <%--<div>
                            <span class="jiage1">价格：</span>
                            <span class="jiage2">免费</span>
                        </div>--%>
                        <div class="clearfix"></div>
                        <div class="kaifang">${outputModel.shareType}</div>
                    </div>
                    <div class="clearfix"></div>
                    <div class="xinxi04">
                        <div class="xinxi00">
                            <div>
                                <span class="xinxi1">面向对象：</span>
                                <span class="xinxi2">${outputModel.catelogCustomName}</span>
                            </div>
                            <div class="xinxi01">
                                <span class="xinxi1">发布机构：</span>
                                <span class="xinxi2">${outputModel.sectorName}</span>
                            </div>
                        </div>
                        <div class="xinxi02">
                            <div>
                                <span class="xinxi1">分类：</span>
                                <span class="xinxi2">${outputModel.catelogThemeName==null?'&nbsp;':outputModel.catelogThemeName}</span>
                            </div>
                            <div class="xinxi01">
                                <span class="xinxi1">发布日期：</span>
                                <span class="xinxi2"><fmt:formatDate value="${outputModel.auditedAt}" pattern="yyyy-MM-dd"/></span>
                            </div>
                        </div>
                    </div>
                    <div class="clearfix"></div>
                    <div class="button0">
                        <button id="fnApplyInfoButton" class="button1" onclick="fnApplyInfo()">立即申请</button>
                        ${outputModel.resourceFollowId ==null ? '<button class="button2" onclick="fnFollow()" id="followId">关注</button>':'<button class="button2" onclick="fnDelFollow()" id="delfollowId" >取消关注</button>'}
                    </div>
                </div>
            </div>
            <div class="clearfix"></div>
            <div class="mid02">
                <div class="xuanxiang">
                    <span class="jieshao" id="diaoyong" onclick="apiInvoking()">数据介绍</span>
                    <span id="return" class="shili" onclick="apiReturn()">数据示例</span>
                    <span class="shili" id="taocan" onclick="introduce()">数据文件</span>
                    <span class="kongbai"></span>
                </div>
                <div class="taocan">
                    <div  id="diaoyongView" class="jieshao0" >
                        <div class="jieshao1">数据项：</div>
                        <div class="jieshao2">${outputModel.dataItem==null?"无":outputModel.dataItem}</div>
                        <div class="jieshao1">发布日期：</div>
                        <div class="jieshao2"><fmt:formatDate value="${outputModel.auditedAt}" pattern="yyyy-MM-dd"/></div>
                        <div class="jieshao1">所属单位：</div>
                        <div class="jieshao2">${outputModel.sectorName==null?"无":outputModel.sectorName}</div>
                        <div class="jieshao1">主题分类：</div>
                        <div class="jieshao2">${outputModel.catelogThemeName==null?"无":outputModel.catelogThemeName}</div>
                        <div class="jieshao1">数据标签：</div>
                        <div class="jieshao2">${outputModel.dataTag==null?"无":outputModel.dataTag}</div>
                    </div>
                    <div id="returnView" class="taocanfont">
                   <%-- <div class="jieshao1">数据示例</div>--%>
                        <div class="jieshao2"></div>
                        <div class="shili0">
                        <c:if test="${outputModel.demoFile!=null}">
                            <img src="<%=resourcePath%>/images/icon_doc.png" alt="${outputModel.demoFileName}" class="doc">
                            <a href="<%=basePath%>/share/data/download.action/1/${outputModel.publishSettingId}" title="${outputModel.demoFileName}">点击此处下载数据示例:${outputModel.demoFileName}</a>
                        </c:if>
                        <c:if test="${outputModel.demoFile==null}">
                            暂无数据
                        </c:if>
                        </div>
                    </div>
                    <div id="taocanView" class="taocanfont">
                   <%-- <div class="jieshao1">数据文件</div>--%>
                        <div class="jieshao2"></div>
                        <div class="shili0">
                            <c:if test="${outputModel.dataFile!=null}">
                                <img src="<%=resourcePath%>/images/icon_doc.png" alt="${outputModel.dataFileName}" class="doc">
                                <a href="<%=basePath%>/share/data/download.action/2/${outputModel.publishSettingId}" title="${outputModel.dataFileName}">点击此处下载数据:${outputModel.dataFileName==null?'暂无数据':outputModel.dataFileName}</a>
                            </c:if>
                            <c:if test="${outputModel.dataFile==null}">
                                暂无数据
                            </c:if>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<jsp:include page="../common/body_footer.jsp"></jsp:include>
<%--////////////////////////////////////////无条件申请页面 ///////////////////////////////////////////////////////--%>
<div id="divUnConditionApply" class="fade" style="display: none;">
    <div class="window">
        <div class="top00">
            <span class="p">申请信息</span>
            <img src="<%=resourcePath%>/images/icon_guanbi.png" alt="" class="guanbi" onclick="closeDivApply()">
        </div>
        <div class="form6">
            <form id="unCoditionApplyFrom">
                <div class="application-font0">
                    <span class="application-font1">开放类型：</span>
                    <span class="application-font2">${outputModel.shareType}</span>
                </div>
                <div class="application-font">
                    <span class="application-font1">资源名称：</span>
                    <span class="application-font2">${outputModel.resourceName}</span>
                </div>
                <div class="clearfix"></div>
                <div>
                    <div class="xieyi0">
                        <span><input type="checkbox" class="box0" value="我已阅读并接受" checked="checked"></span>
                        <span class="fuwu00">阅读并接受<a class="xieyi" target="_blank" href="<%=basePath%>/share/static/agreement_service">《平台服务协议》</a></span>
                    </div>
                    <div class="shenqing" onclick="fnApply(this)">立即申请</div>
                </div>
            </form>
        </div>
    </div>
</div>
<%--////////////////////////////////////////以申请开放页面///////////////////////////////////////////////////////--%>
<div id="divConditionApply" class="fade" style="display: none;">
    <div class="window">
        <div class="top00">
            <span class="p">申请信息</span>
            <img src="<%=resourcePath%>/images/icon_guanbi.png" alt="" class="guanbi" onclick="closeDivApply()">
        </div>
        <div class="form6">
            <form id="coditionApplyFrom">
                <div class="application-font0">
                    <span class="application-font1">开放类型：</span>
                    <span class="application-font2">${outputModel.shareType}</span>
                </div>
                <div class="application-font">
                    <span class="application-font1">资源名称：</span>
                    <span class="application-font2">${outputModel.resourceName}</span>
                </div>
                <%--/////////////////////////////判断加入申请理由对话框//////////////////--%>
                <div  class="application-font" style="display:${outputModel.openType=='无条件开放'?'none':''}">
                    <span class="application-font1">申请理由：</span>
                    <textarea name="applyReason" id="applyReason" cols="60" rows="3"></textarea>
                </div>
                <%--/////////////////////////////////////////////////////////--%>
                <div class="clearfix"></div>
                <div>
                    <div class="xieyi0">
                        <span><input type="checkbox" class="box0" value="我已阅读并接受" checked="checked"></span>
                        <span class="fuwu00">阅读并接受<a class="xieyi" target="_blank" href="<%=basePath%>/share/static/agreement_service">《平台服务协议》</a></span>
                    </div>
                    <div class="shenqing" onclick="fnApply(this)">授权申请</div>
                </div>
            </form>
        </div>
    </div>
</div>
</body>
<script type="text/javascript">
    //关注
    function fnFollow(){
        if (!checkAuthentication()){
            return;
        }
        var id=$('#publishSettingId').val();
        $.get("<%=basePath%>/share/data/follow.action/"+id,function(result){
            //alert(result.stateCode);
            alert(result.msg);
            //alert(result.data)
            $('#resourceFollowId').val(result.data);
            $('#fnApplyInfoButton ~ button:eq(0)').remove();
            $('#fnApplyInfoButton').after('<button class="button2" onclick="fnDelFollow()" id="delfollowId" >取消关注</button>');
        });
    }
    function fnDelFollow(){
        if (!checkAuthentication()){
            return;
        }
        var id=$('#publishSettingId').val();
        var delId=$('#resourceFollowId').val();
        $.get("<%=basePath%>/share/data/delfollow.action/"+delId,function(result){
            //alert(result.stateCode);
            alert(result.msg);
            $('#fnApplyInfoButton ~ button:eq(0)').remove();
            $('#fnApplyInfoButton').after('<button class="button2" onclick="fnFollow()" id="followId">关注</button>');
        });
    }
    //下载没有权限，显示的页面
    if(${paramType=="1"}){
        fnApplyInfo();
    }
    if(${paramType=="2"}){
        alert("已申请，请等待审核");
    }
    //打开申请页面
    function fnApplyInfo(){
        if (!checkAuthentication()){
            return;
        }
        if(${outputModel.shareType=='无条件共享'}){
            $('#divUnConditionApply').show();
        }else{
            $('#divConditionApply').show();
        }

    }
    //关闭申请页面
    function closeDivApply(){
        $('#divUnConditionApply').hide();
        $('#divConditionApply').hide();
    }
    //申请
    function fnApply(tr){
        if (!checkAuthentication()){
            return;
        }
       var b=$(tr).prev().children('span:first').children("input[type='checkbox']").is(':checked');
       if(!b){
         alert("请接受《平台服务协议》");
         return;
       }
        var id=$('#publishSettingId').val();
        var applyReason=$('#applyReason').val();
        $.post("<%=basePath%>/share/data/apply.action",{publishSettingId:id,applyReason:applyReason},function(result){
            if(result.stateCode==200){
                alert(result.msg);
                window.location.href="<%=basePath%>/share/mydata/index.htm/1";
            }else{
                alert(result.msg);
            }
        });
    }

    /*///////////////////////////tab标签页切换//////////////////////////////////*/
    apiInvoking();

    function apiInvoking() {
        $("#diaoyong").attr("class", "jieshao");
        $("#return").attr("class", "shili");
        $("#taocan").attr("class", "shili");
        $("#diaoyongView").show();
        $("#returnView").hide();
        $("#taocanView").hide();

    }

    function apiReturn() {
        $("#diaoyong").attr("class", "shili");
        $("#return").attr("class", "jieshao");
        $("#taocan").attr("class", "shili");
        $("#diaoyongView").hide();
        $("#returnView").show();
        $("#taocanView").hide();
    }

    function introduce() {
        $("#diaoyong").attr("class", "shili");
        $("#return").attr("class", "shili");
        $("#taocan").attr("class", "jieshao");
        $("#diaoyongView").hide();
        $("#returnView").hide();
        $("#taocanView").show();
    }
</script>
</html>