/*-------------------------------文档信息-----------------------------------
///功能：预提费用明细
///创建人: 翟新乐
///创建时间：----------------------
///修改人：------------------------
///修改时间：-----------------------
///修改原因：-----------------------
///详细说明：-----------------------
---------------------------------------------------------------------*/
//页面全局变量的定义
var strTableP051102 = "Tp051102";   //表格ID
var objSelRowP051102 = {};          //选择行的数据
var intSelRowIDP051102 = 0;         //选择行的ID
var strPageP051102 = "divPageP051102";
var objPageParamP051102 = { sortfield: "", orderby: "", where: "", flag: 0 };  //分页控件使用

//窗口关闭按钮调用方法
function closeMyDlg(strDialog, strType, strTable) {
    //$("#" + strDialog).dialog("close");
    cihoDlgClose(strDialog);
}

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓**事件方法 开始**↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
//页面加载方法
function pageLoad_P051102() {
    //选择日期范围
    dateExtent_P051102();
    //加载科目信息
    loadFykmData_P051102();
    //经手人下拉框信息的加载
    loadJsrData_P051102();
    //预提对象信息
    loadYtdxData_P0511();
    var objConfig = ParseData(window.external.DoOptions(strTableP051102, "GetTableConfig", "{}"));
    //添加列格式化方法
    for (var i = 0; i < objConfig.colModel.length; i++) {
        if (objConfig.colModel[i].name == "ytje" || objConfig.colModel[i].name == "zfje") {
            objConfig.colModel[i].formatter = formatterP051102Money;
        }
        if (objConfig.colModel[i].name == "syje") {
            objConfig.colModel[i].formatter = formatterYsyeMoney;
        }
    }
    //创建表格
    createGrid(strTableP051102, objConfig.colNames, objConfig.colModel, [], null, null, true, viewReceipt_P051102);
    //    //表格事件的添加
    addGridEvent_P051102();
    resizeGrid(strTableP051102, true, true);
    createPage(strPageP051102, strTableP051102);
    //加载表格数据(触发查询按钮的点击事件)
    searchDataClick_P051102();
    //resizeGrid(strTableP051102);
    objConfig = {};
}

//查询按钮事件
function searchDataClick_P051102() {
    try {
        objPageParamP051102.sortfield = ""; //排序字段
        objPageParamP051102.orderby = "";     //排序顺序
        objPageParamP051102.flag = 1;             //表示点击查询按钮
        loadGridDataP051102();                     //加载数据
        objPageParamP051102.flag = 0;              //使用完后，设置为零
        //resizeGrid(strTableP051102);
    } catch (e) { }
}

//加载数据
function loadGridDataP051102() {
    var objResult = [];
    objPageParamP051102.where = getSelJson_P051102();
    objResult = loadGridData_Page(objPageParamP051102);
    //后台返回的合计
    if (objResult) {
        if (objResult.Records.length > 0) {
            $("#" + strTableP051102).footerData("set", { rn: "合计",
                ytje: objResult.ytje.toFixed(window.parent.strMoneyPlace),
                zfje: objResult.zfje.toFixed(window.parent.strMoneyPlace)
            }, false);
        } else {
            $("#" + strTableP051102).footerData("set", { rn: "合计", ytje: "&nbsp;", zfje: "&nbsp;" }, false);
        }
    }
    objResult = {};
    intSelRowIDP051102 = "";
    objSelRowP051102 = {};
}

//取得查询条件
function getSelJson_P051102() {
    //combobox的key不存在，赋值空
    if (!$("#cmbFykmP051102").combobox("getValue")) {
        $("#cmbFykmP051102").combobox("setValue", "");
    }
    if (!$("#cmbFyjsrP051102").combobox("getValue")) {
        $("#cmbFyjsrP051102").combobox("setValue", "");
    }
    if (!$("#cmbYtdxP051102").combobox("getValue")) {
        $("#cmbYtdxP051102").combobox("setValue", "");
    }
    //查询条件的取得
    var strWhereJson = "";
    //快捷日期是历史以来，传空值
    if ($("#cmbDateExtentP051102").combobox("getValue") == "历史以来") {
        strWhereJson = "\"sdate\":\"0\",";
        strWhereJson += "\"edate\":\"0\",";
    }
    else {
        strWhereJson = "\"sdate\":\"" + $("#dateStartTimeP051102").val() + "\",";
        strWhereJson += "\"edate\":\"" + $("#dateEndTimeP051102").val() + "\",";
    }
    strWhereJson += "\"kmdm\":\"" + $("#cmbFykmP051102").combobox("getValue") + "\",";
    strWhereJson += "\"jsrdm\":\"" + $("#cmbFyjsrP051102").combobox("getValue") + "\",";
    strWhereJson += "\"ytdx\":\"" + $("#cmbYtdxP051102").combobox("getValue") + "\"";
    return strWhereJson;
}

