/*-------------------------------文档信息-----------------------------------
///功能：工资查询
///创建人: 翟新乐
///创建时间：----------------------
///修改人：------------------------
///修改时间：-----------------------
///修改原因：-----------------------
///详细说明：-----------------------
---------------------------------------------------------------------*/
//页面全局变量的定义
var strTableP0518 = "Tp0518";   //表格ID
var objSelRowP0518 = {};        //选择行的数据
var intSelRowIDP0518 = 0;       //选择行的ID
var objWhereJsonP0518 = {};     //记录查询时的条件
var strBmdm = "";
/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓**事件方法 开始**↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/

//页面加载方法
function pageLoad_P0518() {
    //选择日期范围
    loadDateExtent_P0518();
    //部门信息
    loadBmData_P0518();
    //职员信息
    loadZyData_P0518();
    //加载数据
    searchDataClick_P0518();
}

//加载grid
function createTable_P0518(strjson) {
    try {
        $("#" + strTableP0518).GridUnload(strTableP0518);
        var objConfig = ParseData(window.external.DoOptions(strTableP0518, "GetTableConfig", "{}"));
        //添加列格式化方法
        for (var i = 0; i < objConfig.colModel.length; i++) {
            if (objConfig.colModel[i].name == "qcje" || objConfig.colModel[i].name == "yfje" || objConfig.colModel[i].name == "sfje"
            || objConfig.colModel[i].name == "yuje") {
                objConfig.colModel[i].formatter = formatterP0518Money;
            }
        }
        //创建表格
        var objResult = ParseData(window.external.DoOptions(strTableP0518, "GetList", strjson));
        createGrid(strTableP0518, objConfig.colNames, objConfig.colModel, objResult.Records, null, gridComplete_P0518, true, viewDetail_P051801);
        //表格事件的添加
        addGridEvent_P0518();
        resizeGrid(strTableP0518, true, false);
        resizeGridScroll(strTableP0518);
        objConfig = {};
        objResult = {};
    } catch (e) { }
}

//查询按钮的方法
function searchDataClick_P0518() {
    try {
        //combobox的key不存在，赋值空
        if ($("#cmbBmP0518").combobox("getValue") == undefined) {
            $("#cmbBmP0518").combobox("setValue", "");
            $("#cmbZyP0518").combobox("setValue", "");
        }
        if ($("#cmbZyP0518").combobox("getValue") == undefined) {
            $("#cmbZyP0518").combobox("setValue", "");
        }
        //查询条件的取得
        var strWhereJson = "";
        //快捷日期是历史以来，传空值
        if ($("#cmbDateExtentP0518").combobox("getValue") == "历史以来") {
            strWhereJson = "{\"sdate\":\"0\",";
            strWhereJson += "\"edate\":\"0\",";
        }
        else {
            strWhereJson = "{\"sdate\":\"" + $("#dateStartTimeP0518").val() + "\",";
            strWhereJson += "\"edate\":\"" + $("#dateEndTimeP0518").val() + "\",";
        }
        strWhereJson += "\"bmdm\":\"" + $("#cmbBmP0518").combobox("getValue") + "\",";
        strWhereJson += "\"zydm\":\"" + $("#cmbZyP0518").combobox("getValue") + "\"}";
        //记录查询条件
        objWhereJsonP0518 = ParseData(strWhereJson.replace("}", ",\"dname\":\"" + $("#cmbDateExtentP0518").combobox("getValue") + "\",\"bmmc\":\"" + $("#cmbBmP0518").combobox("getText") + "\"}"));
        createTable_P0518(strWhereJson);
        //清空选择行信息
        intSelRowIDP0518 = "";
        objSelRowP0518 = {};
        strWhereJson = null;
    } catch (e) { }
}

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

