/*--------------------------文档信息-------------------------------------------
///功能：      转账管理
///创建人：  王群
///创建时间：2011年05月31日
///修改人：  --------------
///修改时间：--------------
///详细说明：--------------
-----------------------------------------------------------------------------*/
//页面全局变量的定义
var strTableP0502 = "Tp0502";              //表格ID
var strPageP0502 = "divPageP0502";    //分页层的ID
var strSelRowIDP0502 = "";                   //选择行的ID
var objSelRowP0502 = {};                     //选择行的数据
var objPageParamP0502 = { sortfield: "djdate", orderby: "desc", where: "", flag: 0 };     //分页控件使用

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓**保存♦♦关闭♦♦删除♦♦双击修改 开始**↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
//保存按钮调用方法
function saveMyData(strDialog, strType, strTable) {
    //资金转账单保存
    try {
        saveDataP050201(strType);
    } catch (e) { }
}

//删除按钮的方法
function deleteData_P0502() {
    try {
        var objDelResult = {};    //定义变量用于接收删除后返回的信息
        window.parent.cihoAlert(msg.del.delConfirm, msgBox.dlgBtn.YesNo, function (result) {
            if (result == msgBox.dlgRst.Yes) {
                objDelResult = ParseData(window.external.DoOptions(strTableP0502, 'Delete', "{\"djbh\":\"" + objSelRowP0502.djbh + "\"}"));

                //删除成功后，重新加载数据
                if (objDelResult.ReturnCode == 0) {

                    //清空选择行信息
                    strSelRowIDP0502 = "";
                    objSelRowP0502 = {};

                    //重新加载数据
                    searchDataClick_P0502(2);
                }
            }
        });
        //释放内存
        objDelResult = null;
    } catch (e) { }
}

//双击行事件方法
function dblClickRow_P0502(rowid) {
    try {
        showDialog_P050201('2');   //转账单
    } catch (e) { }
}

//窗口关闭按钮调用方法
function closeMyDlg(strDialog, strType, strTable) {
    //当页面信息已修改时，弹出提示保存
    if ($("#" + strDialog + "_divform").data("change") == true) {
        window.parent.cihoAlert(msg.other.haveChange, msgBox.dlgBtn.YesNoCancel, function (result) {
            //点击【是】时，执行保存操作
            if (result == msgBox.dlgRst.Yes) {
                try {
                    saveDataP050201(strType);
                } catch (e) { }
            }
            //点击【否】时，关闭弹出层
            else if (result == msgBox.dlgRst.No) {
                //$("#" + strDialog).dialog("close");
                cihoDlgClose(strDialog);
            }
        });
    }
    //数据没变动直接关闭弹出层
    else {
        //$("#" + strDialog).dialog("close");
        cihoDlgClose(strDialog);
    }
}

/*↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑**保存♦♦关闭♦♦删除♦♦双击修改 结束**↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑*/


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

//页面加载事件
function pageLoad_P0502() {
    try {
        //选择日期范围
        loadDateExtent_P0502();
        //加载流出账户信息
        loadLczhData_P0502();
        //加载流入账户的信息
        loadLrzhData_P0502();
        //获得jqGrid的列名和属性
        var objConfig = ParseData(window.external.DoOptions(strTableP0502, "GetTableConfig", "{}"));
        //创建表格
        createGrid(strTableP0502, objConfig.colNames, objConfig.colModel, [], null, null, true, dblClickRow_P0502);
        //调整表格的自适应列宽度
        resizeGrid(strTableP0502, true, true);
        //添加事件
        addGridEvent_P0502();
        //添加列格式化方法
        addColFormat_P0502();
        //创建分页
        createPage(strPageP0502, strTableP0502);
        //加载表格数据
        searchDataClick_P0502(1);
        //释放内存
        objConfig = null;
    } catch (e) { }
}

//查询按钮的事件
function searchDataClick_P0502(flags) {
    try {
        var objResult = {};     //定义变量用于接收从后台获得的数据集

        //验证选择的流出账户是否存在
        if (!$("#cmLczhP0502").cihoComboTree("getValue")) {
            $("#cmLczhP0502").cihoComboTree("setValue", "")
        }
        //验证选择的流入账户是否存在
        if (!$("#cmbLrzhP0502").cihoComboTree("getValue")) {
            $("#cmbLrzhP0502").cihoComboTree("setValue", "");
        }
        //查询条件的取得
        if (flags == 0) {           //保存成功后保存的flag标志位为0
            objPageParamP0502.flag = 0;
        }
        else if (flags == 1) {    //点击查询按钮时保存的flag标志位为1
            objPageParamP0502.flag = 1;
            objPageParamP0502.sortfield = "djdate";
            objPageParamP0502.orderby = "desc";
        }
        else if (flags == 2) {   //删除成功后保存的flag标志位为2
            objPageParamP0502.flag = 2;
        }
        objPageParamP0502.where = getWhereJson_P0502();
        objResult = loadGridData_Page(objPageParamP0502);

        //合计数据的计算
        if (objResult.lrjehej) {  //当合计【流动金额】不存在时，就给其赋值为0
            $("#" + strTableP0502).footerData("set", { rn: "合计", ldje: parseFloat(objResult.lrjehej).toFixed(window.parent.strMoneyPlace) }, false);
        }
        else {
            $("#" + strTableP0502).footerData("set", { rn: "合计", ldje: "&nbsp;" }, false);
        }

        //把标志位设置为0
        objPageParamP0502.flag = 0;

        //清空选择行信息
        strSelRowIDP0502 = "";
        objSelRowP0502 = {};

        //释放内存
        objResult = null;
    } catch (e) { }
}

