/*-------------------------------文档信息-----------------------------------
///功能：税金支付管理
///创建人: 翟新乐
///创建时间：2011-07-01
///修改人：------------------------
///修改时间：-----------------------
///修改原因：-----------------------
///详细说明：-----------------------
---------------------------------------------------------------------*/
//页面全局变量的定义
var strTableP0403 = "Tp0403";    //表格ID
var strPageP0403 = "divPageP0403"; // 信息编辑窗口ID
var objSelRowP0403 = {};        //选择行的数据
var intSelRowIDP0403 = 0;       //选择行的ID
var objPageParamP0403 = { sortfield: "djdate", orderby: "desc", where: "", flag: 0 };  //分页控件使用

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

//保存按钮调用方法
function saveMyData(strDialog, strType, strTable) {
    try {
        if (strTable == "Tp040301") {
            //支付保存
            saveMyData_P040301(strType);
        }
        //添加分类
        else if (strTable == ciho.layal.table) {
            ciho.saveType();
        }
    } catch (e) { }
}

//修改
function updateP0403() {
    if (objSelRowP0403.djbh != null) {
        showDialog_P040301("2");
    }
    else {
        window.parent.cihoAlert(msg.edit.selEditRow);
    }
}

//删除
function deleteData_P0403() {
    try {
        window.parent.cihoAlert(msg.del.delConfirm, msgBox.dlgBtn.YesNo, function (result) {
            if (result == msgBox.dlgRst.Yes) {
                var strJsonData = "{\"djbh\":\"" + objSelRowP0403.djbh + "\"}";
                var objResult = ParseData(window.external.DoOptions(strTableP0403, 'Delete', strJsonData));
                //删除成功后，重新加载数据
                if (objResult.ReturnCode == 0) {
                    objPageParamP0403.flag = 2;
                    loadGridDataP0403();
                    objPageParamP0403.flag = 0;
                    //resizeGrid(strTableP0403);
                }
                else {
                    window.parent.cihoAlert(msg.del.selDelRow);
                }
                strJsonData = null;
                objResult = {};
            }
        });
    } catch (e) { }
}

//关闭
function closeMyDlg(strDialog, strType, strTableName) {
    if ($("#" + strDialog + "_divform").data("change")) {
        window.parent.cihoAlert(
                msg.other.haveChange,
                 msgBox.dlgBtn.YesNoCancel,
                 function (strRet) {
                     if (msgBox.dlgRst.Yes == strRet) {
                         saveMyData(strDialog, strType, strTableName);
                     }
                     else if (msgBox.dlgRst.No == strRet) {
                         cihoDlgClose(strDialog);
                     }
                 });
    }
    else {//0：关闭。关闭编辑窗口
        cihoDlgClose(strDialog);
    }
}

/*------------------------以下是页面私有事件方法-----------------------------*/

//页面加载方法
function pageLoad_P0403() {
    try {
        //选择日期范围
        dateExtent_P0403();
        //开票单位下拉框信息的加载
        loadKpdwData_P0403();
        //列表数据的取得
        var objConfig = ParseData(window.external.DoOptions(strTableP0403, "GetTableConfig", "{}")); //获得jqGrid的列名和属性
        addColFormatter_P0403(objConfig.colModel);
        createGrid(strTableP0403, objConfig.colNames, objConfig.colModel, [], null, null, true);
        //添加事件
        addGridEvent_P0403();
        //设置表格的高度
        resizeGrid(strTableP0403, true, true);

        //创建分页
        createPage(strPageP0403, strTableP0403);
        searchData_P0403();
        //resizeGrid(strTableP0403);
        objConfig = {};
    } catch (e) { }
}

//查询按钮的事件
function searchData_P0403() {
    try {
        objPageParamP0403.sortfield = "djdate";     //排序字段
        objPageParamP0403.orderby = "desc";         //排序顺序
        objPageParamP0403.flag = 1;                 //表示点击查询按钮
        loadGridDataP0403();                        //加载数据
        objPageParamP0403.flag = 0;                 //使用完后，设置为零
//        resizeTbl(false, strTableP0403, true, true);
        //resizeGrid(strTableP0403);
    } catch (e) { }
}

//加载数据的事件
function loadGridDataP0403(strFlag) {
    var objResult = [];
    if ($("#cmbKpdwP0403").combobox('getValue') == undefined) {
        $("#cmbKpdwP0403").combobox('setValue', "");
    }
    if (!strFlag) {
        objPageParamP0403.where = getSelJson_P0403();
    }
    objResult = loadGridData_Page(objPageParamP0403);
    if (objResult) {
        if (objResult.Records.length > 0) {
            $("#" + strTableP0403).footerData("set", { rn: "合计", a1: objResult.zfjes }, true);
        }
        else {
            $("#" + strTableP0403).footerData("set", { rn: "合计", a1: "&nbsp;" }, false);
        }
    }
    objResult = {};
    intSelRowIDP0403 = "";
    objSelRowP0403 = {};
}

