<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title></title>
    <!--引用样式-->
    <link href="../../Content/Default/jquery-ui-1.8.10.custom.css" rel="stylesheet" type="text/css" />
    <link href="../../Content/Default/ui.jqgrid.css" rel="stylesheet" type="text/css" />
    <link href="../../Content/Default/combo.css" rel="stylesheet" type="text/css" />
    <link href="../../Content/Default/combobox.css" rel="stylesheet" type="text/css" />
    <link href="../../Content/style.css" rel="stylesheet" type="text/css" />
    <!--引用角本-->
    <script src="../../Scripts/lib/jquery-1.4.4.min.js" type="text/javascript"></script>
    <script src="../../Scripts/lib/jquery-ui-1.8.10.custom.min.js" type="text/javascript"></script>
    <script src="../../Scripts/lib/grid.locale-cn.js" type="text/javascript"></script>
    <script src="../../Scripts/lib/jquery.jqGrid.min.js" type="text/javascript"></script>
    <script src="../../Scripts/lib/jquery.autonum.min.js" type="text/javascript"></script>
    <script src="../../Scripts/lib/jquery.combo_ciho.js" type="text/javascript"></script>
    <script src="../../Scripts/lib/jquery.combobox.js" type="text/javascript"></script>
    <script src="../../Scripts/lib/jquery.layoutpanel.js" type="text/javascript"></script>
    <script src="../../Scripts/msgBox.js" type="text/javascript"></script>
    <script src="../../Scripts/msg.js" type="text/javascript"></script>
    <script src="../../Scripts/06/p0602.js" type="text/javascript"></script>
    <script src="../../Scripts/06/p060201.js" type="text/javascript"></script>
    <script src="../../Scripts/06/p060202.js" type="text/javascript"></script>
    <script src="../../Scripts/common.js" type="text/javascript"></script>
    <script language="javascript" type="text/javascript">
        //页面全局变量的定义
        var strTableP0602 = "TSpxx"; //表格ID
        var strSelRowIDP0602 = "";  //选择行的索引
        var objSelRowP0602 = {};    //选择行的数据

        //页面加载事件
        $(function () {
            strClassType = "0"; //分类设置使用

            //本页面定义方法
            pageLoad_P0602();

            //改变窗口大小时，改变表格的高度和宽度。
            window.onresize = function () {
                //隐藏浮动层
                $(".operate").hide();

                //调整表格的大小
                resizeGrid(strTableP0602, false, false);
                //有滚动条时改变表格宽度
                resizeGridScroll(strTableP0602);
            }
        });

        //保存按钮调用方法
        function saveMyData(strDialog, strType, strTable) {
            try {
                if (strTable == "TSpxx") {
                    saveData_P0602(strType);        //保存药品
                }
                else if (strTable == "TFlsz") {
                    saveData_P06020101(strType);    //保存分类设置
                }
                else if (strTable == "TYpdw") {
                    saveData_P06020201(strType);    //保存单位
                }
            } catch (e) { }
        }

        //窗口关闭按钮调用方法
        function closeMyDlg(strDialog, strType, strTable) {
            //窗口内容变量后，提示用户是否保存
            if ($("#" + strDialog + "_divform").data("change")) {
                window.parent.cihoAlert(msg.other.haveChange, msgBox.dlgBtn.YesNoCancel, function (result) {
                    if (result == msgBox.dlgRst.Yes) {
                        saveMyData(strDialog, strType, strTable);   //保存数据
                    }
                    else if (result == msgBox.dlgRst.No) {
                        //关闭窗口
                        cihoDlgClose(strDialog);
                    }
                });
            }
            else {
                //关闭窗口
                cihoDlgClose(strDialog);
            }
        }

        //页面加载方法
        function pageLoad_P0602() {
            try {
                var objConfig = ParseData(window.external.DoOptions(strTableP0602, "GetTableConfig", "{}"));
                var objResult = ParseData(window.external.DoOptions(strTableP0602, "GetList", "{}"));

                //格式化数据列
                addColFormat_P0602(objConfig.colModel);

                //创建表格，并加载数据
                createGrid(strTableP0602, objConfig.colNames, objConfig.colModel, objResult.Records, null, null, false, dblClickRow_P0602);
                //手动排一下序
                $("#" + strTableP0602).sortGrid("a2", false, "asc");
                //表格事件的添加
                addGridEvent_P0602();

                //调整表格的大小
                resizeGrid(strTableP0602, false, false);

                //有滚动条时改变表格宽度
                resizeGridScroll(strTableP0602);

                //释放内存
                objConfig = null;
                objResult = null;
            } catch (e) { }
        }

        //数据行的双击事件
        function dblClickRow_P0602() {
            //隐藏浮动层
            $(".operate").hide();
            showDialog_P0602("2");
        }

        //删除数据
        function deleteData_P0602() {
            try {
                //提示用户是否删除数据
                window.parent.cihoAlert(msg.del.delConfirm, msgBox.dlgBtn.YesNo, function (result) {
                    if (result == msgBox.dlgRst.Yes) {
                        //删除数据库中的信息
                        var objResult = ParseData(window.external.DoOptions(strTableP0602, 'Delete', "{\"spdm\":\"" + objSelRowP0602.spdm + "\"}"));

                        //删除数据是否有返回值
                        if (objResult) {
                            //删除成功后的操作
                            if (objResult.ReturnCode == 0) {
                                //删除页面中的信息
                                $("#" + strTableP0602).jqGrid("delRowData", strSelRowIDP0602);

                                //更新下拉框数据的全局变量
                                changeComboZt("Tspxx");

                                //有滚动条时改变表格宽度
                                resizeGridScroll(strTableP0602);

                                strSelRowIDP0602 = "";
                                objSelRowP0602 = {};
                            }
                            else {
                                window.parent.cihoAlert(objResult.MSG);
                            }
                        }

                        //释放内存
                        objResult = null;
                    }
                });
            } catch (e) { }
        }

        //修改状态
        function upateState_P0602(strState) {
            try {
                var strDataJson = "{\"spdm\":\"" + objSelRowP0602.spdm + "\",\"zt\":\"" + strState + "\"}";
                //修改数据库状态
                var objResult = ParseData(window.external.DoOptions(strTableP0602, 'ChangeStat', strDataJson));

                if (objResult) {
                    //修改数据的状态
                    if (objResult.ReturnCode == 0) {
                        if (strState == "true") {
                            $("#" + strTableP0602).jqGrid("setCell", strSelRowIDP0602, "zt", "True");
                        }
                        else if (strState == "false") {
                            $("#" + strTableP0602).jqGrid("setCell", strSelRowIDP0602, "zt", "False");
                        }

                        //更新下拉框数据的全局变量
                        changeComboZt("Tspxx");
                    }
                    else {
                        window.parent.cihoAlert(objResult.MSG);
                    }
                }

                //释放内存
                strDataJson = null;
                objResult = null;
            } catch (e) { }
        }

        //表格事件的添加
        function addGridEvent_P0602() {
            $("#" + strTableP0602).setGridParam({
                //当前选择行数据取得
                onSelectRow: function (rowid) {
                    //当前选择行数据
                    strSelRowIDP0602 = rowid;
                    objSelRowP0602 = $(this).getRowData(rowid);

                    //浮动按钮内容
                    if (objSelRowP0602.zt == "已启用") {
                        createFloatButton.call(this, rowid, "<a onclick=\"showDialog_P0602('2')\">修改</a>-<a onclick=\"deleteData_P0602()\">删除</a>-<a onclick=\"upateState_P0602('false')\">停用</a>");
                    }
                    else if (objSelRowP0602.zt == "已停用") {
                        createFloatButton.call(this, rowid, "<a onclick=\"showDialog_P0602('2')\">修改</a>-<a onclick=\"deleteData_P0602()\">删除</a>-<a onclick=\"upateState_P0602('true')\">启用</a>");
                    }
                }
            });
        }

        //格式化数据列
        function addColFormat_P0602(objColModel) {
            for (var intI = 0; intI < objColModel.length; intI++) {
                switch (objColModel[intI]["name"]) {
                    case "a13":
                    case "a14":
                    case "a15":
                    case "a23":
                        objColModel[intI].formatter = function (cellvalue, options, rowObject) {
                            if (cellvalue) {
                                return parseFloat(cellvalue).toFixed(window.parent.strPricePlace);
                            }
                            else {
                                return "&nbsp;";
                            }
                        }
                        break;
                    case "zt":
                        objColModel[intI].formatter = function (cellvalue, options, rowObject) {
                            if (cellvalue == "True") {
                                return "已启用";
                            }
                            else if (cellvalue == "False") {
                                return "已停用";
                            }
                            else {
                                return "&nbsp;";
                            }
                        }
                        break;
                }
            }
        }
    </script>
