<%--
  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.sql.SQLException" %>
<%@ page import="java.util.*" %>
<%


    Connection conn = null;
    Vector v_list;
    Hashtable ht = new Hashtable();
    Pub pub = new Pub();
    ConnectionFactory cf = new ConnectionFactory();
    String zd_id = pub.trimNull(request.getParameter("zd_id"));
    String update_id = pub.trimNull(request.getParameter("update_id"));
    String action="add";
    List list = new ArrayList();
    String sql="";
    if(!"".equals(update_id)){
        sql="select t1.*,t2.zd_name from zc_zd_col t1 join zc_zd t2 on t1.zd_id=t2.id where t2.id=? and t1.id=?";
        action="update";
        list.add(zd_id);
        list.add(update_id);
    }else{
        sql="select t2.zd_name from zc_zd t2 where t2.id=? ";
        list.add(zd_id);
    }
    try {
        conn = com.censoft.db.DBUtil.getConnection();
        v_list=cf.doQuery(conn,sql,null,list.toArray());
        if (v_list == null) {
            out.println("查询出错");
            return;
        }
        if (v_list.size() > 0) {
            ht = (Hashtable) v_list.get(0);
        }
    } catch (Exception e) {
        try {
            if(conn != null){
                conn.rollback();
            }
        } catch (SQLException e1) {
            e1.printStackTrace();
        }
        return;
    } finally {
        if (conn != null) {
            try {
                conn.close();
            } catch (Exception e) {
            }
        }
    }
%>
<article class="page-container" style="overflow: hidden;">
    <form class="form form-horizontal" id="form-admin-add">
        <input type="hidden" name="action" value="<%=action%>">
        <input type="hidden" name="zd_id" value="<%=zd_id%>">
        <input type="hidden" name="update_id" value="<%=update_id%>">
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2">字典名称：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" name="zd_name" id="zd_name" value="<%=pub.trimNull((String) ht.get("zd_name"))%>"
                       placeholder="" >
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2">元素名称：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" name="col_name" id="col_name" value="<%=pub.trimNull((String) ht.get("col_name"))%>"
                       placeholder="" >
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2">备注：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <textarea type="text" class="input-text" name="beizhu" id="beizhu"
                          style="height:120px;" ><%=pub.trimNull((String) ht.get("beizhu"))%></textarea>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2">排序：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" name="col_order" id="col_order" value="<%=pub.trimNull((String) ht.get("col_order"))%>"
                       placeholder="" >
            </div>
        </div>
        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                <input class="btn btn-primary radius" type="button" onclick="javascript:saveForm();"
                       value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
            </div>
        </div>

    </form>
</article>
<script>
    function saveForm(){
        $.ajax({
            type: "POST",
            url: "./action_col.jsp",
            data: $('#form-admin-add').serialize(),
            success: function (msg) {
                if (msg.indexOf("success") >= 0) {
                    layer.msg('操作成功!', {icon: 1, time: 1000},
                        function () {
                            parent.searchModel();
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        });
                } else {
                    layer.msg('操作失败', {
                        icon: 5,
                        time: 2000 //2秒关闭（如果不配置，默认是3秒）
                    }, function () {
                    });
                }
            }
        });
    }
</script>