//查看明细按钮方法
function viewDetail_P051801() {
    try {
        if (intSelRowIDP0518 > 0) {
            //改变标签的Name 
            $(window.parent.document).find("#span_518").text("工资明细");
            $(window.parent.document).find("#idIframe-51801").attr("dname", objWhereJsonP0518.dname);
            $(window.parent.document).find("#idIframe-51801").attr("sdate", objWhereJsonP0518.sdate);
            $(window.parent.document).find("#idIframe-51801").attr("edate", objWhereJsonP0518.edate);
            $(window.parent.document).find("#idIframe-51801").attr("bmdm", objSelRowP0518.bmdm ? objSelRowP0518.bmdm : objWhereJsonP0518.bmdm);
            $(window.parent.document).find("#idIframe-51801").attr("zydm", objSelRowP0518.zydm ? objSelRowP0518.zydm : objWhereJsonP0518.zydm);
            //改变标签Iframe的Src
            $(window.parent.document).find("#idIframe-518").css("display", "none"); //隐藏统计页面
            $(window.parent.document).find("#idIframe-51801").css("display", ""); //显示明页面
            $(window.parent.document).find("#idIframe-51801").attr("src", "05/p051801.htm");
            $(window.parent.document).find("#idIframe-51801").load(function () {
                var iHeight = window.parent.document.documentElement.clientHeight - window.parent._iFrmHeight;
                $(this).height(iHeight);
            });
        }
        else {
            window.parent.cihoAlert(msg.other.selDataRow);
        }
    } catch (e) { }
}


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

//选择日期范围
function loadDateExtent_P0518() {
    //设置默认日期为本月
    dateExtentCalculation("上一月", "dateStartTimeP0518", "dateEndTimeP0518");
    //添加选择事件
    $("#cmbDateExtentP0518").combobox({
        valueField: "dm",
        textField: "mc",
        editable: false,
        panelHeight: 150,
        onSelect: function (option) {
            dateExtentCalculation(option.dm, "dateStartTimeP0518", "dateEndTimeP0518");
        },
        onChange: function (newValue, oldValue) {
            if (newValue == "历史以来") {          //历史以来，灰化日期文本框
                $("#dateStartTimeP0518").attr("disabled", true);
                $("#dateEndTimeP0518").attr("disabled", true);
            }
            else {                                  //其它的不灰化
                $("#dateStartTimeP0518").attr("disabled", false);
                $("#dateEndTimeP0518").attr("disabled", false);
            }
        },
        enterDown: function () {
            dateExtentCalculation($(this).combobox("getValue"), "dateStartTimeP0518", "dateEndTimeP0518");
        }
    });
    //加载数据
    $("#cmbDateExtentP0518").combobox("loadData", [{ dm: "本月", mc: "本月" },
        { dm: "上一月", mc: "上一月", selected: true },
        { dm: "过去三个月", mc: "过去三个月" },
        { dm: "近半年", mc: "近半年" },
        { dm: "本年", mc: "本年" },
        { dm: "上一年", mc: "上一年" }, 
        { dm: "历史以来", mc: "历史以来"}]);    
}

//加载部门信息的方法
function loadBmData_P0518() {
    $("#cmbBmP0518").combobox({
        width: _iWidth100,
        listWidth: _iWidth100,
        valueField: "dm",
        textField: "mc",
        onblur: function () {
            if ($("#cmbBmP0518").combobox("getText") == "") {
                $("#cmbBmP0518").combobox("setValue", "");
            }
        },
        onfocus: function () {
            if ($("#cmbBmP0518").combobox("getText") == "全部部门") {
                $("#cmbBmP0518").combobox("setText", "");
            }
        },
        enterDown: function () {
            //searchDataClick_P0518(); 
        },
        onSelect: function (options) {
            if (options.dm != strBmdm) {        //选择部门关联所属的职员
                if (options.dm == "") {
                    var objZydm = getComboboxData("TZyxx2");
                    $("#cmbZyP0518").combobox("setValue", "");
                    objZydm.unshift({ "dm": "", "mc": "全部职员", "selected": true });
                    $("#cmbZyP0518").combobox("loadData", objZydm);
                    objZydm = {};
                }
                else {
                    var objRet = [];
                    var objZydm = getComboboxData("TZyxx2");
                    objRet = cmbSelectData_P0518(options.dm, objZydm, 'bmdm');
                    objRet.unshift({ "dm": "", "mc": "全部职员", "selected": true });
                    $("#cmbZyP0518").combobox("loadData", objRet);
                    objZydm = {};
                    objRet = {};
                }
            }
            strBmdm = $("#cmbBmP0518").combobox("getValue");
        }
    });

    //加载数据
    var objDrug = getComboboxData('Tbmxx2');
    if (objDrug == "{}") {
        objDrug = [];
    }
    objDrug.unshift({ "dm": "", "mc": "全部部门", "selected": true });
    $("#cmbBmP0518").combobox("loadData", objDrug);
    objDrug = {};
}