</head>
<body>
    <div class="title_bar">
        <div class="topi">
            <div class="column">
                <div id="added">
                    <ul class="topnav">
                        <li><a href="#" onclick="showDialog_P0602('1')">&nbsp;&nbsp;新&nbsp;&nbsp;&nbsp;增&nbsp;&nbsp;</a>
                            <ul class="addnav">
                                <li><a href="#" onclick="showDialog_P060201()">分类设置</a></li>
                                <li><a href="#" onclick="showDialog_P060202()">单位设置</a></li>
                                <!--<li><a href="#" onclick="alert('导入数据！');">导入</a></li>-->
                            </ul>
                        </li>
                    </ul>
                </div>
                <div class="dedt">
                </div>
                <div class="clr">
                </div>
            </div>
            <div>
            </div>
        </div>
        <div class="clr">
        </div>
    </div>
    <div class="mation">
        <div class="mation_div">
            <table id="TSpxx">
            </table>
        </div>
    </div>
    <!--药品基本信息窗口层-->
    <div id="divP0602">
    </div>
    <!--分类设置/单位设置窗口层-->
    <div id="divP060201">
    </div>
    <!--分类设置/单位子窗口层-->
    <div id="divP06020101">
    </div>
    <!--消息提示窗口-->
    <div id="divMessage">
    </div>
</body>
</html>
