/*--------------------------文档信息-------------------------------------------
///功能：      科目明细
///创建人：  王群
///创建时间：2011年05月31日
///修改人：  --------------
///修改时间：--------------
///详细说明：--------------
-----------------------------------------------------------------------------*/
//页面全局变量的定义
var strTableP0517 = "Tp0517";               //表格ID
var strPageP0517 = "divPageP0517";     //分页层的ID
var objPageParamP0517 = { sortfield: "", orderby: "", where: "", flag: 1 };     //分页控件使用
/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓**事件方法 开始**↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/

//页面加载方法
function pageLoad_P0517() {
    try {
        //选择日期范围
        dateExtent_P0517();
        //加载科目信息
        loadKmData_P0517();
        //从后台取得列名
        objConfig = ParseData(window.external.DoOptions(strTableP0517, "GetTableConfig", "{}"));
        //格式化表中的数据
        setData_P0517(objConfig.colModel);
        //创建表格
        createGrid(strTableP0517, objConfig.colNames, objConfig.colModel, [], null, null, true, null);
        //调整表格的高度
        resizeGrid(strTableP0517, true, true);
        //创建分页
        createPage(strPageP0517, strTableP0517);
        //加载表格数据(触发查询按钮的点击事件)
        searchDataClick_P0517(true);
    } catch (e) { }
}

// 绑定查询事件
function searchDataClick_P0517(flag) {
    try {
        var objResult = {};             //存放当前的查询结果
        if (!$("#cmbKmP0517").cihoComboTree("getValue")) {        //"当前选择的客户不存在，赋值为【科目】！"
            $("#cmbKmP0517").cihoComboTree("setValue", "");
        }

        //获取查询条件
        objPageParamP0517.where = mySearchWhereJson();
        if (flag == true) {
            $("#" + strTableP0517).footerData("set", { rn: "合计",
                addje: "&nbsp;",
                jianshaoje: "&nbsp;"
            }, false);
            resizeGridScroll(strTableP0517);               //调整表格的列宽度
        }
        else {
            if ($("#cmbKmP0517").cihoComboTree("getValue") == "") {

            }
            else {
                objResult = loadGridData_Page(objPageParamP0517);
                var intIDLength = $("#" + strTableP0517).getDataIDs();
                if (intIDLength.length > 0) {
                    $("#" + strTableP0517).footerData("set", { rn: "合计",
                        addje: parseFloat(objResult.addje).toFixed(window.parent.strMoneyPlace),
                        jianshaoje: parseFloat(objResult.jianshaoje).toFixed(window.parent.strMoneyPlace)
                    }, false);
                }
                else {
                    $("#" + strTableP0517).footerData("set", { rn: "合计",
                        addje: "&nbsp;",
                        jianshaoje: "&nbsp;"
                    }, false);
                }
            }
        }
        //释放内存
        objResult = null;
    } catch (e) { }
}

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

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓**自定义方法 开始**↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
//格式化表中的数据
function setData_P0517(objP0517) {
    for (var i = 0; i < objP0517.length; i++) {
        if (objP0517[i].name == "addje" || objP0517[i].name == "jianshaoje") {      //money的格式化
            objP0517[i].formatter = formatterP0517Money;
        }
        if (objP0517[i].name == "yuje") {       //余额的格式化
            objP0517[i].formatter = formatterP0517Money1;
        }
    }
}

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

//给日期加载数据
function dateExtent_P0517() {
    dateExtentCalculation("本月", "dateStartTimeP0517", "dateEndTimeP0517");
    $("#cmbDateExtentP0517").combobox({
        width: _iWidth100,
        listWidth: _iWidth100,
        valueField: "dm",
        textField: "mc",
        panelHeight: 102,
        editable: false,
        onSelect: function (option) {
            dateExtentCalculation(option.dm, "dateStartTimeP0517", "dateEndTimeP0517");
        },
        enterDown: function () {
            dateExtentCalculation($("#cmbDateExtentP0517").combobox("getValue"), "dateStartTimeP0517", "dateEndTimeP0517");
        }
    });
    $("#cmbDateExtentP0517").combobox("loadData",
    [{ dm: "本月", mc: "本月", selected: true },
    { dm: "上一月", mc: "上一月" },
    { dm: "本周", mc: "本周" },
    { dm: "过去三个月", mc: "过去三个月" },
    { dm: "本年", mc: "本年"}]);
}

//加载科目信息
function loadKmData_P0517() {
    var item = $("#cmbKmP0517");
    //加载数据
    var objResult = ParseData(window.external.DoOptions("Tp0517", "GetComboBoxData", '{}')).Records;
    objResult.unshift({ "id": "", "text": "全部科目" });
    $("#cmbKmP0517").cihoComboTree('loadData', objResult);
    //释放内存
    item = null;
    objResult = null;
}

//合计行的计算
//function totalCompute_P0517() {
//    var addMoney = 0;                                                                           //增加金额的默认值为0
//    var cutMmoney = 0;                                                                         //减少金额的默认

//给增加额和减少金额格式化money
function formatterP0517Money(cellvalue, options, rowObject) {
    if (!cellvalue || cellvalue == "0") {
        return "&nbsp;"
    }
    else {
        return parseFloat(cellvalue).toFixed(window.parent.strMoneyPlace);
    }
}

//给期初余额的格式化
function formatterP0517Money1(cellvalue, options, rowObject) {
    if (isNaN(parseFloat(cellvalue))) {
        cellvalue = 0;
    }
    return parseFloat(cellvalue).toFixed(window.parent.strMoneyPlace);
}

//切换tab时刷性科目
function refreshMyCombobox(strModels) {
    for (var i = 0; i < strModels.length; i++) {
        if (strModels[i] == "TKjkm") {
            var objKm = ParseData(window.external.DoOptions("Tp0517", "GetComboBoxData", "{}")).Records;
            if (objKm != null && objKm != "{}") {
                objKm.unshift({ "id": "", "text": "全部科目" });
                $("#cmbKmP0517").cihoComboTree("loadData", objKm);
            }
        }
    }
    //释放内存
    objKm = null;
}

//获取查询条件
function mySearchWhereJson() {
    var strWhereJson = "";                     //存放查询条件的变量
    strWhereJson += "{\"sdate\":\"" + $("#dateStartTimeP0517").val() + "\",";
    strWhereJson += "\"edate\":\"" + $("#dateEndTimeP0517").val() + "\",";
    strWhereJson += "\"kmdm\":\"" + $("#cmbKmP0517").cihoComboTree("getValue") + "\",";
    strWhereJson += "\"bh\":\"" + $("#cmbKmP0517").cihoComboTree("getBH") + "\"}";
    return strWhereJson.replace(/[{}]/g, "");
}

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