/*--------------------------文档信息-------------------------------------------
///功能：      利润分析报表
///创建人：  王群
///创建时间：2011年05月31日
///修改人：  --------------
///修改时间：--------------
///详细说明：--------------
-----------------------------------------------------------------------------*/
//页面全局变量的定义
var strTableP0514 = "Tp051401";          //表格ID
var objSelRowP0514 = {};                     //选择行的数据
var intSelRowIDP0514 = 0;                  //选择行的ID
var objWhereJsonP0514 = {};              //记录查询时的条件
var sortfieldP0514 = "";                      //记录一下默认排序字段
var orderbyP0514 = "";                      //记录一下默认的排序方式
var strRecordWhereJson = "";           //记录一下排序的查询条件

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

//页面加载的事件
function pageLoad_P0514() {
    try {
        //给快捷日期加载数据
        dateExtent_P0514()
        //给客户绑定数据
        cliend_P0514();
        //给药品绑定数据
        medicinal_P0514();
        //给职员绑定数据
        member_P0514();
        //查询方法的加载
        searchDataClick_P0514();
    } catch (e) { }
}

//查询事件
function searchDataClick_P0514(flag) {
    try {
        var strWhereJson = "";      //存放当前查询条件
        var objConfig = {};            //存放当前的列配置对象
        var objResult = {};             //存放当前的查询结果
        var showDatas = {};           //存放当前的病状图中要显示的数据对象
        if (!$("#cliendP0514").combobox("getValue")) {      //当前选择的客户不存在，就给赋值为【全部客户】           
            $("#cliendP0514").combobox("setValue", "");
        }

        if (!$("#medicinalP0514").combobox("getValue")) {     // "当前选择的药品不存在，就给赋值为【全部药品】"
            $("#medicinalP0514").combobox("setValue", "");
        }
        if (!$("#memberP0514").combobox("getValue")) {       // "当前选择的药品不存在，就给赋值为【全部销售员】"
            $("#memberP0514").combobox("setValue", "");
        }
        if (flag == "2") {
        }
        else {
            if ($("#cmbDateExtentP0514").combobox("getValue") == "历史以来") {     //历史以来时向后台传空值
                strWhereJson += "{\"sdate\":\"0\",";
                strWhereJson += "\"edate\":\"0\",";
            }
            else {                                                                              //其他情况就传指定的日期
                strWhereJson += "{\"sdate\":\"" + $("#dateStartTimeP0514").val() + "\",";
                strWhereJson += "\"edate\":\"" + $("#dateEndTimeP0514").val() + "\",";
            }
            strWhereJson += "\"khdm\":\"" + $("#cliendP0514").combobox("getValue") + "\",";
            strWhereJson += "\"spdm\":\"" + $("#medicinalP0514").combobox("getValue") + "\",";
            strWhereJson += "\"zydm\":\"" + $("#memberP0514").combobox("getValue") + "\"}";
            strRecordWhereJson = strWhereJson;                          //记录查询条件
        }
        //获取列配置
        objConfig = ParseData(window.external.DoOptions(strTableP0514, "GetTableConfig", "{}"));
        setData_P0514(objConfig.colModel);     //格式化数据

        //按客户的显示的简洁模式和详细模式
        if (strTableP0514 == "Tp051401" || strTableP0514 == "Tp051402") {
            //切换模式的时候默认按客户名称的倒序排序
            if (flag != "2") {
                sortfieldP0514 = "";
                orderbyP0514 = "";
            }
            var strCollateWhereJson = strRecordWhereJson.replace("}", ",\"sortfield\":\"" + sortfieldP0514 + "\",\"orderby\":\"" + orderbyP0514 + "\"}");
            //创建表格
            objResult = ParseData(window.external.DoOptions(strTableP0514, "GetList", strCollateWhereJson));
            if (flag == "2") {
                loadTreeData(strTableP0514, objResult.Records);
            }
            else {
                createTreeGrid_P0514(strTableP0514, objConfig.colNames, objConfig.colModel, objResult.Records, "khmc");
                loadTreeData(strTableP0514, objResult.Records);
            }
        }
        else {
            //根据查询条件getList一下
            objResult = ParseData(window.external.DoOptions(strTableP0514, "GetList", strWhereJson));
            createGrid_P0514(strTableP0514, objConfig.colNames, objConfig.colModel, objResult.Records);
        }
        if (flag !== "1") {
            if (flag == "2") {
            }
            else {
                //创建饼状图=== 选择表格
                showDatas = ParseData(strSelectP0514());
                if (showDatas == "") {
                    createBing_P0514([{}]);
                }
                else {
                    createBing_P0514(showDatas);
                }
            }
        }
        if (flag !== "2") {
            //调整表格列宽度的自适应度
            resizeMyGrid(strTableP0514);
        }
        //释放内存
        strWhereJson = null;
        objConfig = null;
        objResult = null;
        showDatas = null;
    } catch (e) { }
}

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

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

