/*--------------------------文档信息-------------------------------------------
///
///功能：    流向管理-流向单-建帐期初
///创建人：  王思波
///创建时间：2011年06月14日
///修改人：  --------------
///修改时间：--------------
///详细说明：--------------
///
-----------------------------------------------------------------------------*/

//页面全局变量
var strTableP020502 = "Tp020502";   //表格ID
var strDialogP020502 = "divP020502"; //建帐期初窗口ID

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓**事件方法 开始**↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/

//编辑流向单方法
function showDialog_P020502(strSaveFlag) {
    if ($("#spdm", "#" + strDialogP020501).combobox("getText") == "" || $("#khdm", "#" + strDialogP020501).combobox("getText") == "") {
        window.parent.cihoAlert(msg.cx.lxglJzqc1);
    }
    else if ($("#spdm", "#" + strDialogP020501).combobox("getValue") == undefined || $("#khdm", "#" + strDialogP020501).combobox("getValue") == undefined) {
        window.parent.cihoAlert(msg.cx.lxglJzqc2);
    }
    else {
        //弹出窗口的创建
        creatDiv_ShowDialog(strDialogP020502, "建帐期初", false, false, strTableP020502, 400);

        //创建窗口元素
        creatDialogItem_P020502();
    }

    //回车保存功能的添加
    $("#" + strDialogP020502).bind("keypress", function () { if (event.keyCode == 13) { saveData_P020502(); } });
}

/*↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑**事件方法 结束**↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑*/



/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓**自定义方法 开始**↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/

//添加表单元素到窗口中
function creatDialogItem_P020502() {
    var strDrugCode = $("#spdm", "#" + strDialogP020501).combobox("getValue");
    var strClientCode = $("#khdm", "#" + strDialogP020501).combobox("getValue");
    var strInitial = "";
    var strPrice = "";
    var strItemHtml = "";
    var objResult = ParseData(window.external.DoOptions(strTableP020502, "GetList", "{\"spdm\":\"" + strDrugCode + "\",\"khdm\":\"" + strClientCode + "\"}"));
    if (objResult.Records.length > 0) {
        if (objResult.Records[0].a1 != "") {
            strInitial = parseFloat(objResult.Records[0].a1).toFixed(window.parent.strCountPlace);
        }
        if (objResult.Records[0].a2 != "") {
            strPrice = parseFloat(objResult.Records[0].a2).toFixed(window.parent.strPricePlace);
        }
    }
    strItemHtml += "<ul>";
    strItemHtml += "    <li>";
    strItemHtml += "        配送客户：<input id=\"\" name=\"\" type=\"text\" disabled=\"true\" value=\"" + $("#khdm", "#" + strDialogP020501).combobox("getText") + "\" />";
    strItemHtml += "    </li>";
    strItemHtml += "    <li>";
    strItemHtml += "        药品：<input id=\"\" name=\"\" type=\"text\" disabled=\"true\" value=\"" + $("#spdm", "#" + strDialogP020501).combobox("getText") + "\" />";
    strItemHtml += "    </li>";
    strItemHtml += "    <li>";
    strItemHtml += "        <font color=\"red\">*</font>建帐期初：<input id=\"txtInitial\" name=\"\" type=\"text\" value=\"" + strInitial + "\" />";
    strItemHtml += "    </li>";
    strItemHtml += "    <li>";
    strItemHtml += "        <font color=\"red\">*</font>销售单价：<input id=\"txtPrice\" name=\"\" type=\"text\" value=\"" + strPrice + "\" />";
    strItemHtml += "    </li>";
    strItemHtml += "</ul>";
    $("#" + strDialogP020502 + "_divform").append(strItemHtml);
    //添加按钮
    strItemHtml = "<div class=\"clr\"></div>";
    strItemHtml += "<div class=\"box_btn_width\">";
    strItemHtml += "    <div class=\"box_btn\">";
    strItemHtml += "        <div class=\"btn01\"><a onclick=\"saveMyData('" + strDialogP020502 + "', 1, '" + strTableP020502 + "')\">保存退出</a></div>";
    strItemHtml += "    </div>";
    strItemHtml += "</div>";
    $(".pop_box", "#" + strDialogP020502).append(strItemHtml);

    //设置初始焦点
    $("#txtInitial", "#" + strDialogP020502).focus();

    //建账期初
    $("#txtInitial").autoNumeric({ mDec: window.parent.strCountPlace, aSep: "", aNeg: '-' }).focus(function () { this.select(); }).css("ime-mode", "disabled");
    //单价
    $("#txtPrice").autoNumeric({ mDec: window.parent.strPricePlace, aSep: "" }).focus(function () { this.select(); }).css("ime-mode", "disabled");

    //给控件添加变量事件
    $(":input", $("#" + strDialogP020502 + "_divform")).change(function () {
        $("#" + strDialogP020502 + "_divform").data("change", true);
    });

    //释放内存
    strDrugCode = null;
    strClientCode = null;
    strInitial = null;
    strPrice = null;
    strItemHtml = null;
    objResult = null;
}

//保存信息
function saveData_P020502() {
    if ($("#txtInitial").val() == "") {
        window.parent.cihoAlert(msg.other.lxglJzqc1, msgBox.dlgBtn.Ok, function () { $("#txtInitial").focus(); });
    }
    else if ($("#txtPrice").val() == "") {
        window.parent.cihoAlert(msg.other.lxglJzqc2, msgBox.dlgBtn.Ok, function () { $("#txtPrice").focus(); });
    }
    else {
        var strSpdm = $("#spdm", "#" + strDialogP020501).combobox("getValue");
        var strKhdm = $("#khdm", "#" + strDialogP020501).combobox("getValue");
        var strDataJson = "{\"spdm\":\"" + strSpdm + "\",\"khdm\":\"" + strKhdm + "\",\"a1\":\"" + $("#txtInitial").val() + "\",\"a2\":\"" + $("#txtPrice").val() + "\"}";
        var objResult = ParseData(window.external.DoOptions(strTableP020502, "Add", strDataJson));
        if (objResult.ReturnCode == 0) {
            getStockInitial_P020501(strSpdm, strKhdm);
            cihoDlgClose(strDialogP020502); //关闭窗口
        }
        else {
            window.parent.cihoAlert(objResult.MSG);
        }
    }
}

/*↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑**自定义方法 结束**↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑*/