/*--------------------------文档信息-------------------------------------------
///功能：      资金报表明细
///创建人：  王群
///创建时间：2011年05月31日
///修改人：  --------------
///修改时间：--------------
///详细说明：--------------
-----------------------------------------------------------------------------*/
//页面全局变量的定义
var strTableP051601 = "Tp051601";               //表格ID
var strPageP051601 = "divPageP051601";     //分页层的ID
var objSelRowP051601 = {};                           //选择行的数据
var intSelRowIDP051601 = 0;                         //选择行的ID
var objPageParamP051601 = { sortfield: "", orderby: "", where: "", flag: 1 };     //分页控件使用

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓**事件方法 开始**↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
//页面的加载
function pageLoad_P051601() {
    try {
        //选择日期范围
        loadDateExtent_P051601();
        //给查询类型加载数据
        loadTjData_P051601();
        //加载费用科目的数据
        loadFykmData_P051601();
        objConfig = ParseData(window.external.DoOptions(strTableP051601, "GetTableConfig", "{}"));
        //格式化表格中的数据
        setData_P051601(objConfig.colModel);
        //创建表格
        createGrid(strTableP051601, objConfig.colNames, objConfig.colModel, [], null, null, true, null);
        //调整表格的高度
        resizeGrid(strTableP051601, false, true);
        //创建分页
        createPage(strPageP051601, strTableP051601);
        //加载数据
        searchDataClick_P051601();
    } catch (e) { }
}

//查询按钮
function searchDataClick_P051601() {
    try {
        var objResult = {};             //存放当前的查询结果
        if (!$("#cmbFykmP051601").cihoComboTree("getValue")) {     // "当前选择的药品不存在，赋值为【科目】！"
            $("#cmbFykmP051601").cihoComboTree("setValue", "");
        }
        //清空选择行信息
        intSelRowIDP051601 = 0;
        objSelRowP051601 = {};
        //获取查询条件
        objPageParamP051601.where = mySearchWhereJson();
        objResult = loadGridData_Page(objPageParamP051601);
        var intIDLength = $("#" + strTableP051601).getDataIDs();
        if (intIDLength.length > 1) {
            $("#" + strTableP051601).footerData("set", { rn: "合计",
                zj: parseFloat(objResult.zjje).toFixed(window.parent.strMoneyPlace),
                js: parseFloat(objResult.jsje).toFixed(window.parent.strMoneyPlace)
            }, false);
        }
        else {
            $("#" + strTableP051601).footerData("set", { rn: "合计",
                zj: "&nbsp;",
                js: "&nbsp;"
            }, false);
        }
        //释放内存
        objResult = null;
    } catch (e) { }
}

//返回按钮的事件
function pageBack_P051601() {
    //改变标签的Name
    $(window.parent.document).find("#span_516").text("资金报表");
    //改变标签Iframe的Src
    $(window.parent.document).find("#idIframe-516").css("display", ""); //显示统计页面
    $(window.parent.document).find("#idIframe-51601").css("display", "none"); //隐藏明细页面
    $(window.parent.document).find("#idIframe-51601").attr("src", "");
}

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

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓**自定义方法 开始**↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
//格式化表格中的数据方法
function setData_P051601(objP051601) {
    for (var i = 0; i < objP051601.length; i++) {
        if (objP051601[i].name == "zj" || objP051601[i].name == "js") {     //数量的格式化
            objP051601[i].formatter = formatterP051601Money;
        }
        if (objP051601[i].name == "ye") {       //money的格式化
            objP051601[i].formatter = formatterP051601Money1;
        }
    }
}

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