//表格事件的添加
function addGridEvent_P0403() {
    $("#" + strTableP0403).setGridParam({
        onSelectRow: function (rowId) { //选择行使用方法
            //当前选择行数据
            intSelRowIDP0403 = rowId;
            objSelRowP0403 = $(this).getRowData(rowId);
            var strBtnHtml = "";
            if (objSelRowP0403.djbh != null) {
                //浮动按钮内容
                strBtnHtml = "<a onclick=\"updateP0403()\">修改</a>-<a onclick=\"deleteData_P0403()\">删除</a>";
            }
            createFloatButton.call(this, rowId, strBtnHtml);
        },
        ondblClickRow: function (rowId) {
            updateP0403();
        },
        onSortCol: function (index, colindex, sortorder) {  //排序
            $("div.operate").hide();                    //浮动层隐藏
            objPageParamP0403.sortfield = index;        //排序字段
            objPageParamP0403.orderby = sortorder;      //排序顺序
            loadGridDataP0403(true);                        //加载数据
            return "stop";
        }
    });
}

//添加列格式化方法
function addColFormatter_P0403(objColModel) {
    //添加列格式化方法
    for (var intI = 0; intI < objColModel.length; intI++) {
        if (objColModel[intI]["name"] == "a1") {
            objColModel[intI].formatter = function (cellvalue, options, rowObject) {
                if (cellvalue != "") {
                    return parseFloat(cellvalue).toFixed(window.parent.strMoneyPlace);
                }
                else {
                    return "&nbsp;";
                }
            }
        }
        if (objColModel[intI]["name"] == "bz") {
            objColModel[intI].sortable = false;
        }
    }
}

//日期范围的选择方法
function dateExtent_P0403() {
    //设置默认日期为本月
    dateExtentCalculation("本月", "dateStartTimeP0403", "dateEndTimeP0403");

    //添加选择事件
    $("#cmbDateExtentP0403").combobox({
        width: _iWidth100,
        listWidth: _iWidth100,
        valueField: "dm",
        textField: "mc",
        editable: false,
        panelHeight: 82,
        onSelect: function (option) {
            dateExtentCalculation(option.dm, "dateStartTimeP0403", "dateEndTimeP0403");
        },
        enterDown: function () {
            dateExtentCalculation($(this).combobox("getValue"), "dateStartTimeP0403", "dateEndTimeP0403");
            //searchData_P0403();
        }
    });
    //加载数据
    $("#cmbDateExtentP0403").combobox("loadData", [{ dm: "本月", mc: "本月", selected: true }, { dm: "上一月", mc: "上一月" }, { dm: "过去三个月", mc: "过去三个月" }, { dm: "本年", mc: "本年"}]);
}

//开票单位下拉框信息的加载
function loadKpdwData_P0403() {
    $("#cmbKpdwP0403").combobox({
        width: _iWidth120,
        listWidth: _iWidth120,
        valueField: "dm",
        textField: "mc",
        //获得焦点
        onfocus: function () {
            if ($('#cmbKpdwP0403').combobox('getText') == "全部往来单位") {
                $("#cmbKpdwP0403").combobox("setText", "");
            }
        },
        //失去焦点
        onblur: function () {
            if ($("#cmbKpdwP0403").combobox("getText") == "") {
                $("#cmbKpdwP0403").combobox("setValue", "");
            }
        },
        enterDown: function () {
            //searchData_P0403();
        }
    });
    var objKp = getComboboxData('Tkpdwxx2');
    if (objKp == "{}") {
        objKp = [];
    }
    objKp.unshift({ "dm": "", "mc": "全部往来单位", "selected": true });
    $("#cmbKpdwP0403").combobox("loadData", objKp);
    objKp = {};
}

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

//得到查询字符串
function getSelJson_P0403() {
    var strRecord = "";
    strRecord += "\"sdate\":\"" + $("#dateStartTimeP0403").val() + "\",";
    strRecord += "\"edate\":\"" + $("#dateEndTimeP0403").val() + "\",";
    strRecord += "\"kpdwdm\":\"" + $("#cmbKpdwP0403").combobox('getValue') + "\"";
    return strRecord;
}
/*↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑**事件方法 结束**↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑*/