<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="InventoryList.aspx.cs" Inherits="Medical.MBusiness.SysInventory.InventoryList" %>

<%@ Register Src="../../Controls/Pager.ascx" TagName="Pager" TagPrefix="ucPager" %>
<%@ Register Src="../../Controls/LoadButton.ascx" TagName="LoadButton" TagPrefix="ucLoadButton" %>
<!DOCTYPE html>
<html>
<head>
    <title><%=ModuleName%></title>
    <link href="../../css/style.css" rel="stylesheet" type="text/css" />
    <script src="../../Scripts/jquery-1.7.2.min.js" type="text/javascript"></script>
    <script src="../../Scripts/My97DatePicker/My97DatePicker/WdatePicker.js" type="text/javascript"></script>
    <script src="../../js/myLib/jsHelper_Form.js" type="text/javascript"></script>
    <script src="../../js/myLib/Pager.js" type="text/javascript"></script>
    <script src="../../js/myLib/Grid.js" type="text/javascript"></script>
</head>
<body>
    <div class="pt-panel">
        <strong><%=ModuleName%></strong>
        <form name="fCondition" class="pt-padding">
            <ucLoadButton:LoadButton ID="LoadButton1" runat="server"/>
            <dl>
                <dt>仓库名称</dt>
                <dd><select id="warehouse" name="warehouse" runat="server"></select></dd>
            </dl>
            <dl>
                <dt>药品名称</dt>
                <dd><input type="text" name="name" /></dd>
            </dl>
            <dl>
                <dt>规格</dt>
                <dd><input type="text" name="spec" /></dd>
            </dl>
            <dl>
                <dt>批号</dt>
                <dd><input type="text" name="batch" /></dd>
            </dl>
            <dl>
                <dt>类别</dt>
                <dd>
                    <select name="category">
                        <option value="全部">全部</option>
                        <option value="西药">西药</option>
                        <option value="中药">中药</option>
                    </select>
                </dd>
            </dl>
            <dl>
                <dt>生产企业</dt>
                <dd><input type="text" name="factory" /></dd>
            </dl>
            <dl>
                <dt style="width:100px">有效期截止时间</dt>
                <dd><input type="text" name="validEnd" onclick="WdatePicker()"  /></dd>
            </dl>
            <dl>
                <dt style="width:120px">只显示无库存药品</dt>
                <dd><input type="checkbox" name="isAmount" value="0" /></dd>
            </dl>
            <dl>
                <dt>金额合计：</dt>
                <dd><span id="totalMoney" class="pt-tip">0.00</span>元</dd>
           </dl>
        </form>
    </div>
    <div class="pt-panel pt-below">
        <strong>查询一览</strong>
        <div class="pt-grid_frame">
            <table class="pt-grid" id="grid">
                <thead>
                    <tr>
                        <th style="width:170px">操作</th>
                        <th>药品编码</th>
                        <th>条码</th>
                        <th>药品名称</th>
                        <th>规格</th>
                        <th>包装单位</th>
                        <th>最小单位</th>
                        <th>剂型</th>
                        <th>材质</th>
                        <th>生产企业</th>
                        <th>批号</th>
                        <th>有效期</th>
                        <th>采购价</th>
                        <th>单价</th>
                        <th>库存量</th>
                        <th>仓库名称</th>
                        <th>金额</th>
                    </tr>
                </thead>
                <tbody></tbody>
            </table>
        </div>
        <div class="pt-tip">友情提示：采购价按包装单位计，单价按最小单位计。</div>
        <ucPager:Pager ID="gridPager" runat="server" />
    </div>
    
    <script>
        (function() {
            var url = "InventoryList.aspx",
            grid = new Grid({ id: "grid", url: url, pager: new Pager("gridPager"), bindFun: bindData }),
            title = "清理无库存药品",
            dialogUrl = "/MBusiness/SysInventory/InventoryForm.aspx",
            dialogFormName = "Inventory_Form",
            dialogUpdateUrl = "/MBusiness/SysInventory/InventoryUpdateForm.aspx",
            dialogUpdateFormName = "InventoryUpdate_Form",
            listbutton = '<%=Medical.MCommon.PageHelper.GetListButton() %>';

            function init() {
                grid.search();
                bindMoney();
                bindEvents();
            }
            function bindEvents() {
                $("#btnQuery").click(function() {
                    grid.search(true);
                    bindMoney();
                });
                $("#btnClear").click(function() {
                    top.openDialog(dialogUrl, dialogFormName, title, 800, 450, 50, 50);
                });
                $('input[type="text"]').keydown(function(e) {
                    if (e.keyCode == 13) {
                        grid.search(true);
                        bindMoney();
                    }
                });
                grid.control.click(function(e) {
                    var target = $(e.target);
                    if (target.is("input") && !target.is(":disabled")) {
                        var data = target.parent().parent().data("data");
                        switch (target.val()) {
//                            case "查看":  
//                                top.openDialog(dialogUrl + "?type=view&key=" + data.iCode, dialogFormName, title + ' - 查看', 800, 530, 50, 50);  
//                                break;  
                            case "修改":
                                top.openDialog(dialogUpdateUrl + "?key=" + data.ID, dialogUpdateFormName, '库存查询' + ' - 编辑', 250, 100, 50, 50);
                                break;
//                            case "删除": 
//                                remove(data); 
//                                break; 
                            case "删除":
                                var ID = data.ID,Name=data.Name,Batch=data.Batch;
                                $.get(url, { action: "querystatus", id: data.ID }, function(data) {
                                    if (data === "success") {
                                        top.showConfirmMsg("有未收费确认的处方中包含此药品信息，无法删除！", function(r) {
                                            if (r) {
                                            }
                                        });
                                    } else {
                                        remove(ID, Name, Batch);
                                    }
                                });
                                break;
                        }
                    }
                });
            }
            function remove(ID, Name, Batch) {
                top.showConfirmMsg("确定要删除[药品名称]为[" + Name + "]、[批号]为[" + Batch + "]的库存信息吗?", function(r) {
                    if (r) {
                        $.get(url, { action: "remove", id: ID }, function(data) {
                            if (data == "success") {
                                top.showTipsMsg('删除成功!', 0, 5000);
                                grid.search();
                            } else {
                                top.showTipsMsg('删除失败!', 1, 5000);
                            }
                        });
                    }
                });
            }
            function bindMoney() {
                var parms = { action: "getMoney" };
                $.get(url, $.parseJSON(form2JsonString(fCondition, parms)), function(data) {
                    $("#totalMoney").text(data);
                });
            }
            function bindData(tr, data) {
                tr.append($("<td>").html(listbutton))
                .append($("<td>").html(data.Code))
                .append($("<td>").html(data.Barcode))
                .append($("<td>").html(data.Name))
                .append($("<td>").html(data.Spec))
                .append($("<td>").html(data.Subsection))
                .append($("<td>").html(data.Unit))
                .append($("<td>").html(data.Type))
                .append($("<td>").html(data.Material))
                .append($("<td>").html(data.Factory))
                .append($("<td>").html(data.Batch))
                .append($("<td>").html(data.Valid))
                .append($("<td>").html(data.PurchasePrice))
                .append($("<td>").html(data.Price))
                .append($("<td>").html(data.Amount))
                .append($("<td>").html(data.Warehouse))
                .append($("<td>").html(data.Money));
            }
            init();
        })();
    </script>
</body>
</html>