<%--
  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();
    DateFormat df = new SimpleDateFormat("yyyyMMdd");
    Pub pub = new Pub();
    Connection conn = null;
    Vector v_list = null;
    Vector v_list_1 = null;
    Date sys_date = new Date();
    String id = df.format(sys_date)+sys_date.getTime();
    String page_number = pub.trimNull(request.getParameter("page_number"));
    if ("".equals(page_number)) page_number = "1";
    String page_size = pub.trimNull(request.getParameter("page_size"));
    String pd_id = pub.trimNull(request.getParameter("pd_id"));
    if("".equals(pd_id)){
        pd_id=id;
    }
    String action = pub.trimNull(request.getParameter("action"));
    if("".equals(action)){
        action="add";
    }
    if ("".equals(page_size)) page_size = "10";
    String pd_number_view="";
    String pd_user_view="";
    String pd_b_time_view="";
    String beizhu_view="";
    List list_1 = new ArrayList();
    List list_2 = new ArrayList();
    Hashtable ht=null;
    try {
        StringBuffer sb = new StringBuffer();
        StringBuffer sb_list = new StringBuffer();
        sb.append("select * from zc_pd where pd_id=? ");
        sb.append(" order by add_time desc");

        if(!"add".equals(action)){
            sb_list.append("select  t1.*,t2.pd_b_time from zc_register t1" +
                    "  join zc_pd t2 on t1.zc_id=t2.zc_id where t2.pd_id=?");
            list_2.add(pd_id);
        }else{
            sb_list.append("select  t1.*,t2.pd_b_time from zc_register t1" +
                    " left join zc_pd t2 on t1.zc_id=t2.zc_id where t1.zc_status ='0'");//不查什么状态的。。。
        }
        sb_list.append(" order by t1.add_time desc");
        list_1.add(pd_id);
        conn = com.censoft.db.DBUtil.getConnection();
        v_list = cf.doQuery(conn, sb.toString(),null, list_1.toArray());
        v_list_1 = cf.doQuery(conn, sb_list.toString(),null, list_2.toArray());
        if (v_list == null) {
            out.println("查询出错" + cf.getMsg());
            return;
        }
        if (v_list_1 == null) {
            out.println("查询出错" + cf.getMsg());
            return;
        }
        if (v_list.size()>0&&!"add".equals(action)) {
            ht=(Hashtable)v_list.get(0);
            pd_number_view=pub.trimNull((String)ht.get("pd_number"));
            pd_user_view=pub.trimNull((String)ht.get("pd_user"));
            pd_b_time_view=pub.trimNull((String)ht.get("pd_b_time"));
            beizhu_view=pub.trimNull((String)ht.get("beizhu"));
        }
%>
<article class="page-container" style="overflow: hidden;">
    <form class="form form-horizontal" id="form-admin-add">
        <input type="hidden" name="action" id="action" value="<%=action%>"/>
        <input type="hidden" name="update_id" value=""/>
        <input type="hidden" name="pd_id" value="<%=pd_id%>"/>
        <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-2">盘点单号：</label>
                <div class="formControls col-xs-8 col-sm-3" id="xm_id" >
                    <input type="text" name="pd_number" id="pd_number"  value="<%=pd_number_view%>" class="input-text ">
                </div>
                <label class="form-label col-xs-4 col-sm-2">盘点人：</label>
                <div class="formControls col-xs-8 col-sm-3">
                    <input type="text" name="pd_user" id="pd_user"  value="<%=pd_user_view%>" class="input-text ">
                </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-3">
                    <input type="text" name="pd_b_time" id="pd_b_time" onclick="WdatePicker({dateFmt:'yyyy-MM-dd'})" value="<%=pd_b_time_view%>" class="input-text Wdate">
                </div>
                <label class="form-label col-xs-4 col-sm-2">盘点说明：</label>
                <div class="formControls col-xs-8 col-sm-3">
                    <input type="text" name="beizhu" id="beizhu"  value="<%=beizhu_view%>" class="input-text">
                </div>
            </div>
        </div>
        <div class="table-list">
            <table class="table  table-hover table-bg">
                <thead>
                <tr class="text-c">
                    <th width="50px">
                        <input id="checkboxAll" type="checkbox" onclick="checkAll(this);"></input>
                    </th>
                    <th width="50px">条码</th>
                    <th width="50px">资产名称</th>
                    <th width="50px">国标大类</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 zc_id_view=pub.trimNull((String)ht_view.get("zc_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_gj_type_view=pub.trimNull((String)ht_view.get("zc_gj_type"));
                            String gg_type_view=pub.trimNull((String)ht_view.get("gg_type"));
                            String sb_type_view=pub.trimNull((String)ht_view.get("sb_type"));
                            String jiazhi_view=pub.trimNull((String)ht_view.get("jiazhi"));
                            String cw_date_view=pub.trimNull((String)ht_view.get("cw_date"));
                            String pd_b_time=pub.trimNull((String)ht_view.get("pd_b_time"));
                            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 >
                        <input type="checkbox" class="info" id="zc_ids"
                               name="zc_ids" value="<%=zc_id_view%>" />
                    </td>
                    <td><%=i+1%>
                    </td>
                    <td>
                        <%=zc_name_view%>
                    </td>
                    <td>
                        <%=zc_gj_type_view%>
                    </td>
                    <td>
                        <%=gg_type_view%>
                    </td>
                    <td>
                        <%=sb_type_view%>
                    </td>
                    <td>
                        <%=jiazhi_view%>
                    </td>
                    <td>
                        <%=pd_b_time%>
                    </td>
                    <td>
                        <%=cw_date_view%>
                    </td>
                </tr>
                <%
                        }
                    }
                %>
                </tbody>
            </table>
        </div>
    </form>
</article>
<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('tj');" value="&nbsp;&nbsp;申请&nbsp;&nbsp;">
--%>
        <input class="btn btn-primary radius btn-green" type="button" onclick="javascript:saveForm('save');" value="&nbsp;&nbsp;保存&nbsp;&nbsp;">
    </div>
</div>
<script>
    var checkAll = function (checkbox) {
        $(".info").prop("checked", checkbox.checked);
    }
    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() {
        parent.searchModel();
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);
    }
    function saveForm(type){
        if(type=='tj'){
            $("#action").val("shenqing");
        }
		var check_len=$('input[name="zc_ids"]:checked').length;
        if(check_len==0){
            layer.msg('请至少选择一条数据', {
                icon: 5,
                time: 3000
            })
            return false;
        }
		if($("#pd_number").val()==''){
            layer.msg('盘点单号不能为空', {
                icon: 5,
                time: 3000
            })
            return false;
        }
		if($("#pd_user").val()==''){
            layer.msg('盘点人不能为空', {
                icon: 5,
                time: 3000
            })
            return false;
        }
		if($("#pd_b_time").val()==''){
            layer.msg('盘点时间不能为空', {
                icon: 5,
                time: 3000
            })
            return false;
        }
        $.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('操作失败'+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) {
            }
        }
    }
%>