//。。。。。。。。。组织饼图显示的数据比例。。。。。。。。。。。。
function strSelectP0514() {
    var getLr = "[";
    var objTable = $("#" + strTableP0514);
    if (strTableP0514 == "Tp051401" || strTableP0514 == "Tp051402") {    //客户的简洁模式和详细模式
        var arrIds = $("#" + strTableP0514).getDataIDs();
        for (var i = 0; i < arrIds.length; i++) {
            var objTr = objTable.getRowData(arrIds[i]);
            if (objTable.getCell(arrIds[i], "parent") == "0") {
                if (i != 0) {
                    getLr += ",";
                }
                if (objTr.khmc != "") {
                    if (objTr.lrje.substr(0, 1) == "-") {
                        getLr += "{'name':'" + objTr.khmc + "','y':" + (objTr.lrje) * (-1) + ",'isMinus':'-'}";
                    }
                    else {
                        getLr += "{'name':'" + objTr.khmc + "','y':" + objTr.lrje + ",'isMinus':''}";
                    }
                }
            }
        }
    }
    else if (strTableP0514 == "Tp051403" || strTableP0514 == "Tp051404") {      //商品的简洁模式和详细模式
        var arrIds = $("#" + strTableP0514).getDataIDs();
        for (var i = 0; i < arrIds.length; i++) {
            var objTr = $("#" + strTableP0514).getRowData(arrIds[i]);
            if (objTr.spmc != "") {
                if (i != 0) {
                    getLr += ",";
                }
                if (objTr.spmc) {
                    if (objTr.lrje.substr(0, 1) == "-") {
                        getLr += "{'name':'" + objTr.spmc + "','y':" + (objTr.lrje) * (-1) + ",'isMinus':'-'}";
                    }
                    else {
                        getLr += "{'name':'" + objTr.spmc + "','y':" + (objTr.lrje) + ",'isMinus':''}";
                    }
                }
            }
        }
    }
    else if (strTableP0514 == "Tp051405" || strTableP0514 == "Tp051406") {      //职员的简洁模式和详细模式
        var arrIds = $("#" + strTableP0514).getDataIDs();
        for (var i = 0; i < arrIds.length; i++) {
            var objTr = $("#" + strTableP0514).getRowData(arrIds[i]);
            if (i != 0) {
                getLr += ",";
            }
            if (objTr.zymc) {
                if (objTr.lrje.substr(0, 1) == "-") {
                    getLr += "{'name':'" + objTr.zymc + "','y':" + (objTr.lrje) * (-1) + ",'isMinus':'-'}";
                }
                else {
                    getLr += "{'name':'" + objTr.zymc + "','y':" + (objTr.lrje) + ",'isMinus':''}";
                }
            }
        }
    }
    getLr += "]";
    return getLr;
}

//创建饼状图
function createBing_P0514(strDatas) {
    var chart = {};
    chart = new Highcharts.Chart({
        chart: {
            renderTo: 'divBingTu',
            plotBackgroundColor: null,
            plotBorderWidth: null,
            plotShadow: false,
            backgroundColor: "none"
        },
        title: {
            text: ''
        },
        tooltip: {
            formatter: function () {
                return '<b>' + this.point.name + '</b>: ' + this.point.isMinus + parseFloat(this.y).toFixed(window.parent.strMoneyPlace);
            }
        },
        plotOptions: {
            pie: {
                allowPointSelect: true,
                cursor: 'pointer',
                size: "90%",
                dataLabels: {
                    enabled: false,
                    color: '#000000',
                    connectorColor: '#000000',
                    formatter: function () {
                        return '<b>' + this.point.name + '</b>: ' + this.point.isMinus + parseFloat(this.y).toFixed(window.parent.strMoneyPlace);
                    }
                }
            }
        },
        series: [{
            type: 'pie',
            name: 'Browser share',
            data: strDatas
        }]
    });
    //释放内存
    chart = null;
}

