<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2020/9/11
  Time: 12:54
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="com.censoft.common.base.Pub" %>
<%@ page import="com.censoft.common.db.ConnectionFactory" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.util.Hashtable" %>
<%@ page import="java.util.Vector" %>
<%
    ConnectionFactory cf = new ConnectionFactory();
    Pub pub = new Pub();
    Connection conn = null;
    Vector v_list = null;
    Vector v_type_list = null;
    String mx_id = pub.trimNull(request.getParameter("mx_id"));
    String action = pub.trimNull(request.getParameter("action"));
    Hashtable ht = new Hashtable();
    StringBuffer sql = new StringBuffer();
    StringBuffer group_sql = new StringBuffer();
    int listSize=1;
    try {
        conn = com.censoft.db.DBUtil.getConnection();
        if("update".equals(action)){
            sql.append("select * from zb_mx where id=?");
            v_list = cf.doQuery(conn, sql.toString(), null, new Object[]{mx_id});
        }
        if(!"".equals(mx_id)) {
            group_sql.append("select * from zb_type where mx_id=? order by order_num asc");
            v_type_list = cf.doQuery(conn, group_sql.toString(), null, new Object[]{mx_id});
            if(v_type_list!=null && v_type_list.size()>0){
                listSize=v_type_list.size();
            }
        }
        if (v_list!=null&&v_list.size() > 0) {
            ht = (Hashtable) v_list.get(0);
        }
    } catch (Exception e) {
        out.println("查询用户信息异常" + e);
        return;
    } finally {
        if (conn != null) {
            try {
                conn.close();
            } catch (Exception e) {
            }
        }
    }
%>
<style>
    .input-three {
        width: 22%
    }
    .input-two {
        width: 32%
    }
    .col-sm-2{
        width:14%;
    }
    .col-sm-3{
        width:19%;
    }
    .btn-red{ background-color:red;border: red}
    .btn-green{ background-color:green;border: green}