//选择日期范围
function loadDateExtent_P051601() {
    //设置默认日期为本月
    dateExtentCalculation("本月", "dateStartTimeP051601", "dateEndTimeP051601");
    //添加选择事件
    $("#cmbDateExtentP051601").combobox({
        width: _iWidth120,
        listWidth: _iWidth120,
        valueField: "dm",
        textField: "mc",
        panelHeight: 102,
        editable: false,
        onSelect: function (option) {
            dateExtentCalculation(option.dm, "dateStartTimeP051601", "dateEndTimeP051601");
        },
        onChange: function (newValue, oldValue) {
            if (newValue && newValue == "历史以来") {       //当日期快捷为【历史以来时】，要把日期控件灰化掉
                $("#dateStartTimeP051601").attr("disabled", true);
                $("#dateEndTimeP051601").attr("disabled", true);
            }
            else {                                                                      //当日期快捷不为【历史以来时】，要把日期控件去掉灰化
                $("#dateStartTimeP051601").attr("disabled", false);
                $("#dateEndTimeP051601").attr("disabled", false);
            }
        },
        enterDown: function () {
            dateExtentCalculation($("#cmbDateExtentP051601").combobox("getValue"), "dateStartTimeP051601", "dateEndTimeP051601");
        }
    });
    //加载数据今天/上一年/前年/历史以来 系统默认“今天
    $("#cmbDateExtentP051601").combobox("loadData",
    [{ dm: "今天", mc: "今天", selected: true },
    { dm: "上一年", mc: "上一年" },
    { dm: "前年", mc: "前年" },
    { dm: "历史以来", mc: "历史以来"}]);
    var strDateItem = $(window.parent.document).find("#idIframe-51601").attr("dname");
    if (strDateItem != "") {
        $("#cmbDateExtentP051601").combobox("setValue", strDateItem);
        dateExtentCalculation(strDateItem, "dateStartTimeP051601", "dateEndTimeP051601");
    }
    else {
        var strStartTime = $(window.parent.document).find("#idIframe-51601").attr("sdate");
        var strEndTime = $(window.parent.document).find("#idIframe-51601").attr("edate");
        $("#cmbDateExtentP051601").combobox("setText", "自定义");
        $("#dateStartTimeP051601").val(strStartTime);
        $("#dateEndTimeP051601").val(strEndTime);
    }
}

//查询类型
function loadTjData_P051601() {
    $("#cmbTjP051601").combobox({
        width: _iWidth100,
        listWidth: _iWidth100,
        valueField: "dm",
        textField: "mc",
        editable: false
    });
    //加载数据
    $("#cmbTjP051601").combobox("loadData", [{ dm: "0", mc: "按日统计", selected: true }, { dm: "1", mc: "按月统计" }, { dm: "2", mc: "按年统计"}]);
}

//加载费用科目的数据
function loadFykmData_P051601() {
    //加载数据
    var objResult = ParseData(window.external.DoOptions("Tp051601", "GetComboBoxData", '{}')).Records;
    var strKmdm = $(window.parent.document).find("#idIframe-51601").attr("kmdm");
    objResult.unshift({ "id": "", "text": "全部科目" });
    $("#cmbFykmP051601").cihoComboTree('loadData', objResult);
    //设定默认值
    $("#cmbFykmP051601").cihoComboTree("setValue", strKmdm);
    //释放内存
    objResult = null;
    strKmdm = null;
}

//money格式化
function formatterP051601Money(cellvalue, options, rowObject) {
    if (!cellvalue || cellvalue == "0") {
        return "&nbsp;";
    }
    else {
        return parseFloat(cellvalue).toFixed(window.parent.strMoneyPlace);
    }
}

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

//comboTree的刷新
function refreshMyCombobox() {
    var objKm = ParseData(window.external.DoOptions("Tp051601", "GetComboBoxData", "{}")).Records;
    if (objKm != null && objKm != "{}") {
        objKm.unshift({ "id": "", "text": "全部科目" });
        $("#cmbFykmP051601").cihoComboTree("loadData", objKm);
    }
    //释放内存
    objKm = null;
}

//获取查询条件
function mySearchWhereJson() {
    var strWhereJson = "";      //记录当前的查询条件
    //查询条件的取得
    if ($("#cmbDateExtentP051601").combobox("getValue") == "历史以来") {
        strWhereJson = "{\"sdate\":\"0\",";
        strWhereJson += "\"edate\":\"0\",";
    } else {
        strWhereJson = "{\"sdate\":\"" + $("#dateStartTimeP051601").val() + "\",";
        strWhereJson += "\"edate\":\"" + $("#dateEndTimeP051601").val() + "\",";
    }
    strWhereJson += "\"kmdm\":\"" + $("#cmbFykmP051601").cihoComboTree("getValue") + "\",";
    strWhereJson += "\"flag\":\"" + $("#cmbTjP051601").combobox("getValue") + "\"}";
    return strWhereJson.replace(/[{}]/g, "");
}

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