//格式化表格中的数据
function setData_P0514(objP0514) {
    for (var i = 0; i < objP0514.length; i++) {
        //                if (objP0514[i].name == "srje" || objP0514[i].name == "zcje" || objP0514[i].name == "lrje" || objP0514[i].name == "yysj"
        //                || objP0514[i].name == "ytfy" || objP0514[i].name == "xssr" || objP0514[i].name == "qtsr" || objP0514[i].name == "cgcb"
        //                || objP0514[i].name == "flsr" || objP0514[i].name == "jyfy") {      //money的格式化
        //                    objP0514[i].formatter = formatterP0514Money;
        //                }
        //                if (objP0514[i].name == "szbl") {       //百分比的格式化
        //                    objP0514[i].formatter = formatterP0514Percent;
        //                }
        if (objP0514[i].name == "khmc" || objP0514[i].name == "spmc" || objP0514[i].name == "parent"
        || objP0514[i].name == "zymc" || objP0514[i].name == "level" || objP0514[i].name == "isLeaf"
        || objP0514[i].name == "bh" || objP0514[i].name == "xh" || objP0514[i].name == "kmdm"
        || objP0514[i].name == "spdm" || objP0514[i].name == "zydm") {          //这些列不进行格式化
        }
        else {
            if (objP0514[i].name == "szbl") {       //百分比的格式化
                objP0514[i].formatter = formatterP0514Percent;
            }
            else {
                objP0514[i].formatter = formatterP0514Money;      //格式化成Money的格式
            }
        }
    }
}

//给快捷日期加载数据
function dateExtent_P0514() {
    //设置默认日期为本月
    dateExtentCalculation("本月", "dateStartTimeP0514", "dateEndTimeP0514");
    //添加选择事件
    $("#cmbDateExtentP0514").combobox({
        width: _iWidth80,
        listWidth: _iWidth80,
        valueField: "dm",
        textField: "mc",
        panelHeight: 182,
        editable: false,
        onSelect: function (option) {
            dateExtentCalculation(option.dm, "dateStartTimeP0514", "dateEndTimeP0514");
        },
        onChange: function (newValue, oldValue) {
            if (newValue) {
                if (newValue == "历史以来") {          //日期为历史以来时 后边的日期灰化掉
                    $("#dateStartTimeP0514").attr("disabled", true);
                    $("#dateEndTimeP0514").attr("disabled", true);
                }
                else {                                                  //其他的情况日期是可以操作的
                    $("#dateStartTimeP0514").attr("disabled", false);
                    $("#dateEndTimeP0514").attr("disabled", false);
                }
            }
        },
        enterDown: function () {
            dateExtentCalculation($("#cmbDateExtentP0514").combobox("getValue"), "dateStartTimeP0514", "dateEndTimeP0514");
        }
    });
    //加载数据
    $("#cmbDateExtentP0514").combobox("loadData",
    [{ dm: "本月", mc: "本月", selected: true },
    { dm: "上一月", mc: "上一月" },
    { dm: "过去三个月", mc: "过去三个月" },
    { dm: "本季度", mc: "本季度" },
    { dm: "本年", mc: "本年" },
    { dm: "上一年", mc: "上一年" },
    { dm: "前年", mc: "前年" },
    { dm: "历史以来", mc: "历史以来"}]);
}