</style>
<div class="">
    <form class="form form-horizontal" id="form-admin-add">
        <input type="hidden" value="<%=action%>" name="action" id="action">
        <input type="hidden" value="<%=mx_id%>" name="mx_id" id="mx_id">
        <input type="hidden" id="input_count" name="input_count" value="<%=listSize%>"/>
        <input type="hidden"  name="mx_day" id="mx_day" value="30" >
        <div id="content" class="cl pd-5  bk-gray divOverflow" style="overflow:hidden;margin-bottom: 20px;">
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-2">
                    <span class="c-red">*</span>模型名字&nbsp;：
                </label>
                <div class="formControls col-xs-8 col-sm-10">
                    <input type="text" class="input-text" name="mx_name" id="mx_name" value="<%=pub.trimNull((String)ht.get("name"))%>" >
                </div>
            </div>
            <div class="row cl" id="zb_type_div">
                <label class="form-label col-xs-4 col-sm-2">
                    <span class="c-red">*</span>时间段&nbsp;：
                </label>
            </div>

            <%
                Hashtable ht1 = new Hashtable();
                if(v_type_list != null && v_type_list.size() > 0){
                    for (int i = 0; i < v_type_list.size(); i++) {
                        ht1 = (Hashtable) v_type_list.get(i);
            %>
            <div class="zbType row cl" id="div_<%=pub.trimNull((String)ht.get("id"))%>">
                <input type="hidden" name="zb_type_id_<%=i+1%>" value="<%=pub.trimNull((String)ht1.get("id"))%>">
                <label class="form-label col-xs-4" style="margin-top: 0px;">
                    <input type="text" style="width:30%;" autocomplete="off" class="input-text" value="<%=pub.trimNull((String)ht1.get("zb_type"))%>" placeholder=""  id = "zb_type_<%=i+1%>" name="zb_type_<%=i+1%>" >
                    ：
                </label>
                <div class="formControls col-xs-6">
                    <input type="text" style="width:25%;" class="input-text Wdate" onclick="WdatePicker({dateFmt:'HH-mm'})" value="<%=pub.trimNull((String)ht1.get("b_time"))%>" placeholder="" id = "b_time_<%=i+1%>" name="b_time_<%=i+1%>" >
                    &nbsp;至&nbsp;
                    <input type="text" style="width:25%;" class="input-text Wdate" onclick="WdatePicker({dateFmt:'HH-mm'})" value="<%=pub.trimNull((String)ht1.get("e_time"))%>" placeholder="" id = "e_time_<%=i+1%>" name="e_time_<%=i+1%>" >
                    &nbsp;&nbsp;默认人数
                    <input type="text" style="width:20%;" class="input-text "  value="<%=pub.trimNull((String)ht1.get("ren_num"))%>" placeholder="" id = "ren_num_<%=i+1%>" name="ren_num_<%=i+1%>" >
                </div>
                <%
                    if(i==0){
                %>
                <a href="javascript:void (0);" onclick="addDiv();" style="font-size: 25px;">+</a>
                <%}else{%>
                <a href="javascript:void (0);" onclick="deleteDiv('<%=pub.trimNull((String)ht.get("id"))%>');" style="font-size: 25px;display:none;">-</a>
                <%}
                %>
            </div>
            <%
                }
            }else{
            %>
            <div class="zbType row cl" id="div_1">
                <label class="form-label col-xs-4" style="margin-top: 0px;">
                    <input type="text" style="width:30%;" autocomplete="off" class="input-text" value="" placeholder=""  id = "zb_type_1" name="zb_type_1" >
                    ：
                </label>
                <div class="formControls col-xs-6">
                    <input type="text" style="width:25%;" autocomplete="off" class="input-text Wdate" onclick="WdatePicker({dateFmt:'HH-mm'})" value="" placeholder="" id = "b_time_1" name="b_time_1" >
                    &nbsp;至&nbsp;
                    <input type="text" style="width:25%;" autocomplete="off" class="input-text Wdate" onclick="WdatePicker({dateFmt:'HH-mm'})" value="" placeholder="" id = "e_time_1" name="e_time_1" >
                    &nbsp;&nbsp;默认人数
                    <input type="text" style="width:20%;" class="input-text "  value="" placeholder="" id = "ren_num_1" name="ren_num_1" >
                </div>
                <a href="javascript:void (0);" onclick="addDiv();" style="font-size: 25px;">+</a>
            </div>
            <%
                }
            %>
        </div>

    </form>
</div>
<div class="cl mb-10  bk-gray " style="height: 50px;">
    <div class="col-sm-3 pd-10" style="width:100%;text-align: center;">
        <input class="btn btn-primary radius btn-green" type="button" onclick="javascript:saveForm();" value="&nbsp;&nbsp;保存&nbsp;&nbsp;">
    </div>
