<%@ 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>
<html>
<head>
    <meta charset="utf-8">
    <title>数据详情</title>
    <link rel="stylesheet" href="css/base.css" type="text/css">
    <jsp:include page="../common/head.jsp"></jsp:include>
</head>
<body>
<jsp:include page="../common/body_header.jsp"></jsp:include>
<div class="line0"></div>
<div class="mid-xiangqing">
    <div class="mid0">
        <div class="mid00">
            <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/icon_chakan.png" class="bottomimg">&nbsp;(${outputModel.viewTimes})
                                    </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <span class="bottom0">
                                        <img src="<%=resourcePath%>/images/icon_xiazai.png" class="bottomimg"> &nbsp;()
                                    </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <span class="bottom0">
                                        <img src="<%=resourcePath%>/images/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="resourceId" name="resourceId" value="${outputModel.resourceId}"/>
                        <input type="hidden" id="resourceFollowId" name="id" value="${outputModel.resourceFollowId}"/>
                        <input type="hidden" id="packagePriceId" name="id" value="${outputModel.packagePrice ==null?0:outputModel.packagePrice}"/>
                        <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>
                            ${outputModel.packagePrice  ==null?'':'<span class="jiage2">￥</span>'}
                            <span class="jiage3">${outputModel.packagePrice  ==null?'免费':outputModel.packagePrice}</span>
                        </div>
                        <div class="clearfix"></div>
                        <div class="kaifang">${outputModel.openType}</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="xinxi002">
                                    ${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>'}
                        <button class="button3" onclick="fnOpenOfflineConference()">点我洽谈</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="taocanfont">
                            <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>
                    <div class="shili0" id="returnView" >
                        <c:if test="${outputModel.demoFile!=null}">
                            <img src="<%=resourcePath%>/images/icon_doc.png" alt="${outputModel.demoFileName}" class="doc">
                            <a href="<%=basePath%>/open/data/download.action/1/${outputModel.publishSettingId}" title="${outputModel.demoFileName}">点击此处下载数据示例：${outputModel.demoFileName==null?'暂无数据':outputModel.demoFileName}</a>
                        </c:if>
                        <c:if test="${outputModel.demoFile==null}">
                            暂无数据
                        </c:if>
                    </div>
                    <div class="shili0" id="taocanView">
                        <c:if test="${outputModel.dataFile!=null}">
                            <img src="<%=resourcePath%>/images/icon_doc.png" alt="${outputModel.dataFileName}" class="doc">
                            <a  href="<%=basePath%>/open/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>
<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.openType}</span>
                </div>
                <div class="application-font">
                    <span class="application-font1">资源名称：</span>
                    <span class="application-font2">${outputModel.resourceName}</span>
                </div>
                <div class="application-font">
                    <span class="application-font1">资源价格：</span>
                    <span class="application-font2">${outputModel.packagePrice ==null?0:outputModel.packagePrice}</span>元
                </div>
                <div class="jiage-xinxi">
                    已选择<span class="shuzi">1</span>个套餐，应付：¥<span class="shuzi">${outputModel.packagePrice==null?0:outputModel.packagePrice}</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%>/open/static/agreement_service">《平台服务协议》</a></span>
                    </div>
                   <%-- <div class="jiarugwc">加入购物车</div>--%>
                    <div class="shenqing" style="margin-left: 135px;margin-top: 25px" 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.openType}</span>
                    </div>
                    <div class="application-font">
                        <span class="application-font1">资源名称：</span>
                        <span class="application-font2">${outputModel.resourceName}</span>
                    </div>
                    <div class="application-font">
                        <span class="application-font1">资源价格：</span>
                        <span class="application-font2">${outputModel.packagePrice ==null?'0':outputModel.packagePrice}</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" style="resize: none"></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%>/open/static/agreement_service">《平台服务协议》</a></span>
                        </div>
                        <div class="shenqing" style="margin-top: 19px;margin-left: 135px" onclick="fnApply(this)">授权申请</div>
                    </div>
                </form>
            </div>
        </div>
    </div>