//查看单据按钮的方法
function viewReceipt_P051102() {
    try {
        if (intSelRowIDP051102) {
            if (objSelRowP051102.djname == "预提") {
                //预提
                showDialogP051102_ytd("divP051102", objSelRowP051102.djbh);
            }
            else if (objSelRowP051102.djname == "预提支付") {
                //预提支付
                openYtzfd("divP051102", objSelRowP051102.djbh);
            }
            else if (objSelRowP051102.djname == "预提结转") {
                //预提结转单
                showDialog_ytjzd("divP051102", objSelRowP051102.djbh);
            }
        }
        else {
            window.parent.cihoAlert(msg.other.selDataRow);
        }
    } catch (e) { }
}

//返回按钮的方法
function pageBack_P051102() {
    //改变标签的Name
    $(window.parent.document).find("#span_511").text("预提费用统计");
    //改变标签Iframe的Src
    $(window.parent.document).find("#idIframe-511").css("display", ""); //显示统计页面
    $(window.parent.document).find("#idIframe-51102").css("display", "none"); //隐藏明细页面
    $(window.parent.document).find("#idIframe-51102").attr("src", "");
}

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

/*↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑**事件方法 结束**↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑*/
/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓**自定义方法 开始**↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/

//选择日期范围
function dateExtent_P051102() {
    $("#cmbDateExtentP051102").combobox({
        valueField: "dm",
        textField: "mc",
        editable: false,
        panelHeight: 130,
        onChange: function (newValue,oldValue) {
            if (newValue == "历史以来") {              //历史以来，灰化日期控件文本框
                $("#dateStartTimeP051102").attr("disabled", true);
                $("#dateEndTimeP051102").attr("disabled", true);
            }
            else {                                      //其它的不灰化
                $("#dateStartTimeP051102").attr("disabled", false);
                $("#dateEndTimeP051102").attr("disabled", false);
            }
            //dateExtentCalculation(newValue, "dateStartTimeP051102", "dateEndTimeP051102");
        },
        onSelect: function (option) {
            dateExtentCalculation(option.dm, "dateStartTimeP051102", "dateEndTimeP051102");
        },
        enterDown: function () {
            dateExtentCalculation($(this).combobox("getValue"), "dateStartTimeP051102", "dateEndTimeP051102");
            //searchDataClick_P051102();
        }
    });
    //加载数据
    $("#cmbDateExtentP051102").combobox("loadData", [{ dm: "本月", mc: "本月", selected: true },
        { dm: "上一月", mc: "上一月" },
        { dm: "过去三个月", mc: "过去三个月" },
        { dm: "本年", mc: "本年" },
        { dm: "上一年", mc: "上一年" },
        { dm: "历史以来", mc: "历史以来"}]);

    var strDateItem = $(window.parent.document).find("#idIframe-51102").attr("dname");
    if (strDateItem != "") {
        $("#cmbDateExtentP051102").combobox("setValue", strDateItem);
        dateExtentCalculation(strDateItem, "dateStartTimeP051102", "dateEndTimeP051102");
    }
    else {
        var strStartTime = $(window.parent.document).find("#idIframe-51102").attr("sdate");
        var strEndTime = $(window.parent.document).find("#idIframe-51102").attr("edate");
        $("#cmbDateExtentP051102").combobox("setText", "自定义");
        $("#dateStartTimeP051102").val(strStartTime);
        $("#dateEndTimeP051102").val(strEndTime);
    }
    strDateItem = null;
    strStartTime = null;
    strEndTime = null;
}

