<%--
  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 update_id = pub.trimNull(request.getParameter("update_id"));
    String action="add";
    String sb_dept="";
    String sb_user="";
    String sb_tel="";
    try {
        conn = com.censoft.db.DBUtil.getConnection();
        v_list=cf.doQuery(conn,"select t1.zc_id,zc_name,pinpai,t2.bf_id,sb_dept,sb_user,t2.cl_user" +
                ",bf_time,bf_reason,t3.xm_id,t3.ly_dept,t3.ly_user,t3.tel" +
                " from zc_register t1 join zc_ly t3 on t1.zc_id=t3.zc_id " +
                " left join zc_bf t2 on t1.zc_id=t2.zc_id" +
                " where t1.zc_id=? ",null,new Object[]{update_id});
        if (v_list == null) {
            out.println("查询出错");
            return;
        }
        if (v_list.size() > 0) {
            ht = (Hashtable) v_list.get(0);
            String bf_id=pub.trimNull((String)ht.get("bf_id"));
            if(!"".equals(bf_id)){
                action="update";
            }
            if("".equals(sb_dept)){
                sb_dept=pub.trimNull((String)ht.get("ly_dept"));
            }
            sb_user=pub.trimNull((String)ht.get("sb_user"));
            if("".equals(sb_user)){
                sb_user=pub.trimNull((String)ht.get("ly_user"));
            }
        }
    } 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) {
            }
        }
    }
%>
<style>
    .col-sm-1{width: 12%;}
</style>
<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="update_id" value="<%=update_id%>"/>
        <input type="hidden" name="opt" value="bf"/>
        <div 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-1">资产名称：</label>
                <div class="formControls col-xs-8 col-sm-3">
                    <input type="text" name="zc_name" id="zc_name"  value="<%=pub.trimNull((String)ht.get("zc_name"))%>" class="input-text ">
                </div>
                <label class="form-label col-xs-4 col-sm-1">资产编号：</label>
                <div class="formControls col-xs-8 col-sm-3">
                    <input type="text" name="zc_id" id="zc_id"  value="<%=pub.trimNull((String)ht.get("zc_id"))%>" class="input-text ">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-1">所属项目：</label>
                <div class="formControls col-xs-8 col-sm-3">
                    <input type="text"  value="<%=pub.trimNull((String)ht.get("xm_id"))%>" class="input-text ">
                </div>
                <label class="form-label col-xs-4 col-sm-1">品牌：</label>
                <div class="formControls col-xs-8 col-sm-3">
                    <input type="text" name="pinpai" value="<%=pub.trimNull((String)ht.get("pinpai"))%>" class="input-text">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-1">申报单位：</label>
                <div class="formControls col-xs-8 col-sm-3">
                    <input type="text" name="sb_dept" value="<%=sb_dept%>" class="input-text">
                </div>
                <label class="form-label col-xs-4 col-sm-1">申报人：</label>
                <div class="formControls col-xs-8 col-sm-3">
                    <input type="text" name="sb_user" id="sb_user" value="<%=sb_user%>" class="input-text ">
                </div>
            </div>
            <div class="row cl">
               <%-- <label class="form-label col-xs-4 col-sm-1">处理人：</label>
                <div class="formControls col-xs-8 col-sm-3">
                    <input type="text" name="cl_user" value="<%=pub.trimNull((String)ht.get("cl_user"))%>" class="input-text">
                </div>--%>
                <label class="form-label col-xs-4 col-sm-1">报废时间：</label>
                <div class="formControls col-xs-8 col-sm-3">
                    <input type="text" name="bf_time" class="input-text Wdate"  autocomplete="off" onclick="WdatePicker({dateFmt:'yyyy-MM-dd'})" value="<%=pub.trimNull((String)ht.get("bf_time"))%>" >
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-1">报废原因：</label>
                <div class="formControls col-xs-8 col-sm-9">
                <textarea name="bf_reason" cols="" rows="2" class="textarea" placeholder=""
                          dragonfly="true"><%=pub.trimNull((String) ht.get("bf_reason"))%></textarea>
                </div>
            </div>
        </div>
    </form>
    <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>
</article>
<script>
    function saveForm(){
        $.ajax({
            type: "POST",
            url: "./action.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('操作失败'+msg, {
                        icon: 5,
                        time: 2000 //2秒关闭（如果不配置，默认是3秒）
                    }, function () {
                    });
                }
            }
        });
    }
</script>