<%--
  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="java.sql.Connection" %>
<%@ page import="java.util.*" %>
<%@ page import="com.censoft.common.db.ConnectionFactory" %>
<%@ page import="com.censoft.common.base.Pub" %>
<%@ page import="org.omg.CosCollection.IteratorInBetween" %>
<%@ page import="com.censoft.db.DBUtil" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.text.DateFormat" %>
<%!
    Pub pub = new Pub();

    public int getCounts(ConnectionFactory cf,Connection conn,String ly_id,String reg_id){
        StringBuffer sb = new StringBuffer();
        sb.append("select reg_id from zc_register" +
                " where zc_id in (select  zc_id from zc_ly where ly_id =?) and reg_id=?");

        Vector list = cf.doQuery(conn,sb.toString(),null,new Object[]{ly_id,reg_id});
        if(list==null){
            System.out.println("查询出错"+cf.getMsg());
            return 1;
        }
        return list.size();
    }
%>
<%
    ConnectionFactory cf = new ConnectionFactory();
    Pub pub = new Pub();
    Connection conn = null;
    Vector v_list_1 = null;
    String ly_id = pub.trimNull(request.getParameter("ly_id"));
    List list_s = new ArrayList();
    try {
        StringBuffer sb_list = new StringBuffer();
        sb_list.append("select distinct reg_id,zc_name,zc_fl,sb_type,counts,jiazhi,add_time from zc_register where zc_id in (select  zc_id from zc_ly where ly_id =?)");
        sb_list.append(" order by add_time desc");
        list_s.add(ly_id);
        conn = com.censoft.db.DBUtil.getConnection();
        v_list_1 = cf.doQuery(conn, sb_list.toString(),null, list_s.toArray());
        if (v_list_1 == null) {
            out.println("查询出错" + cf.getMsg());
            return;
        }
%>
<div class="table-list">
    <table class="table  table-hover table-bg">
        <thead>
        <tr class="text-c">
            <th width="30px">序号</th>
            <th width="50px">资产名称</th>
            <th width="50px">资产分类</th>
            <th width="50px">设备类型</th>
            <th width="50px">价值</th>
            <th width="50px">数量</th>
        </tr>
        </thead>
        <tbody>
        <%
            if (v_list_1 != null && v_list_1.size() > 0) {
                for (int i = 0; i < v_list_1.size(); i++) {
                    Hashtable ht_view = (Hashtable) v_list_1.get(i);
                    String reg_id_view=pub.trimNull((String)ht_view.get("reg_id"));
                    int counts=getCounts(cf,conn,ly_id,reg_id_view);
                    String zc_name_view=pub.trimNull((String)ht_view.get("zc_name"));
                    String zc_fl_view=pub.trimNull((String)ht_view.get("zc_fl"));
                    String sb_type_view=pub.trimNull((String)ht_view.get("sb_type"));
                    String jiazhi_view=pub.trimNull((String)ht_view.get("jiazhi"));
                    if("".equals(jiazhi_view)){
                        jiazhi_view="0";
                    }
                    int jiazhi = Integer.parseInt(jiazhi_view)*counts;

        %>
        <tr <%if(i%2==0){%>id="tr_doub"<%}else{%>id="tr_single"<%}%> class="text-c">
            <td><%=i+1%>
            </td>
            <td>
                <%=zc_name_view%>
            </td>
            <td>
                <%=zc_fl_view%>
            </td>
            <td>
                <%=sb_type_view%>
            </td>
            <td>
                <%=jiazhi%>
            </td>
            <td>
                <%=counts%>
            </td>
        </tr>
        <%
                }
            }
        %>
        </tbody>
    </table>
</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:closeIframe();" value="&nbsp;&nbsp;关闭&nbsp;&nbsp;">
    </div>
</div>
<script>
    function addRules(title, url) {
        var action = $("#action").val();
        if(action!='update'){
            layer.msg('请先保存再添加', {
                icon: 5,
                time: 2000 //2秒关闭（如果不配置，默认是3秒）
            }, function () {

            });
            return false;
        }
        var abc = layer.open({
            title:title,
            type: 2,
            content: url,
            maxmin: true
        });
        layer.full(abc);

    }
    function closeIframe() {
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);
    }
    function saveForm(type){
        if(type=='tj'){
            $("#action").val("shenqing");
        }
        $.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 () {
                            $("#action").val("update");
                            parent.searchModel();
                            //var index = parent.layer.getFrameIndex(window.name);
                            //parent.layer.close(index);
                        });
                } else {
                    layer.msg('操作失败', {
                        icon: 5,
                        time: 2000 //2秒关闭（如果不配置，默认是3秒）
                    }, function () {
                    });
                }
            }
        });
    }
    function deleteById(id,ly_id) {
        layer.confirm('确认要删除吗？', function (index) {
            $.ajax({
                type: "POST",
                url: "./action.jsp?action=delete&delete_id="+id+"&ly_id="+ly_id,
                data: $('#form-admin-add').serialize(),
                success: function (msg) {
                    if (msg.indexOf("success") >= 0) {
                        layer.msg('操作成功!', {icon: 1, time: 1000},
                            function () {
                                location.reload();
                                parent.searchModel();
                            });
                    } else {
                        layer.msg('操作失败', {
                            icon: 5,
                            time: 2000 //2秒关闭（如果不配置，默认是3秒）
                        }, function () {
                        });
                    }
                }
            });
        })
    }
</script>
<%
    } catch (Exception e) {
        out.println("查询异常" + e);
        return;
    } finally {
        if (conn != null) {
            try {
                conn.close();
            } catch (Exception e) {
            }
        }
    }
%>