//科目下拉框信息的加载
function loadFykmData_P051102() {
    $("#cmbFykmP051102").combobox({
        valueField: "kmdm",
        textField: "kmmc",
        onblur: function () {
            if ($("#cmbFykmP051102").combobox("getText") == "") {
                $("#cmbFykmP051102").combobox("setValue", "");
            }
        },
        onfocus: function () {
            if ($("#cmbFykmP051102").combobox("getText") == "全部费用科目") {
                $("#cmbFykmP051102").combobox("setText", "");
            }
        },
        enterDown: function () {
            //searchDataClick_P051102();
        }
    });
    //科目信息的取得
    //var objProvider = ParseData(window.external.DoOptions("Tp0511", "GetTreeList", "{'flag':'1'}")).Records;
    var objProvider = ParseData(window.external.DoOptions("Tp0505", "GetComboBoxData", "{'fb':'2'}")).Records;
    if (objProvider == "{}") {
        objProvider = [];
    }
    //加载数据
    objProvider.unshift({ "kmdm": "", "kmmc": "全部费用科目" });
    $("#cmbFykmP051102").combobox("loadData", objProvider);
    //设定默认值
    $("#cmbFykmP051102").combobox("setValue", $(window.parent.document).find("#idIframe-51102").attr("kmdm"));
    objProvider = {};
}

//经手人下拉框信息的加载
function loadJsrData_P051102() {
    $("#cmbFyjsrP051102").combobox({
        valueField: "jsrdm",
        textField: "jsrmc",
        onblur: function () {
            if ($("#cmbFyjsrP051102").combobox("getText") == "") {
                $("#cmbFyjsrP051102").combobox("setValue", "");
            }
        },
        onfocus: function () {
            if ($("#cmbFyjsrP051102").combobox("getText") == "全部费用经手人") {
                $("#cmbFyjsrP051102").combobox("setText", "");
            }
        },
        enterDown: function () {
            //searchDataClick_P051102();
        }
    });

    //经手人信息的取得
    //var objDrug = ParseData(window.external.DoOptions("Tp0507", "GetComboBoxData", '{"flag":"3"}')).Records;
    var objDrug = ParseData(window.external.DoOptions("Tp0505", "GetComboBoxData", "{'fb':'1'}")).Records;
    if (objDrug == "{}") {
        objDrug = [];
    }
    //加载数据
    objDrug.unshift({ "jsrdm": "", "jsrmc": "全部费用经手人" });
    $("#cmbFyjsrP051102").combobox("loadData", objDrug);
    //设定默认值
    $("#cmbFyjsrP051102").combobox("setValue", $(window.parent.document).find("#idIframe-51102").attr("jsrdm"));
    objDrug = {};
}

//加载预提对象
function loadYtdxData_P0511() {
    $("#cmbYtdxP051102").combobox({
        width: _iWidth190,
        listWidth: _iWidth190,
        valueField: "ytdx",
        textField: "ytdxmc",
        onblur: function () {
            if ($("#cmbYtdxP051102").combobox("getText") == "") {
                $("#cmbYtdxP051102").combobox("setValue", "");
            }
        },
        onfocus: function () {
            if ($("#cmbYtdxP051102").combobox("getText") == "全部预提对象") {
                $("#cmbYtdxP051102").combobox("setText", "");
            }
        },
        enterDown: function () {
            //searchDataClick_P051102();
        }
    });

    //预提对象信息的取得
    var objDrug = window.external.DoOptions("Tp0505", "GetComboBoxData", "{'fb':'3'}");
    //var objDrug = window.external.DoOptions("Tp0511", "GetTreeList", "{'flag':'2'}");
    if (objDrug) {
        var objZyxx = ParseData(objDrug);
        //加载数据
        objZyxx.Records.unshift({ "ytdx": "", "ytdxmc": "全部预提对象", "selected": true });
        $("#cmbYtdxP051102").combobox("loadData", objZyxx.Records);
    }    
    //设定默认值
    $("#cmbYtdxP051102").combobox("setValue", $(window.parent.document).find("#idIframe-51102").attr("ytdx"));
    objDrug = {};
    objZyxx = {};
}

//表格事件的添加
function addGridEvent_P051102() {
    $("#" + strTableP051102).setGridParam({        
        onSelectRow: function (rowId) { //当前选择行数据取得
            intSelRowIDP051102 = rowId;
            objSelRowP051102 = $(this).getRowData(rowId);
        },
        ondblClickRow: function (rowId) {   //双击事件
            viewReceipt_P051102();
        }
    });
}

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

//格式化应付金额
function formatterYsyeMoney(cellvalue, options, rowObject) {
    if (!isNaN(parseFloat(cellvalue))) {
        return parseFloat(cellvalue).toFixed(window.parent.strMoneyPlace);
    }
    else {
        return "&nbsp;";
    }
}
/*↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑**自定义方法 结束**↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑*/