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

//页面加载方法
function pageLoad_P021501() {
    //加载客户信息
    loadCustomData_P021501();
    //查询数据
    searchData_P021501();
}

//加载grid
function createTable_P021501(strjson) {
    try {
        $("#" + strTableP021501).GridUnload(strTableP021501);
        var objConfig = ParseData(window.external.DoOptions(strTableP021501, "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 = formatterP021501Money;
            }
        }
        //创建表格
        var objResult = ParseData(window.external.DoOptions(strTableP021501, "GetList", strjson));
        createGrid(strTableP021501, objConfig.colNames, objConfig.colModel, objResult.Records, null, gridComplete_P021501, true);
        resizeGrid(strTableP021501, true, false);
        resizeGridScroll(strTableP021501);
        objConfig = {};
        objResult = {};
    } catch (e) { }
}

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

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

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

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

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

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