//给表格添加事件
function addGridEvent_P0502() {

    //定义用于存放浮动层内容的变量
    var strButtonHtml = "";
    $("#" + strTableP0502).setGridParam({

        //当前选择行数据取得
        onSelectRow: function (rowId) {

            //页面全局变量
            strSelRowIDP0502 = rowId;
            objSelRowP0502 = $(this).getRowData(rowId);

            //选择行不是空行时,给行创建浮动层
            if (objSelRowP0502.djbh) {
                strButtonHtml = "<a onclick=\"showDialog_P050201('2')\">修改</a>-<a onclick=\"deleteData_P0502()\">删除</a>";
                createFloatButton.call(this, rowId, strButtonHtml);
            }
        },
        onSortCol: function (index, colindex, sortorder) {
            $("div.operate").hide();                             //隐藏浮动按钮
            objPageParamP0502.sortfield = index;
            objPageParamP0502.orderby = sortorder;
            loadGridData_Page(objPageParamP0502);
            return "stop";
        }
    });
    //释放内存
    strButtonHtml = null;
}

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

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

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

//日期范围的选择方法
function loadDateExtent_P0502() {
    //设置默认日期为本月
    dateExtentCalculation("本月", "dateStartTimeP0502", "dateEndTimeP0502");
    //添加选择事件
    $("#cmbDateExtentP0502").combobox({
        width: _iWidth100,
        listWidth: _iWidth100,
        valueField: "dm",
        textField: "mc",
        panelHeight: 102,
        editable: false,
        onSelect: function (option) {
            dateExtentCalculation(option.dm, "dateStartTimeP0502", "dateEndTimeP0502");
        },
        enterDown: function () {
            dateExtentCalculation($("#cmbDateExtentP0502").combobox("getValue"), "dateStartTimeP0502", "dateEndTimeP0502");
        }
    });
    //加载数据
    $("#cmbDateExtentP0502").combobox("loadData",
    [{ dm: "本月", mc: "本月", selected: true },
     { dm: "上一月", mc: "上一月" },
     { dm: "本周", mc: "本周" },
     { dm: "过去三个月", mc: "过去三个月" },
     { dm: "本年", mc: "本年"}]);
}

//加载流出账户信息
function loadLczhData_P0502() {
    //从后台获取流出账户的数据集
    var objLczhResult = ParseData(window.external.DoOptions("Tp0502", "GetComboBoxData", '{}'));

    objLczhResult.Records.unshift({ "id": "", "text": "全部转出账户" }); //给转出账户添加一项默认值

    $("#cmLczhP0502").cihoComboTree('loadData', objLczhResult.Records);  //给流出账户的comboTree加载数据
    $(".tree-node-selected").removeClass("tree-node-selected");

    //释放一下内存
    objLczhResult = null;
}

//加载流入账户信息
function loadLrzhData_P0502() {
    //定义变量从后台获取数据集
    var objLrzhResult = ParseData(window.external.DoOptions("Tp0502", "GetComboBoxData", '{}'));

    objLrzhResult.Records.unshift({ "id": "", "text": "全部转入账户" });  //设定默认值

    $("#cmbLrzhP0502").cihoComboTree('loadData', objLrzhResult.Records);   //加载数据
    $(".tree-node-selected").removeClass("tree-node-selected");

    //释放一下内存
    objLrzhResult = null;
}

//添加列格式化方法
function addColFormat_P0502() {
    //流动金额
    $("#" + strTableP0502).setColProp("ldje",
    {
        formatter: function (cellvalue, options, rowObject) {
            if (cellvalue) {
                return parseFloat(cellvalue).toFixed(window.parent.strMoneyPlace);
            }
            else {
                return 0;
            }
        }
    });
}

//查询条件的方法
function getWhereJson_P0502() {
    var strWhereJson = "";   //用于存放查询条件的变量
    strWhereJson += "\"sdate\":\"" + trim($("#dateStartTimeP0502").val()) + "\",";
    strWhereJson += "\"edate\":\"" + trim($("#dateEndTimeP0502").val()) + "\",";
    strWhereJson += "\"lczhdm\":\"" + trim($("#cmLczhP0502").cihoComboTree("getValue")) + "\",";
    strWhereJson += "\"lrzhdm\":\"" + trim($("#cmbLrzhP0502").cihoComboTree("getValue")) + "\"";
    return strWhereJson;
}

//基本资料修改刷新
function refreshMyCombobox(strModels) {
    for (var i = 0; i < strModels.length; i++) {
        if (strModels[i] == "TKjkm") {
            var objLrKm = ParseData(window.external.DoOptions("Tp0502", "GetComboBoxData", "{}")).Records; //取得科目的数据集
            var objLcKm = ParseData(window.external.DoOptions("Tp0502", "GetComboBoxData", "{}")).Records; //取得科目的数据集
            //流出帐户存在时
            if (objLcKm && objLcKm != "{}") {
                objLcKm.unshift({ "id": "", "text": "全部转出账户" });
                $("#cmLczhP0502").cihoComboTree("loadData", objLcKm);
            }
            //流入帐户存在时
            if (objLrKm && objLrKm != "{}") {
                objLrKm.unshift({ "id": "", "text": "全部转入账户" });
                $("#cmbLrzhP0502").cihoComboTree("loadData", objLrKm);
            }
        }
    }
}
/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓**自定义方法 结束**↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/