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

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <link href="../../css/style.css" rel="stylesheet" type="text/css" />
    <link href="../../css/autocomplete.css" rel="stylesheet" type="text/css" />
    <script src="../../Scripts/jquery-1.7.2.min.js" type="text/javascript"></script>
    <script src="../../js/myLib/autoComplete.js" type="text/javascript"></script>  
</head>
<body>
    <form id="form1" style="padding:20px" runat="server">
    <table class="pt-edit">
        <tr>
            <th>仓库</th>
            <td><select id="cWarehouse" runat="server"></select></td>
            <th>药品编号/名称</th>
            <td><input type="text" id="cCode" runat="server" /></td>
            <th>条码</th>
            <td><input type="text" id="dBarcode" class="pt-readonly" runat="server" /></td>
        </tr>
        <tr>
            <th>药品名称</th>
            <td><input type="text" id="dName"  class="pt-readonly" runat="server" /></td>
            <th>规格</th>
            <td><input type="text" id="dSpec"  class="pt-readonly" runat="server" /></td>
            <th>剂型</th>
            <td><input type="text" id="dType"  class="pt-readonly" runat="server" /></td>
        </tr>
        <tr>
            <th>材质</th>
            <td><input type="text" id="dMaterial" class="pt-readonly" runat="server" /></td>   
            <th>包装单位</th>
            <td><input type="text" id="dSubsection"  class="pt-readonly" runat="server" /></td>
            <th>最小单位</th>
            <td><input type="text" id="dUnit"  class="pt-readonly" runat="server" /></td>
        </tr>
        <tr>
            <th>单位数量</th>
            <td><input type="text" id="dQuantum"  class="pt-readonly" runat="server" /></td>
            <th>生产企业</th>
            <td><input type="text" id="dFactory"  class="pt-readonly" runat="server" /></td>
            <th>批号</th>
            <td><input type="text" id="cBatch" class="pt-readonly"  runat="server" /></td>  
        </tr>
        <tr>         
            <th>采购价</th>
            <td><input type="text" id="cPurchasePrice" class="pt-readonly"  runat="server" /></td>
            <th>单价</th>
            <td><input type="text" id="cPrice" class="pt-readonly"  runat="server" /></td> 
            <th>金额</th>
            <td><input type="text" id="cMoney" class="pt-readonly"  runat="server" /></td>
        </tr>
        <tr>
            <th>库存数</th>
            <td><input type="text" id="cAmount" class="pt-readonly" value="0" runat="server" /></td> 
            <th>实盘数</th>
            <td><input type="text" id="cCheckAmount"  runat="server" onblur="calculationMoney()" /></td>
            <th>备注</th>
            <td><input type="text" id="cRemark" runat="server" /></td>
        </tr>
    </table>
    <div class="pt-padding" style="text-align:center">
        <asp:Button ID="btnSave" class="pt-button active" runat="server" Text="保存" OnClientClick="return CheckRecordForm.validate()" onclick="btnSave_Click" />
        <input type="button" class="pt-button active" onclick="top.OpenClose('CheckRecord_Form')" value="关闭" />
    </div>
    </form>
    <script>
        var CheckRecordForm = (function() {
            function init() {
                setPage();
                codeAutocomplete();
                bindEvents();
            }
            function setPage() {
                $(".pt-readonly").focus(function() {
                    this.blur();
                });
            }
            function codeAutocomplete() {
                var warehouse = $("#cWarehouse option:selected").text();
                $("#cCode").autocomplete("../../MCommon/QueryInventory.ashx?action=getDrug&warehouse=" + escape(warehouse), {
                    title: "code",
                    width: 600,
                    offsets: [-300, 0],
                    thead: [
                    
                        { text: "药品编码", width: 50 },
                        { text: "药品名称", width: 50 },
                        { text: "规格", width: 50 },
                        { text: "包装单位", width: 50 },
                        { text: "最小单位", width: 50 },
                        { text: "批号", width: 50 },
                        { text: "有效期", width: 50 },
                        { text: "剂型", width: 50 },
                        { text: "材质", width: 50 },
                        { text: "生产企业", width: 50 }
                    ],
                    formatItem: function(row, i, max) {
                        return "dCode,dName,dSpec,dSubsection,dUnit,iBatch,iValid,dType,dMaterial,dFactory";
                    },
                    formatMatch: function(row, i, max) {
                        return "dCode,dName,dSimpleCode";
                    }
                }).result(function(e, row) {
                    var target = $(e.target), tr = target.parent().parent();
                    target.val(row.dCode);
                    $("#dBarcode").val(row.dBarcode);
                    $("#dName").val(row.dName);
                    $("#dSpec").val(row.dSpec);
                    $("#dSubsection").val(row.dSubsection);
                    $("#dUnit").val(row.dUnit);
                    $("#dQuantum").val(row.dQuantum);
                    $("#dType").val(row.dType);
                    $("#dMaterial").val(row.dMaterial);
                    $("#dFactory").val(row.dFactory);
                    $("#cBatch").val(row.iBatch);
                    $("#cAmount").val(row.Amount);
                    $("#cPurchasePrice").val(row.iPurchasePrice);
                    $("#cPrice").val(row.iPrice);
                }).removeRelation(function(e) {
                    $("#dBarcode").val("");
                    $("#dName").val("");
                    $("#dSpec").val("");
                    $("#dUnit").val("");
                    $("#dType").val("");
                    $("#dMaterial").val("");
                    $("#dFactory").val("");
                    $("#cBatch").val("");
                    $("#cAmount").val("");
                    $("#cPurchasePrice").val("");
                    $("#cPrice").val("");
                });
            }
            function bindEvents() {
                $("#cWarehouse").change(function() {
                    codeAutocomplete();
                });
                $("#cCheckAmount").click(function(e) {
                    var target = $(e.target);
                    top.openDialog("/MBusiness/SysLoss/inputAmount.aspx?key=" + $("#cCode").val() + "&oldValue=" + $("#cCheckAmount").val(), "inputAmount", '损耗数量-编辑', 300, 130, 50, 50, callInputAmountCallBack);
                });
            }
            function callInputAmountCallBack(){
                $("#cCheckAmount").val(top.art.dialog.data("amount")); 
            }
            function validate() {
                if (!$("#cBatch").val()) {
                    top.showTipsMsg('批号不能为空!', 1, 3000);
                    return false;
                }
                if (!$("#cCheckAmount").val()) {
                    top.showTipsMsg('实盘数不能为空!', 1, 3000);
                    return false;
                }
                return true;
            }
            init();
            return { validate: validate};
        })();

        //计算金额
        function calculationMoney() {
            var purchasePrice = 0, //采购价
                amount = 0, //数量
                purchasePriceText = $("#cPurchasePrice").val(),
                amountText = $("#cCheckAmount").val(),
                moneyInput = $("#cMoney");
            if (purchasePriceText) {
                purchasePrice = purchasePriceText * 1;
            }
            if (amountText) {
                amount = amountText * 1;
            }
            moneyInput.val(purchasePrice * amount);
        }
    </script>
</body>
</html>

