<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DrugForm.aspx.cs" Inherits="Medical.MBase.SysDrug.DrugForm" %>

<!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="../../Scripts/jquery.ajaxQueue.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><input type="text" id="dCode" runat="server" class="pt-readonly" /></td>
            <th>类别</th>
            <td>
                <select id="dCategory" runat="server">
                    <option value="西药">西药</option>
                    <option value="中药">中药</option>
                    <option value="卫生材料">卫生材料</option>
                </select>
            </td>
        </tr>
        <tr>
            <th>条码</th>
            <td><input type="text" id="dBarcode" runat="server"/></td>
            <th>药名名称</th>
            <td><input type="text" id="dName" runat="server"/></td>
        </tr>
        <tr>
            <th>规格</th>
            <td><input type="text" id="dSpec" runat="server"/></td>
            <th>包装单位</th>
            <td><input type="text" id="dSubsection" runat="server"/></td>
        </tr>
        <tr>
            <th>最小单位</th>
            <td><input type="text" id="dUnit" runat="server"/></td>
            <th>生产企业</th>
            <td colspan='3'><input type="text" id="dFactory"  runat="server"/></td>
        </tr>
        <tr>
            <th>单位数量</th>
            <td><input type="text" id="dQuantum" runat="server"/></td>
            <th>剂型</th>
            <td><input type="text" id="dType" runat="server"/></td>
        </tr>
        <tr>
            <th>材质</th>
            <td><input type="text" id="dMaterial" runat="server"/></td>
            <th>安全库存</th>
            <td><input type="text" id="dSafetyStock" runat="server"/></td>
        </tr>
        
        <tr>
            <th>售购比</th>
            <td><input type="text" id="dPriceProportion" runat="server" /></td>
            <th>药品说明</th>
            <td><input type="text" id="dRemark" 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 Drug.validate()" onclick="btnSave_Click" />
        <input type="button" class="pt-button active" onclick="top.OpenClose('Drug_Form')" value="关闭" />
    </div>
    </form>
    <script type="text/javascript">
        var Drug = (function() {

            function init() {
                readonly();
                bindEvents();
                bindAutocomplete();
                barcodeInputReadonly($("#dCategory").find("option:selected").text());
            }
            function readonly() {
                $(".pt-readonly").focus(function() {
                    this.blur();
                });
            }
            function validate() {
                var Quantum = $("#dQuantum").val() * 1;
                if (!$("#dSafetyStock").val()) {
                    top.showTipsMsg('安全库存不能为空!', 1, 3000);
                    return false;
                }
                if (!$("#dQuantum").val()) {
                    top.showTipsMsg('单位数量不能为空！', 1, 3000);
                    return false;
                }
                if (isNaN(Quantum)) {
                    top.showTipsMsg('您在单位数量文本内输入的不是数字，请重新输入!', 1, 3000);
                    return false;
                }
                if (!$("#dPriceProportion").val()) {
                    top.showTipsMsg('售购比不能为空!', 1, 3000);
                    return false;
                }
                return true;
            }
            function bindAutocomplete() {
                $("#dFactory").autocomplete("../../MCommon/QueryDrug.ashx?action=getFactory", {
                    title: "factory",
                    max: 10,
                    width: 400,
                    formatItem: function(row, i, max) {
                        return "dFactory";
                    },
                    formatMatch: function(row, i, max) {
                        return "dFactory";
                    },
                    formatResult: function(row) {
                        return row.dFactory;
                    }
                });

                $("#dType").autocomplete("../../MCommon/QueryDrug.ashx?action=getType", {
                    title: "type",
                    max: 10,
                    formatItem: function(row, i, max) {
                        return "dType";
                    },
                    formatMatch: function(row, i, max) {
                        return "dType";
                    },
                    formatResult: function(row) {
                        return row.dType;
                    }
                });

                $("#dUnit").autocomplete("../../MCommon/QueryDrug.ashx?action=getUnit", {
                    title: "unit",
                    max: 10,
                    formatItem: function(row, i, max) {
                        return "dUnit";
                    },
                    formatMatch: function(row, i, max) {
                        return "dUnit";
                    },
                    formatResult: function(row) {
                        return row.dUnit;
                    }
                });
                
                $("#dSubsection").autocomplete("../../MCommon/QueryDrug.ashx?action=getSubsection", {
                    title: "Subsection",
                    max: 10,
                    formatItem: function(row, i, max) {
                        return "dSubsection";
                    },
                    formatMatch: function(row, i, max) {
                        return "dSubsection";
                    },
                    formatResult: function(row) {
                        return row.dSubsection;
                    }
                });
            }
            function bindEvents() {
                $("#dCategory").change(function() {
                    barcodeInputReadonly($(this).find("option:selected").text());
                });
//                $("#dSafetyStock").click(function(e) {
//                    var target = $(e.target);
//                    top.openDialog("/MBusiness/SysLoss/inputAmount.aspx?key=" + $("#cCode").val() + "&oldValue=" + $("#dSafetyStock").val(), "inputAmount", '损耗数量-编辑', 300, 130, 50, 50, callInputAmountCallBack);
//                });
            }
            function barcodeInputReadonly(selectedText) {
                if (selectedText == "中药" || selectedText == "材料") {
                    $("#dBarcode").addClass("pt-readonly").bind("focus", function() {
                        this.blur();
                    });
                } else {
                    $("#dBarcode").removeClass("pt-readonly").unbind("focus");
                }
            }
            init();
            return { validate: validate }
        })();
    </script>
</body>
</html>

