/*-------------------------------文档信息-----------------------------------
///功能：药品分布
///创建人: 翟新乐
///创建时间：------------------------
///修改人：------------------------
///修改时间：-----------------------
///修改原因：-----------------------
///详细说明：-----------------------
---------------------------------------------------------------------*/
//页面全局变量的定义
var strTableP021502 = "Tp021502";    //表格ID

//页面加载方法
function pageLoad_P021502() {
    //加载客户信息
    loadCustomData_P021502();
    //查询数据
    searchData_P021502();
}

//加载grid
function createTable_P021502(strjson) {
    try {
        $("#" + strTableP021502).GridUnload(strTableP021502);
        var objConfig = ParseData(window.external.DoOptions(strTableP021502, "GetTableConfig", "{}"));
        //添加列格式化方法
        for (var i = 0; i < objConfig.colModel.length; i++) {
            objConfig.colModel[i].sortable = true;
            if (objConfig.colModel[i].name == "ysye") {
                objConfig.colModel[i].formatter = formatterP021502Money;
            }
        }
        //创建表格
        var objResult = ParseData(window.external.DoOptions(strTableP021502, "GetList", strjson));
        createGrid(strTableP021502, objConfig.colNames, objConfig.colModel, objResult.Records, null, gridComplete_P021502, true);

        resizeGrid(strTableP021502, true, false);
        resizeGridScroll(strTableP021502);
        objConfig = {};
        objResult = {};
    } catch (e) { }
}

//查询按钮的方法
function searchData_P021502() {
    try {
        var strStartTime = $(window.parent.document).find("#idIframe-21502").attr("sdate");
        var strEndTime = $(window.parent.document).find("#idIframe-21502").attr("edate");
        var strDrugID = $(window.parent.document).find("#idIframe-21502").attr("spdm");
        var strZyID = $(window.parent.document).find("#idIframe-21502").attr("zydm");
        //combobox的key不存在，赋值空
        if ($("#cmbCustomP021502").combobox("getValue") == undefined) {
            $("#cmbCustomP021502").combobox("setValue", "");
        }
        //查询条件的取得
        var strWhereJson = "";
        strWhereJson = "{\"sdate\":\"" + strStartTime + "\",";
        strWhereJson += "\"edate\":\"" + strEndTime + "\",";
        strWhereJson += "\"khdm\":\"" + $("#cmbCustomP021502").combobox("getValue") + "\",";
        strWhereJson += "\"spdm\":\"" + strDrugID + "\",";
        strWhereJson += "\"zydm\":\"" + strZyID + "\"}";
        createTable_P021502(strWhereJson);

        strEndTime = null;
        strDrugID = null;
        strWhereJson = null;
        strZyID = null;
        strStartTime = null;
    } catch (e) { }
}

//返回应收查询的方法
function pageBack_P021502() {
    //改变标签的Name
    $(window.parent.document).find("#span_215").text("应收查询");
    //改变标签Iframe的Src
    $(window.parent.document).find("#idIframe-21502").css("display", "none");
    $(window.parent.document).find("#idIframe-215").css("display", "block");
    $(window.parent.document).find("#idIframe-21502").attr("src", "");
}

//客户下拉框信息的加载
function loadCustomData_P021502() {
    $("#cmbCustomP021502").combobox({
        valueField: "dm",
        textField: "mc",
        onblur: function () {
            if ($("#cmbCustomP021502").combobox("getText") == "") {
                $("#cmbCustomP021502").combobox("setValue", "");
            }
        },
        onfocus: function () {
            if ($("#cmbCustomP021502").combobox("getText") == "全部客户") {
                $("#cmbCustomP021502").combobox("setText", "");
            }
        },
        enterDown: function () {
            //searchData_P021502();
        },
        afterChange: function (newValue, newText) {
            $(this).combobox("setText", newText.replace(/&nbsp;/g, ""));
        }
    });

    //加载数据
    var objProvider = getComboboxData('Tkhxx2');
    if (objProvider == "{}") {
        objProvider = [];
    }
    objProvider.unshift({ "dm": "", "mc": "全部客户" });
    $("#cmbCustomP021502").combobox("loadData", objProvider);
    $("#cmbCustomP021502").combobox("setValue", $(window.parent.document).find("#idIframe-21502").attr("khdm"));
    $("#cmbCustomP021502").combobox("setText", $(window.parent.document).find("#idIframe-21502").attr("khmc").replace(/&nbsp;/g, ""));
    objProvider = {};
}

//dj,je格式化money
function formatterP021502Money(cellvalue, options, rowObject) {
    if (isNaN(parseFloat(cellvalue))) {
        cellvalue = "&nbsp;";
    }
    return parseFloat(cellvalue).toFixed(window.parent.strMoneyPlace);
}

//合计
function gridComplete_P021502() {
    var intNumJe = 0;
    var arrIds = $("#" + strTableP021502).getDataIDs();
    if (!isNaN(parseFloat($("#" + strTableP021502).getCol("ysye", false, "sum")))) {
        intNumJe = $("#" + strTableP021502).getCol("ysye", false, "sum");
    }
    //var objFooterData = { rn: "合计", ysye: intNumJe };
    if (arrIds.length == 0) {
        $("#" + strTableP021502).footerData("set", { rn: "合计", ysye: "&nbsp;" }, false);
    }
    else {
        $("#" + strTableP021502).footerData("set", { rn: "合计", ysye: intNumJe }, true);
    }
    intNumJe = null;
    arrIds = null;
    //objFooterData = {};
}