//给客户加载数据
function cliend_P0514() {
    $("#cliendP0514").combobox({
        width: _iWidth90,
        listWidth: _iWidth90,
        valueField: "dm",
        textField: "mc",
        onblur: function () {
            if ($("#cliendP0514").combobox("getText") == "") {
                $("#cliendP0514").combobox("setValue", "");
            }
        },
        onfocus: function () {
            if ($("#cliendP0514").combobox("getText") == "全部客户") {
                $("#cliendP0514").combobox("setText", "");
            }
        },
        afterChange: function (newValue, newText) {
            $(this).combobox("setText", newText.replace(/&nbsp;/g, ""));
        }
    });
    //加载数据
    var objProvider = getComboboxData("Tkhxx2");
    if (objProvider == "{}") {
        objProvider = [];
    }
    objProvider.unshift({ "dm": "", "mc": "全部客户", "selected": true });
    $("#cliendP0514").combobox("loadData", objProvider);
}

//给药品绑定数据
function medicinal_P0514() {
    $("#medicinalP0514").combobox({
        width: _iWidth90,
        listWidth: _iWidth90,
        valueField: "dm",
        textField: "mc",
        onblur: function () {
            if ($("#medicinalP0514").combobox("getText") == "") {
                $("#medicinalP0514").combobox("setValue", "");
            }
        },
        onfocus: function () {
            if ($("#medicinalP0514").combobox("getText") == "全部药品") {
                $("#medicinalP0514").combobox("setText", "");
            }
        },
        enterDown: function () { }
    });

    //加载数据
    var objDrug = getComboboxData("Tspxx2");
    if (objDrug == "{}") {
        objDrug = [];
    }
    objDrug.unshift({ "dm": "", "mc": "全部药品", "selected": true });
    $("#medicinalP0514").combobox("loadData", objDrug);
}

//给职员绑定数据
function member_P0514() {
    $("#memberP0514").combobox({
        width: _iWidth90,
        listWidth: _iWidth90,
        valueField: "dm",
        textField: "mc",
        onblur: function () {
            if ($("#memberP0514").combobox("getText") == "") {
                $("#memberP0514").combobox("setValue", "");
            }
        },
        onfocus: function () {
            if ($("#memberP0514").combobox("getText") == "全部销售员") {
                $("#memberP0514").combobox("setText", "");
            }
        },
        enterDown: function () { }
    });

    //加载数据
    var objDrug = getComboboxData("TZyxx2");
    objDrug.push({ "dm": "-1", "mc": "其他销售员" });
    if (objDrug == "{}") {
        objDrug = [];
    }
    objDrug.unshift({ "dm": "", "mc": "全部销售员", "selected": true });
    $("#memberP0514").combobox("loadData", objDrug);
}

//日期范围修改方法
function dateTimeChange_P0514() {
    if ($("#cmbDateExtentP0514").combobox("getText") != "自定义") {
        $("#cmbDateExtentP0514").combobox("setValue", "");
        $("#cmbDateExtentP0514").combobox("setText", "自定义");
    }
}

//总利润的计算
function totalCompute_P0514() {
    //计算总利润数据
    var intMoney = parseFloat($("#" + strTableP0514).getCol("lrje", false, "sum")).toFixed(window.parent.strMoneyPlace);
    $("#Ddd").text(intMoney);
}

//树总利润的计算
function totalCompute_P0514P() {
    //设置合计行的数据
    $("#" + strTableP0514).setGridParam({
        gridComplete: function () {
            var objTable = $("#" + strTableP0514);
            var arrIds = objTable.getDataIDs();
            var intMoney = 0;
            for (var i = 0; i < arrIds.length; i++) {
                if (objTable.getCell(arrIds[i], "parent") == 0) {
                    intMoney += parseFloat(objTable.getCell(arrIds[i], "lrje"));
                }
            }
            $("#Ddd").text(intMoney.toFixed(window.parent.strMoneyPlace));
        }
    });
}