//加载职员信息的方法
function loadZyData_P0518() {
    $("#cmbZyP0518").combobox({
        width: _iWidth100,
        listWidth: _iWidth100,
        valueField: "dm",
        textField: "mc",
        onblur: function () {
            if ($("#cmbZyP0518").combobox("getText") == "") {
                $("#cmbZyP0518").combobox("setValue", "");
            }
        },
        onfocus: function () {
            if ($("#cmbZyP0518").combobox("getText") == "全部职员") {
                $("#cmbZyP0518").combobox("setText", "");
            }
        },
        enterDown: function () {
            //searchDataClick_P0518(); 
        },
        onSelect: function (options) {
            if (options.dm != "") {                 //选择职员，关联它的部门
                var objZyData = getComboboxData("TZyxx2");
                for (var intI = 0; intI < objZyData.length; intI++) {
                    if (options.mc == objZyData[intI].mc) {
                        if (objZyData[intI].bmdm != $("#cmbBmP0518").combobox("getValue")) {
                            $("#cmbBmP0518").combobox("setValue", objZyData[intI].bmdm);
                        }
                    }
                }
                objZyData = {};
                strBmdm = $("#cmbBmP0518").combobox("getValue");
            }
        }
    });

    //加载数据
    var objZy = getComboboxData('TZyxx2');
    if (objZy == "{}") {
        objZy = [];
    }
    objZy.unshift({ "dm": "", "mc": "全部职员", "selected": true });
    $("#cmbZyP0518").combobox("loadData", objZy);
    objZy = {};
}

//部门关联对应的职员
function cmbSelectData_P0518(options, objList, strdm) {
    var objRet = [];
    for (var i = 0; i < objList.length; i++) {
        if (options == objList[i][strdm]) {
            objRet.push({ "bmdm": objList[i].bmdm, "dm": objList[i].dm, "jc": objList[i].jc, "jp": objList[i].jp, "mc": objList[i].mc, "newbh": objList[i].newbh });
        }
    }
    return objRet;
}

//表格事件的添加
function addGridEvent_P0518() {
    $("#" + strTableP0518).setGridParam({
        onSelectRow: function (rowId) {//当前选择行数据取得
            intSelRowIDP0518 = rowId;
            objSelRowP0518 = $(this).getRowData(rowId);
        },
        gridComplete: function () {
            gridComplete_P0518();
        }
    });
}

//合计
function gridComplete_P0518() {
    //设置合计行的数据
    var objTable = $("#" + strTableP0518);
    var arrIds = objTable.getDataIDs();
    var strQc = 0;
    var intBqxx = 0;
    var intBqjx = 0;
    var intSjtz = 0;
    for (var i = 0; i < arrIds.length; i++) {
        if (!isNaN(parseFloat(objTable.getCell(arrIds[i], "qcje")))) {
            strQc += parseFloat(objTable.getCell(arrIds[i], "qcje"));
        }
        if (!isNaN(parseFloat(objTable.getCell(arrIds[i], "yfje")))) {
            intBqxx += parseFloat(objTable.getCell(arrIds[i], "yfje"));
        }
        if (!isNaN(parseFloat(objTable.getCell(arrIds[i], "sfje")))) {
            intBqjx += parseFloat(objTable.getCell(arrIds[i], "sfje"));
        }
        if (!isNaN(parseFloat(objTable.getCell(arrIds[i], "yuje")))) {
            intSjtz += parseFloat(objTable.getCell(arrIds[i], "yuje"));
        }
    }
    if (arrIds.length == 0) { //"&nbsp;"
        $("#" + strTableP0518).footerData("set", { rn: "合计", qcje: "&nbsp;", yfje: "&nbsp;", sfje: "&nbsp;", yuje: "&nbsp;" }, false);
    }
    else {
        $("#" + strTableP0518).footerData("set", { rn: "合计", qcje: strQc, yfje: intBqxx, sfje: intBqjx, yuje: intSjtz }, true);
    }
    objTable = null;
    arrIds = null;
    strQc = null;
    intBqjx = null;
    intBqxx = null;
    intSjtz = null;
}

//dj,je格式化money
function formatterP0518Money(cellvalue, options, rowObject) {
    if (!isNaN(parseFloat(cellvalue))) {
        return parseFloat(cellvalue).toFixed(window.parent.strMoneyPlace);
    }
    else {
        return parseFloat(0).toFixed(window.parent.strMoneyPlace);
    }
}

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