/*************************
*功能：会计凭证管理
*创建人：张振华
*时间：2010-08-15
*备注：此时间是加注释时间
*************************/

var strTableP0504 = "Tp0504";
var strPageP0504 = "divPageP0504";
var objSelRowP0504; //单击行时的数据
var objPageParamP0504 = { sortfield: "", orderby: "", where: "",flag:0 }; //分页控件使用

//基本资料修改刷新
function refreshMyCombobox(strModels) {
    for (var i = 0; i < strModels.length; i++) {
        if (strModels[i] == "TKjkm") {
            var objKm = ParseData(window.external.DoOptions("Tp0504", "GetComboBoxData", "{}")).Records;
            if (objKm != null && objKm != "{}") {
                objKm.unshift({ "id": "", "text": "全部科目" });
                $("#cmbKmP0504").cihoComboTree("loadData", objKm);
            }
        }
    }
}

//格式化金额
function formatterP0504Money(cellValue) {
    if (!isNaN(parseFloat(cellValue))) {
        return parseFloat(cellValue).toFixed(window.parent.strMoneyPlace);
    }
    else {
        return "&nbsp;";
    }
}

//头部搜索条的信息
function getSearchInfoP0504() {

    //科目
    var objKm = getComboboxData("TKjkm2");
    var item;

    //属性科目
    $("#cmbKmP0504").cihoComboTree({
        width:120,
        mode: "child"
    });

    //快捷日期
    $("#cmbDateExtentP0504").combobox();

    //树形combobox和普通combobox下拉箭头的样式
    addArrowClass();
    addTreeArrowClass();

    //开始日期，结束日期绑定事件和值
    inputAndBindData("dateStartTimeP0504", false, null, dateTimeChangeP0504);
    inputAndBindData("dateEndTimeP0504", false, null, dateTimeChangeP0504);
    dateExtentCalculation("本月", "dateStartTimeP0504", "dateEndTimeP0504");

    //快捷日期
    $("#cmbDateExtentP0504").combobox({
        width: _iWidth120,
        panelHeight: 122,
        editable: false,
        onSelect: function (option) {
            dateExtentCalculation(option.value, "dateStartTimeP0504", "dateEndTimeP0504");
        },
        enterDown: function () {
            dateExtentCalculation($(this).combobox("getValue"), "dateStartTimeP0504", "dateEndTimeP0504");
        }
    });

    //树形科目数据
    objKm = ParseData(window.external.DoOptions("Tp0504", "GetComboBoxData", "{}")).Records;
    item = $("#cmbKmP0504");
    if (objKm != null && objKm != "{}") {
        objKm.unshift({"id": "", "text": "全部科目"});
        $("#cmbKmP0504").cihoComboTree("loadData", objKm);
    }

    //释放内存
    item = null;
     
     //层序
    $(".layoutpanel").css("z-index", "50000009");
}

//搜索数据
function searchDataClickP504() {
    
    //组查询条件
    var strWhereJson = "";
    strWhereJson += "\"sdate\":\"" + $("#dateStartTimeP0504").val() + "\",";
    strWhereJson += "\"edate\":\"" + $("#dateEndTimeP0504").val() + "\"";
    if ($("#cmbKmP0504").cihoComboTree("getValue") != "-1") {
        strWhereJson += ",\"kmdm\":\"" + $("#cmbKmP0504").cihoComboTree("getValue") + "\"";
    }

    objPageParamP0504.where = strWhereJson;

    //根据查询条件取出数据
    var objRecords = loadGridData_Page(objPageParamP0504);

    //重新设置分页标志位
    objPageParamP0504.flag = 0;

    //隐藏浮动按钮
    $("div.operate").hide();

    //计算合计
    if (objRecords.Records.length == 0) {
        $("#" + strTableP0504).footerData('set', { rn: "合计", a1: "&nbsp;" });
    }
    else {
        $("#" + strTableP0504).footerData('set', { rn: "合计", a1: objRecords.zje }, true);
    }

}

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

//单击
function onSelectGridP0504(rowId) {

    //行数据
    objSelRowP0504 = $(this).getRowData(rowId);
    createFloatButton.call(this, rowId, "<a onclick=\"showDialogP050401('2');\">修改</a>-<a onclick=\"deleteDataP0504();\">删除</a>");
}

//双击
function dbClickP0504(strType, rowId) {
    //行数据
    objSelRowP0504 = $(this).getRowData(rowId);

    showDialogP050401(strType);
}

//排序事件
function sortDataP0504(index, colindex, sortorder) {

    objPageParamP0504.sortfield = index;
    objPageParamP0504.orderby = sortorder;

    //根据查询条件取出数据
    var objRecords = loadGridData_Page(objPageParamP0504);

    //重新设置分页标志位
    objPageParamP0504.flag = 0;

    //隐藏浮动按钮
    $("div.operate").hide();

    //计算合计
    if (objRecords.Records.length == 0) {
        $("#" + strTableP0504).footerData('set', { rn: "合计", a1: "&nbsp;" });
    }
    else {
        $("#" + strTableP0504).footerData('set', { rn: "合计", a1: objRecords.zje }, true);
    }

    return 'stop';
}

//窗口关闭按钮调用方法
function closeMyDlg(strDialog, strType, strTable) {
    var isTextChange = $("#" + strDialog + "_divform").data("change");

    //当页面信息已修改时，弹出提示保存
    if (isTextChange == true) {
        //函数名称
        window.parent.cihoAlert(
            msg.other.haveChange  //message information
            , msgBox.dlgBtn.YesNoCancel     //按钮类型msgBox.dlgBtn.YesNo  msgBox.dlgBtn.YesNoCancel
            , function (strRet) {//回调函数
                if (msgBox.dlgRst.Yes == strRet) {
                    saveMyData(strDialog, 0, strTable);
                }
                else if (msgBox.dlgRst.No == strRet) {
                    cihoDlgClose(strDialog);
                    freeMemory_P050401();
                }
            }
        );


    }
    else {
        cihoDlgClose(strDialog);
        freeMemory_P050401();
    }
}

//保存按钮调用方法
function saveMyData(strDialog, strType, strTable) {
    try {
        if (strTable == "Tp050401") {
            saveMyDataTp050401(strDialog, strType)
        }
    }
    catch (e) {
        proceError("P0504", e.ToString());
    }
}

//删除
function deleteDataP0504(rowId) {
    try {
        window.parent.cihoAlert(msg.del.delConfirm, msgBox.dlgBtn.YesNo, function (result) {
            if (result == msgBox.dlgRst.Yes) {
                //删除数据信息
                var objResult = ParseData(window.external.DoOptions(strTableP0504, 'Delete', "{\"djbh\":\"" + objSelRowP0504.djbh + "\"}"));
                //删除成功后，重新加载数据
                if (objResult.ReturnCode == 0) {
                    objPageParamP0504.flag = 2;
                    searchDataClickP504();
                }
                else {
                    window.parent.cihoAlert(objResult.MSG);
                }

            }
        });
    }
    catch (e) {
        proceError("P0504", e.ToString());
    }
}