//查询方法
function searchFunction(newTables) {
    if (newTables) {
        if (newTables == "Tp051401") {  //按客户的简洁模式
            if ($("#Eee").attr("class") == "profit_xx") {
                strTableP0514 = "Tp051401";
                $("#divTp051401").css("display", "");
                $("#divTp051402").css("display", "none");
                $("#divTp051403").css("display", "none");
                $("#divTp051404").css("display", "none");
                $("#divTp051405").css("display", "none");
                $("#divTp051406").css("display", "none");
                resizeMyTbl("Tp051401");
            }
            else {      //按客户的详细模式
                strTableP0514 = "Tp051402";
                $("#divTp051401").css("display", "none");
                $("#divTp051402").css("display", "");
                $("#divTp051403").css("display", "none");
                $("#divTp051404").css("display", "none");
                $("#divTp051405").css("display", "none");
                $("#divTp051406").css("display", "none");
                resizeMyTbl("Tp051402");
            }
        }

        else if (newTables == "Tp051403") {  //按商品的简洁模式
            if ($("#Eee").attr("class") == "profit_xx") {
                strTableP0514 = "Tp051403";
                $("#divTp051401").css("display", "none");
                $("#divTp051402").css("display", "none");
                $("#divTp051403").css("display", "");
                $("#divTp051404").css("display", "none");
                $("#divTp051405").css("display", "none");
                $("#divTp051406").css("display", "none");
                resizeMyTbl("Tp051403");
            }
            else {      //按商品的详细模式
                strTableP0514 = "Tp051404";
                $("#divTp051401").css("display", "none");
                $("#divTp051402").css("display", "none");
                $("#divTp051403").css("display", "none");
                $("#divTp051404").css("display", "");
                $("#divTp051405").css("display", "none");
                $("#divTp051406").css("display", "none");
                resizeMyTbl("Tp051404");
            }
        }

        else if (newTables == "Tp051405") {   //按职员的简洁模式
            if ($("#Eee").attr("class") == "profit_xx") {
                strTableP0514 = "Tp051405";
                $("#divTp051401").css("display", "none");
                $("#divTp051402").css("display", "none");
                $("#divTp051403").css("display", "none");
                $("#divTp051404").css("display", "none");
                $("#divTp051405").css("display", "");
                $("#divTp051406").css("display", "none");
                resizeMyTbl("Tp051405");
            }
            else {      //按职员的详细模式
                strTableP0514 = "Tp051406";
                $("#divTp051401").css("display", "none");
                $("#divTp051402").css("display", "none");
                $("#divTp051403").css("display", "none");
                $("#divTp051404").css("display", "none");
                $("#divTp051405").css("display", "none");
                $("#divTp051406").css("display", "");
                resizeMyTbl("Tp051406");
            }
        }
        searchDataClick_P0514();
    }
    else {
        if (strTableP0514 == "Tp051401") {  //按客户的详细模式
            strTableP0514 = "Tp051402";
            $("#divTp051401").css("display", "none");
            $("#divTp051402").css("display", "");
            $("#divTp051403").css("display", "none");
            $("#divTp051404").css("display", "none");
            $("#divTp051405").css("display", "none");
            $("#divTp051406").css("display", "none");
            $("#Eee").removeClass("profit_xx");
            $("#Eee").addClass("profit_jj");
            resizeMyTbl("Tp051402");
        }
        else if (strTableP0514 == "Tp051402") {   //按客户的简洁模式
            strTableP0514 = "Tp051401";
            $("#divTp051401").css("display", "");
            $("#divTp051402").css("display", "none");
            $("#divTp051403").css("display", "none");
            $("#divTp051404").css("display", "none");
            $("#divTp051405").css("display", "none");
            $("#divTp051406").css("display", "none");
            $("#Eee").removeClass("profit_jj");
            $("#Eee").addClass("profit_xx");
            resizeMyTbl("Tp051401");
        }
        else if (strTableP0514 == "Tp051403") {   //按商品的详细模式
            strTableP0514 = "Tp051404";
            $("#divTp051401").css("display", "none");
            $("#divTp051402").css("display", "none");
            $("#divTp051403").css("display", "none");
            $("#divTp051404").css("display", "");
            $("#divTp051405").css("display", "none");
            $("#divTp051406").css("display", "none");
            $("#Eee").removeClass("profit_xx");
            $("#Eee").addClass("profit_jj");
            resizeMyTbl("Tp051404");
        }
        else if (strTableP0514 == "Tp051404") { //按商品的简洁模式
            strTableP0514 = "Tp051403";
            $("#divTp051401").css("display", "none");
            $("#divTp051402").css("display", "none");
            $("#divTp051403").css("display", "");
            $("#divTp051404").css("display", "none");
            $("#divTp051405").css("display", "none");
            $("#divTp051406").css("display", "none");
            $("#Eee").removeClass("profit_jj");
            $("#Eee").addClass("profit_xx");
            resizeMyTbl("Tp051403");
        }
        else if (strTableP0514 == "Tp051405") {     //按职员的详细模式
            strTableP0514 = "Tp051406";
            $("#divTp051401").css("display", "none");
            $("#divTp051402").css("display", "none");
            $("#divTp051403").css("display", "none");
            $("#divTp051404").css("display", "none");
            $("#divTp051405").css("display", "none");
            $("#divTp051406").css("display", "");
            $("#Eee").removeClass("profit_xx");
            $("#Eee").addClass("profit_jj");
            resizeMyTbl("Tp051406");
        }
        else if (strTableP0514 == "Tp051406") {     //按职员的简洁模式
            strTableP0514 = "Tp051405";
            $("#divTp051401").css("display", "none");
            $("#divTp051402").css("display", "none");
            $("#divTp051403").css("display", "none");
            $("#divTp051404").css("display", "none");
            $("#divTp051405").css("display", "");
            $("#divTp051406").css("display", "none");
            $("#Eee").removeClass("profit_jj");
            $("#Eee").addClass("profit_xx");
            resizeMyTbl("Tp051405");
        }
        searchDataClick_P0514("1");
    }
}

