<%--
  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_bgs 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_bgs 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="3"/>
        <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">
                <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_day" id="mx_day" value="<%=pub.trimNull((String)ht.get("day"))%>" >
                </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);
                        String zb_type=pub.trimNull((String)ht1.get("zb_type"));
            %>
            <div class="zbType row cl" id="div_<%=pub.trimNull((String)ht1.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;" id="lable_<%=i+1%>">
                    <script>
                        var index='<%=i+1%>';
                        getSelect('<%=i+1%>','<%=zb_type%>','lable_'+index);
                        function getSelect(index,value,divId) {
                            value=encodeURI(encodeURI(value));
                            $.post("./zd_view_list.jsp?value="+value+"&name_id=zb_type_"+index+"&math="+Math.random(),function(data){
                                    document.getElementById(divId).innerHTML=data;
                                }
                            );
                        }
                    </script>
                </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>
            </div>
            <%
                }
            }else{
            %>
            <div class="zbType row cl" id="div_1">
                <label class="form-label col-xs-4" style="margin-top: 0px;" id="lable_1">
                    <script>
                        $.post("./zd_view_list.jsp?name_id=zb_type_1&math="+Math.random(),function(data){
                                document.getElementById("lable_1").innerHTML=data;
                            }
                        );
                    </script>
                </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>
            </div>
            <div class="zbType row cl" id="div_2">
                <label class="form-label col-xs-4" style="margin-top: 0px;" id="lable_2">
                    <script>
                        $.post("./zd_view_list.jsp?name_id=zb_type_2&math="+Math.random(),function(data){
                                document.getElementById("lable_2").innerHTML=data;
                            }
                        );
                    </script>
                </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_2" name="b_time_2" >
                    &nbsp;至&nbsp;
                    <input type="text" style="width:25%;" autocomplete="off" class="input-text Wdate" onclick="WdatePicker({dateFmt:'HH-mm'})" value="" placeholder="" id = "e_time_2" name="e_time_2" >
                    &nbsp;&nbsp;默认人数
                    <input type="text" style="width:20%;" class="input-text "  value="" placeholder="" id = "ren_num_2" name="ren_num_2" >
                </div>
            </div>
            <div class="zbType row cl" id="div_3">
                <label class="form-label col-xs-4" style="margin-top: 0px;" id="lable_3">
                    <script>
                        $.post("./zd_view_list.jsp?name_id=zb_type_3&math="+Math.random(),function(data){
                                document.getElementById("lable_3").innerHTML=data;
                            }
                        );
                    </script>
                </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_3" name="b_time_3" >
                    &nbsp;至&nbsp;
                    <input type="text" style="width:25%;" autocomplete="off" class="input-text Wdate" onclick="WdatePicker({dateFmt:'HH-mm'})" value="" placeholder="" id = "e_time_3" name="e_time_3" >
                    &nbsp;&nbsp;默认人数
                    <input type="text" style="width:20%;" class="input-text "  value="" placeholder="" id = "ren_num_3" name="ren_num_3" >
                </div>
            </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>

    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 param=msg.split(",");
                    //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=param[1];
                            parent.document.getElementById("check_mx_day").value=param[2];
                            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>