<%@ 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"%>
<%
    String basePath = request.getContextPath();
    String resourcePath = basePath + "/resource";
%>
<!doctype html>
<html>
<head>
    <jsp:include page="../common/head.jsp"></jsp:include>
    <title>数据发布需求</title>
    <link rel="stylesheet" href="css/base.css" type="text/css">
</head>
<body>
<jsp:include page="../common/body_header.jsp"></jsp:include>

<div class="clearfix"></div>
<div class="line0"></div>
<div class="mid-fabu1">
    <div class="form-fabu1">
        <div class="fabufont">发布您的需求</div>
        <div class="line-fabu"></div>
        <div class="clearfix"></div>
        <div class="fabu001">
            <form id="publishFormId"  method="post">
                <div class="fabu-01">
                    <span class="fabufont1"><span class="xinghao">*</span>需求名称</span>
                    <span class="ff1"><input type="text" class="fabuinput" name="rqrmntName" placeholder="请输入需求名称">
                    <div class="tishi4"></div>
                    </span>
                </div>
                <div class="fabu-01">
                    <span class="fabufont1"><span class="xinghao">*</span>需求摘要</span>
                    <span class="ff1"><textarea cols="30" rows="2" class="fabuinput1"  style="resize: none" name="rqrmntSummary" placeholder="请输入需求摘要" ></textarea>
                    <div class="tishi4"></div>
                    </span>
                </div>
                <div class="fabu-01">
                    <span class="fabufont1"><span class="xinghao">*</span>需求用途</span>
                    <span class="ff1"><input type="text" class="fabuinput" name="dataUses" placeholder="请输入需求用途">
                    <div class="tishi4"></div>
                    </span>
                </div>
                <div class="fabu-01">
                    <span class="fabufont1">数据所属部门</span>
                    <select name="sectorId" id="sectorId" class="fabuinput5">
                        <option></option>
                        <c:forEach items="${sectorNames}" var="item">
                            <option value="${item.sectorId}">${item.sectorName}</option>
                        </c:forEach>
                    </select>
                </div>
                    <%--//////////////////////--%>
                <div class="fabu-028">
                    <span class="fabufont1">数据资源</span>
                    <div class="fb" id="DataRequirementDataDemoId">
                        <div class="fabuinput4" >
                            <div class="fabu-010">
                                <span class="fabufont1">数据名称</span>
                                <input type="text" class="fabuinput6" name="dataRequirementDataList[0].dataName"  placeholder="请输入数据名称">
                            </div>
                            <div class="fabu-010">
                                <span class="fabufont1">数据项</span>
                                <input type="text" class="fabuinput6" name="dataRequirementDataList[0].dataItem"  placeholder="请输入数据项">
                            </div>
                            <div class="clearfix"></div>
                            <div><div class="jia-1" id="jiaOrJian"><span   onclick="fnAdd()">+</span></div></div>
                        </div>
                    </div>
                </div>
                    <%--//////////////////--%>
                <div class="clearfix"></div>
                <button  class="fabu-but" style="margin-left: 410px" type="button" onclick="fnPublish()">发布</button>
            </form>
        </div>

    </div>

</div>
<jsp:include page="../common/body_footer.jsp"></jsp:include>
</body>
<script type="text/javascript">
    //加
    var count=0;
    function fnAdd(){
        count++;
        var v=$('#DataRequirementDataDemoId').children('div:last-child').html();
        $('#DataRequirementDataDemoId').children('div:last-child').after("<div class='fabuinput4'>"+v+"</div>");
        $('#DataRequirementDataDemoId').children('div:last-child').prev().children('div:last-child').html('<div class="jian-1" id="jiaOrJian"><span onclick="fnDec(this)">-</span></div>');
        var d=$('#DataRequirementDataDemoId').children('div:last-child').find('input:eq(0)').attr('name',"dataRequirementDataList["+count+"].dataName");
        var d=$('#DataRequirementDataDemoId').children('div:last-child').find('input:eq(1)').attr('name',"dataRequirementDataList["+count+"].dataItem");
    }

    //减
    function fnDec(tr){
        $(tr).parent().parent().parent().remove();
    }


    //发布
    function fnPublish(){
        var msg = "您真的确定要发布吗？";
        if (confirm(msg)){
            //前台验证
           /* $('#publishFormId').valid({
                rules:{
                    rqrmntName:"required",
                    rqrmntSummary:"required",
                    dataUses:"required",
                }
            });*/
            //后台验证
            $('.tishi4').text('');//清空验证
            $.post("<%=basePath%>/open/dataRequirement/publish.action",$('#publishFormId').serialize(),function(result){
                if(result.stateCode==200){
                    alert(result.msg)
                    window.location.href="<%=basePath%>/open/dataRequirement/index.htm";
                }else{
                    if(result.data ==null){
                        alert(result.msg);//弹出发布失败提示
                    }else{
                        for(var item in result.data){
                            $("[name='"+item+"']").next().text("! "+result.data[item]);
                            $("[name='"+item+"']").next().show();
                        }
                    }
                }
            })
        }
    }
</script>
</html>