//money的格式化
function formatterP0514Money(cellvalue, options, rowObject) {
    if (isNaN(parseFloat(cellvalue))) {
        cellvalue = 0;
    }
    return parseFloat(cellvalue).toFixed(window.parent.strMoneyPlace);
}

//szbl格式化
function formatterP0514Percent(cellvalue, options, rowObject) {
    if (isNaN(parseFloat(cellvalue))) {
        cellvalue = "0";
    }
    return (parseFloat(cellvalue) * 100).toFixed(window.parent.strPercentPlace) + "%";
}

//调整表格的高度
function resizeMyTbl(strTableId) {
    //表格宽度
    $("#" + strTableId).jqGrid("setGridWidth", window.parent.document.documentElement.clientWidth);
    //调整无法调整的div的宽度
    $("#gbox_" + strTableId).find("div").each(function () {
        if ($(this).width() > window.parent.document.documentElement.clientWidth) {
            $(this).width(window.parent.document.documentElement.clientWidth);
        }
    });
    //调整表格所属层的高度
    //设定饼状图所在层的高度：过滤条件47，简洁模式40，总利润30，表格180
    $(".overflo").css("height", window.parent.document.documentElement.clientHeight - _iHtMenu - _iHtTab - _iHtCopyright - 47 - 26);
}

//当基本资料数据有修改时 刷新相关的combobox
function refreshMyCombobox(strModels) {
    for (var i = 0; i < strModels.length; i++) {
        var data = getComboboxData(strModels[i] + "2");     //从后台取得数据集
        if (strModels[i] == "Tkhxx") {
            data.unshift({ dm: "", mc: "全部客户", "selected": true });
            reLoadCombobox("cliendP0514", data);
        }
        if (strModels[i] == "Tspxx") {
            data.unshift({ dm: "", mc: "全部药品", "selected": true });
            reLoadCombobox("medicinalP0514", data);
        }
        if (strModels[i] == "TZyxx") {
            data.unshift({ dm: "", mc: "全部销售员", "selected": true });
            data.push({ dm: "-1", mc: "其他销售员" });
            reLoadCombobox("memberP0514", data);
        }
    }
}


