<%@ page import="org.apache.commons.lang.StringUtils" %>
<%@ 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>
    <style>
        .fb{
            width: 835px;
            float: left;
            margin-left: 20px;
        }
        .fabufont1{
            font-size: 14px;
            color: #333333;
            line-height: 36px;
            float: left;
        }
        .fabuinput4{
            width: 835px;
            height: 200px;
            border: solid 1px #c3ccda;
            display: block;
            padding-left: 10px;
            position: relative;
        }
        .fabu-but{
            width: 200px;
            height: 50px;
            background-color: #0f51b2;
            display: block;
            border: none;
            font-size: 16px;
            color: #fff;
            margin-top: 30px;
            margin-left: 326px;
            float: left;
            cursor: pointer;
        }
        .fabu-010{
            margin-top: 24px;
            float: right;
            margin-right: 108px
        }
        .fabuinput6{
            width: 635px;
            height: 36px;
            background-color: #ffffff;
            border: solid 1px #c3ccda;
            display: block;
            float: left;
            margin-left: 20px;
            padding-left: 10px;
        }
        .jia-1{
            color: #ffffff;
            font-size: 46px;
            width: 54px;
            height: 68px;
            border-radius: 50%;
            background-color: #36d6b7;
            text-align: center;
            display: block;
            position: absolute;
            top: 42px;
            right: 30px;
            cursor: pointer;
        }
        .fabu-028{
            margin-top: 20px;
            float: right;
            margin-right: 11px
        }
        .jian-1{
            color: #999999;
            font-size: 46px;
            width: 46px;
            height: 46px;
            border-radius: 50%;
            background-color: #f2f2f2;
            text-align: center;
            display: block;
            position: absolute;
            top: 42px;
            right: 30px;
            cursor: pointer;
        }
        .jian-1 span{
            float: left;
            margin-top: -12px;
            margin-left: 13px;
        }
        .tishi4{
            font-size: 12px;
            color: #f56c6c;
            margin-top: 4px
        }
    </style>
</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 class="active">
                        <strong>发布数据需求</strong>
                    </li>
                </ol>
            </div>
        </div>
    </div>
</div>
<div class="row hidden-print">
    <div class="col-lg-12">
        <div class="ibox">
            <div class="ibox-title">
                <h3>在这里发布你的需求</h3>
            </div>
        </div>
    </div>
</div>
<div class="row">
    <div class="col-lg-12">
        <div class="ibox">
            <div class="ibox-title">
                <span></span>
            </div>
            <div class="ibox-content">
<form id="publishFormId"  method="post" class="form-horizontal">
        <div class="form-group">
            <label for="rqrmntName" class="col-md-2 col-sm-2 control-label" style="text-align:center" ><span style="color: red">*</span>需求名称：</label>
            <div class="col-md-7 col-sm-7">
                <input type="text" id="rqrmntName" name="rqrmntName" placeholder="请输入需求名称" class="form-control" />
                <div class="tishi4"></div>
                <span class="help-block"></span>
            </div>
        </div>
        <div class="form-group">
            <label for="rqrmntSummary" class="col-md-2 col-sm-2 control-label" style="text-align:center" ><span style="color: red">*</span>需求摘要：</label>
            <div class="col-md-7 col-sm-7">
                <input type="text" id="rqrmntSummary"  name="rqrmntSummary" placeholder="请输入需求摘要" class="form-control" ></input>
                <div class="tishi4"></div>
                <span class="help-block"></span>
            </div>
        </div>
        <div class="form-group">
            <label for="dataUses" class="col-md-2 col-sm-2 control-label" style="text-align:center" ><span style="color: red">*</span>需求用途：</label>
            <div class="col-md-7 col-sm-7">
                <input type="text" id="dataUses"  name="dataUses" placeholder="请输入需求用途" class="form-control" ></input>
                <div class="tishi4"></div>
                <span class="help-block"></span>
            </div>
        </div>
        <div class="form-group">
            <label for="sectorId" class="col-md-2 col-sm-2 control-label" style="text-align:center"><span style="color: red">*</span>数据所属部门:</label>
            <div class="col-md-7 col-sm-7">
                <select id="sectorId" name="sectorId" class="form-control">
                    <c:forEach items="${sectorNames}" var="item">
                        <option value="${item.sectorId}">${item.sectorName}</option>
                    </c:forEach>
                </select>
                <span class="help-block"></span>
            </div>
        </div>
        <div class="form-group">
            <label for="sectorId" class="col-md-2 col-sm-2 control-label" style="text-align:center"><span style="color: red">*</span>数据资源:</label>
            <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>--%>
        <div class="form-group">
        <div class="col-sm-offset-2 col-sm-7 text-center">
            <button type="button"  onclick="fnPublish()" class="btn btn-primary"><i class="fa fa-check"></i>发布</button>
            <button type="button" onclick="fnCancel()" class="btn btn-default" data-dismiss="modal"><i class="fa fa-close"></i>返回</button>
        </div>
    </div>
    </form>
<jsp:include page="../../../common/admin/grid_post.jsp"></jsp:include>
<jsp:include page="../../../common/admin/body_post.jsp"></jsp:include>
<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)){
            //后台验证
            $('.tishi4').text('');//清空验证
            $.post("<%=basePath%>/admin/data_supply/publishRequirement.action",$('#publishFormId').serialize(),function(result){
                if(result.stateCode==200){
                    alert(result.msg)
                    window.location.href="<%=basePath%>/admin/data_supply/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();
                        }
                    }
                }
            })
        }
    }
    function fnCancel(){
        window.location.href="<%=basePath%>/admin/data_supply/index.htm"
    }
</script>
</body>
</html>