</div>
<script>
    var  count;
    var size='<%=listSize%>';
    if(size==0){
        count=1;
    }else{
        count=parseInt(size);
    }
    function addDiv(){
        var name_count=parseInt($("#input_count").val());
        $("#content").append("<div class=\"zbType row cl\" name=\""+(count+1)+"\" id=\"div_"+(count+1)+"\">\n" +
            "                <label class=\"form-label col-xs-4\" style=\"margin-top: 0px;\">                    " +
            "                   <input type=\"text\" style=\"width:30%;\" autocomplete=\"off\" class=\"input-text\" value=\"\" placeholder=\"\"  id = \"zb_type_"+(name_count+1)+"\" name=\"zb_type_"+(name_count+1)+"\" > ：</label>\n" +
            "                <div class=\"formControls col-xs-6\">\n" +
            "                    <input type=\"text\" style=\"width:25%;\" autocomplete=\"off\" class=\"input-text Wdate\" onclick=\"WdatePicker({dateFmt:'HH-mm'})\" value=\"\" placeholder=\"\" id = \"b_time_"+(name_count+1)+"\" name=\"b_time_"+(name_count+1)+"\" >\n" +
            "                    &nbsp;至&nbsp;\n" +
            "                    <input type=\"text\" style=\"width:25%;\" autocomplete=\"off\" class=\"input-text Wdate\" onclick=\"WdatePicker({dateFmt:'HH-mm'})\" value=\"\" placeholder=\"\" id = \"e_time_"+(name_count+1)+"\" name=\"e_time_"+(name_count+1)+"\" >\n" +
            "                       &nbsp;&nbsp;默认人数\n" +
            "                    <input type=\"text\" style=\"width:20%;\" class=\"input-text \"  value=\"\" placeholder=\"\" id = \"ren_num_"+(name_count+1)+"\" name=\"ren_num_"+(name_count+1)+"\" >" +
            "                 </div>\n" +
            "                  <a href=\"javascript:void (0);\" onclick=\"deleteDiv("+(count+1)+");\" style=\"font-size: 25px;\">-</a>"+
            "            </div>");
        count++;
        //var obj=document.getElementsByClassName("row cl").length;
        var obj=$(".zbType").length;
        $("#input_count").val(obj);
    }
    function deleteDiv(div_id){
        $("#div_"+div_id).remove();
        $('.zbType').each(function(index,element){
            if(index!=0){
                index=index+1;
                //$(this).children(":first").html("号段"+index+"：");
                var div_index=$(this).attr("name");
                $("#zb_type_"+div_index).attr("name","zb_type_"+index);
                $("#b_time_"+div_index).attr("name","b_time_"+index);
                $("#e_time_"+div_index).attr("name","e_time_"+index);
            }
        });
        //var obj=document.getElementsByClassName("row cl").length;
        var obj=$(".zbType").length;
        $("#input_count").val(obj);
    }
    function LayerOpen(title, url, w, h) {
        if($("#user_id").val()==''){
            layer.alert("请先保存用户再添加相关人员",{icon:5,title:"提示"});
            return false;
        }
        var abc = layer.open({
            title:title,
            type: 2,
            content: url,
            area: [w, h],
            maxmin: true
         });
        layer.full(abc);
    }
    function viewDeptOrUserInfo(title, url, w, h) {
        location.href=url;
    }
    function saveForm() {
        if($("#mx_name").val()==''){
            layer.alert("模型名称不能为空",{icon:5,title:"提示"});
            return false;
        }
        $.ajax({
            type: "POST",
            url: "./action.jsp",
            data: $('#form-admin-add').serialize(),
            success: function (msg) {
                if (msg.indexOf("success") >= 0) {
                    var mx_id = msg.substring(msg.indexOf(",")+1,msg.length);
                    layer.msg('操作成功!', {icon: 1, time: 1000},
                        function () {
                            //parent.searchModel();
                            parent.document.getElementById("check_mx_id").value=mx_id;
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        });
                } else {
                    layer.msg('操作失败', {
                        icon: 5,
                        time: 2000 //2秒关闭（如果不配置，默认是3秒）
                    }, function () {
                        // console.log("********************8")
                    });
                }
            }
        });
    }
    function deleteUser(user_id,p_user_id){
        layer.confirm('确认要删除吗？', function (index) {
			$.ajax({
				type: "POST",
				url: "./action.jsp?&p_user_id="+p_user_id+"&user_id="+user_id+"&action=delete",
				success: function (msg) {
					if (msg.indexOf("success") >= 0) {
						layer.msg('操作成功!', {icon: 1, time: 1000},
							function () {
								location.reload();
								if(rel_user_id!=''){
									window.parent.location.reload();
								}
								parent.searchModel();
							});
					} else {
						layer.msg('操作失败', {
							icon: 5,
							time: 2000 //2秒关闭（如果不配置，默认是3秒）
						}, function () {
							// console.log("********************8")
						});
					}
				}
			});
		});
    }
</script>