//调整表格的自适应宽度
function resizeMyGrid(tbId) {
    var gridHeight = $("#" + tbId).height();      //取得当前的表格的高度
    var gridWidth = $("#" + tbId).width();         //取得表格的宽度
    var bdivHeight = $("#" + tbId).parent().parent().height();      //取得表格父层的高度
    var bdivWidth = $("#" + tbId).parent().parent().width();        //取得表格父层的高度
    var colWidth = $("table tr th:visible:last", "#gbox_" + tbId).width();
    var myTableHeight = window.parent.document.documentElement.clientHeight     //取得当前窗体的高度
    if (myTableHeight > 692) {
        var obj = $(".overflo");
        if (obj[0].scrollHeight > 568) {
            $("table", "#gbox_" + tbId).width(gridWidth - 16).parent().width(gridWidth - 16);
            $("table tr", "#gbox_" + tbId).each(function () {
                $(this).find("td:visible:last,th:visible:last").width(colWidth - 16);
            });
        }
    }
    else {
        $("table", "#gbox_" + tbId).width(gridWidth - 16).parent().width(gridWidth - 16);
        $("table tr", "#gbox_" + tbId).each(function () {
            $(this).find("td:visible:last,th:visible:last").width(colWidth - 16);
        });
    }
    //释放内存
    gridHeight = null;
    gridWidth = null;
    bdivHeight = null;
    bdivWidth = null;
    colWidth = null;
    myTableHeight = null;
}

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓**自定义 结束**↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
/*-------------------------------------------------------------
功能：创建普通表格
*****①strTableID：表格的ID
*****②objColNames:表格需要显示的列名
*****③objColModel：表格的列配置
*****④objDataRecords：表格中需要加载的数据
-----------------------------------------------------------------*/
function createGrid_P0514(strTableID, objColNames, objColModel, objDataRecords) {
    $("#" + strTableID).GridUnload();       //删除旧表格
    if (objDataRecords == "{}") {               //当数据集为空时，格式化数据集的空值
        objDataRecords = [];
    }
    //生成表格
    $("#" + strTableID).jqGrid({
        datatype: "local",
        sortname: "id",
        colNames: objColNames,
        colModel: objColModel,
        data: objDataRecords,
        rownumbers: true,
        autowidth: true,
        footerrow: false,
        gridview: true,
        rownumWidth: 30,
        cellsubmit: "clientArray",
        height: "100%",
        //height: "100",
        rowNum: objDataRecords.length
    }).parent(".ui-jqgrid-bdiv").siblings().css("width", "100%");
    //设置行号列的名称
    //$("table.ui-jqgrid-htable th:first", $("#gbox_" + strTableID)).text("序号");
    $("#" + strTableID).setLabel("rn", "序号");
    //设置表格高度
    resizeMyTbl(strTableID);
    //总利润的计算
    totalCompute_P0514();
}

/*-----------------------------------------------------------------------------
///     ①strGridID:表格ID
///     ②objColNames:表格列名
///     ③objColModel:表格列属性
///     ④objJsonDatas:表格数据源，Json格式
///     ⑤strColExpandKey:伸缩列的字段名称
///     ⑥funcGridComplete:表格的gridComplete事件方法，此参数类型是方法对象
///     ⑦funcSelectRow:表格的onSelectRow事件方法，此参数类型是方法对象
///-----------------------------------------------------------------------------*/
function createTreeGrid_P0514(strTableID, objColNames, objColModel, objJsonDatas, strColExpandKey) {
    $("#" + strTableID).GridUnload();           //删除旧表格
    if (objJsonDatas == "{}") {                      //当数据集为空时，格式化数据集的空值
        objJsonDatas = [];
    }
    //创建表格
    $("#" + strTableID).jqGrid({
        datatype: "local",
        colNames: objColNames,
        colModel: objColModel,
        data: objJsonDatas[0],
        treeGrid: true,
        treedatatype: "local",
        treeGridModel: 'adjacency',
        ExpandColumn: strColExpandKey,
        ExpandColClick: false,
        editable: true,
        rownumbers: false,
        rowNum: 999999,
        sortname: "khdm",
        localReader: { id: "bh" },
        ExpandColClick: true,
        autowidth: true,
        height: "100%",
        onSortCol: function (index, colindex, sortorder) {
            sortfieldP0514 = index;                             //排序字段
            orderbyP0514 = sortorder;                       //排序顺序
            searchDataClick_P0514("2");                     //加载数据
            return "stop";
        }
    }).parent(".ui-jqgrid-bdiv").siblings().css("width", "100%");
    //设置表格的高度
    resizeMyTbl(strTableID);
    //树总利润的计算
    totalCompute_P0514P();
}