<%--//////////////////////////////////////洽谈////////////////////////////////////--%>
    <div id="divOfflineConference" class="fade" style="display: none;">
        <div class="window" >
            <div class="top00">
                <span class="p"><span class="xinghao">*</span>资源使用需求</span>
                <img src="<%=resourcePath%>/images/icon_guanbi.png" alt="关闭" class="guanbi" onclick="fnCloseOfflineConference()" >
            </div>
            <div class="form">
                <form id="requirementFormId">
                    <input type="hidden" name="publishSettingId" value="${outputModel.publishSettingId}"/>
                    <div class="application-font-0">
                        <span class="application-font-1"><span class="xinghao">*</span>资源需求：</span>
                        <textarea name="requirement" id="requirement" cols="46" rows="3"  placeholder="请输入您的需求" class="area1"></textarea>
                        <div class="tishi4"></div>
                    </div>
                    <div class="application-font-0">
                        <span class="application-font-2"><span class="xinghao">*</span>使用意向：</span>
                        <textarea name="usages" id="usages" cols="46" rows="3" class="area2" placeholder="请输入您的使用意向"></textarea>
                        <div class="tishi4"></div>
                    </div>
                    <div class="application-font-0">
                        <span class="application-font-2"><span class="xinghao">*</span>联系人：</span>
                        <input type="text" class="area4" id="contact" name="contact" placeholder="请输入联系人">
                        <div class="tishi4"></div>
                    </div>
                    <div class="application-font-0">
                        <span class="application-font-2"><span class="xinghao">*</span>联系电话：</span>
                        <input type="text" class="area4"id="phone" name="phone" placeholder="请输入联系电话">
                        <div class="tishi4"></div>
                    </div>
                    <div class="clearfix"></div>
                    <div class="queding0">
                        <span class="quxiao" onclick="fnCloseOfflineConference()">取消</span>
                        <span class="queding" onclick="fnRequirementForm()">确定</span>
                    </div>
                </form>
            </div>
        </div>
    </div>
<%--//////////////////////////////////////洽谈////////////////////////////////////--%>
</body>
<script type="text/javascript">
    //关注
    function fnFollow(){
            if (!checkAuthentication()){
                return;
            }
            var id=$('#publishSettingId').val();
            $.get("<%=basePath%>/open/data/follow.action/"+id,function(result){
                if(result.stateCode){
                    alert(result.msg);
                    $('#resourceFollowId').val(result.data);
                    $('#fnApplyInfoButton ~ button:eq(0)').remove();
                    $('#fnApplyInfoButton').after('<button class="button2" onclick="fnDelFollow()" id="delfollowId" >取消关注</button>');
                }else{
                    alert(result.msg);
                }
            });
    }
    function fnDelFollow(){
            if (!checkAuthentication()){
                return;
            }
            var id=$('#publishSettingId').val();
            var delId=$('#resourceFollowId').val();
            $.get("<%=basePath%>/open/data/delfollow.action/"+delId,function(result){
                if(result.stateCode==200){
                    alert(result.msg);
                    $('#fnApplyInfoButton ~ button:eq(0)').remove();
                    $('#fnApplyInfoButton').after('<button class="button2" onclick="fnFollow()" id="followId">关注</button>');
                }else{
                    alert(result.msg);
                }
            });
    }

    //下载没有权限，显示的页面
    if(${paramType=="1"}){
        fnApplyInfo();
    }
    if(${paramType=="2"}){
        if(${toPayed!="3"}){
            $('#divUnConditionApply').show();
        }else{
            alert("已申请，请等待审核");
        }
    }
    //打开申请页面
    function fnApplyInfo(){
        if (!checkAuthentication()){
            return;
        }
        if(${outputModel.openType=='无条件开放'}){
            $('#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();
        var packagePrice = $('#packagePriceId').val();
        $.post("<%=basePath%>/open/data/apply.action",{publishSettingId:id,applyReason:applyReason},function(result){
            if(result.stateCode==200){
                if("待支付"===result.msg){
                    var orderNumer = result.data;
                    window.location.href="<%=basePath%>/alipay/index.htm/"+orderNumer+"/"+packagePrice;
                }else{
                    alert(result.msg);
                    window.location.href="<%=basePath%>/open/mydata/index.htm/1";
                }
            }else{
                alert(result.msg);
            }
        });
    }
    //弹出洽谈页面
   function fnOpenOfflineConference(){
       if (!checkAuthentication()){
           return;
       }
        $("#divOfflineConference").show();
   }
   //取消洽谈页面
   function fnCloseOfflineConference(){
       $("#divOfflineConference").hide();
   }
    //洽谈
   function fnRequirementForm(){
       $('.tishi4').text('');//清空验证
        $.post("<%=basePath%>/open/data/offlineConference.action",$('#requirementFormId').serialize(),function(result){
            if(result.stateCode==200){
                alert(result.msg)
                $("#divOfflineConference").hide();
            }else{
                if(result.data ==null){
                    alert(result.msg);//弹出发布失败提示
                }else{
                    for(var item in result.data){
                        debugger;
                        $("[name='"+item+"']").next().text("! "+result.data[item]);
                        $("[name='"+item+"']").next().show();
                    }
                }
            }
        })
   }
   /*///////////////////////////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>