/*************************
*功能：工资预提管理
*创建人：张振华
*时间：2010-08-16
*备注：此时间是加注释时间
*************************/

var strTableP0509 = "Tp0509";
var strPageP0509 = "divPageP0509";
var objPageParamP0509 = { sortfield: "", orderby: "", where: "", flag: 0 }; //分页控件使用
var objSelRowP0509; //选择行对象


//刷新
function refreshMyCombobox(strModels) {
    for (var i = 0; i < strModels.length; i++) {
        var data;
        if (strModels[i] == "TZyxx") {
            data = getComboboxData(strModels[i] + "2");
            data.unshift({ dm: "", mc: "全部职员" });
            reLoadCombobox("cmbZyP0509", data);
        }
        data = null;
    }
}

//格式化预提方式
function formatterP0509YtType(cellValue) {
    if (cellValue == "0") {
        return "按销售";
    }
    else {
        return "按回款";
    }
}

//数量金额
function formatterP0509Slje(cellValue) {
    if (cellValue == "0") {
        return "按数量";
    }
    else {
        return "按金额";
    }
}

//预提时间
function formatterP0509Ytsj(cellValue) {

    switch (cellValue) {
        case "0":
            return "每笔";
            break;
        case "1":
            return "月末";
            break;
        case "2":
            return "季度末";
            break;
        case "3":
            return "年末";
            break;
    }
}

//预提状态
function formatterP0509Zt(cellValue) {
    if (cellValue == "True") {
        return "已启用";
    }
    else {
        return "已停用";
    }
}

//预提规则
function formatterP0509Gz(cellValue, option) {
    return "<div class = 'name'><div class='wfp'><div class='add'><a herf='#' style=' cursor:pointer; ' onclick=\"showDialogP050902('2','" + option.rowId + "');\"  title=\"修改预提规则区间\" ></a></div></div></div>";
}

//反格式化预提类型
function unFormatterP0509YtType(cellValue, option) {
    if (cellValue == "按销售") {
        return "0";
    } else {
        return "1";
    }
}

//反格式化预提时间
function unFormatterP0509Ytsj(cellValue, option) {
    switch (cellValue) {
        case "每笔":
            return "0";
            break;
        case "月末":
            return "1";
            break;
        case "季度末":
            return "2";
            break;
        case "年末":
            return "3";
            break;
    }
}

//反格式化数量金额
function unFormatterP0509Slje(cellValue) {
    if (cellValue == "按数量") {
        return "0";
    }
    else {
        return "1";
    }
}

//改变状态
function setZtP0509(rowId) {

    //table对象
    var objTable = $("#" + strTableP0509);

    //数据库返回结果
    var objResult;

    if (objSelRowP0509.zt == "已启用") {
        objResult = ParseData(window.external.DoOptions(strTableP0509, "Edit", "{gzguid:\"" + objSelRowP0509.gzguid + "\",zt:\"" + false + "\"}"));
        if (objResult != null && objResult.ReturnCode == "0") {
            objTable.setCell(rowId, "zt", "False");
        }

    }
    else {
        objResult = ParseData(window.external.DoOptions(strTableP0509, "Edit", "{gzguid:\"" + objSelRowP0509.gzguid + "\",zt:\"" + true + "\"}"));
        if (objResult != null && objResult.ReturnCode == "0") {
            objTable.setCell(rowId, "zt", "True");
        }
    }

    //释放内存
    objTable = null;
}

//单击事件
function onSelectGridP0509(rowId) {

    //存储行数据
    objSelRowP0509 = $(this).getRowData(rowId);

    //浮动层
    var strButtonHtml = "";
    if (objSelRowP0509.zt == "已停用") {
        strButtonHtml = "<a onclick=\"setZtP0509('" + rowId + "')\">启用</a>-<a onclick=\"showDialogP050901('2');\">修改</a>-<a onclick=\"deleteDataP0509('" + rowId + "')\">删除</a>";
    }
    else if (objSelRowP0509.zt == "已启用") {
        strButtonHtml = "<a onclick=\"setZtP0509('" + rowId + "')\">停用</a>-<a onclick=\"showDialogP050901('3');\">查看</a>";
    }

    //回调
    createFloatButton.call(this, rowId, strButtonHtml);
}

//搜索头部信息
function getSearchInfoP0509() {

    //设置combobox
    $("#cmbZyP0509").combobox();

    //下拉箭头样式
    addArrowClass();

    //提成职员
    var objZy = getComboboxData("TZyxx2");

    //提成职员
    $("#cmbZyP0509").combobox({
        width: _iWidth150,
        listWidth: _iWidth150,
        textField: "mc",
        valueField: "dm",
        onfocus: function () {
            if ($(this).combobox("getText") == "提成职员") {
                $(this).combobox("setText", "");
            }
        },
        onblur: function () {
            if ($(this).combobox("getText") == "") {
                $(this).combobox("setText", "提成职员");
            }
        }
    });
    if (objZy != null && objZy != "{}") {
        objZy.unshift({ dm: "", mc: "全部职员", selected: true });
        $("#cmbZyP0509").combobox("loadData", objZy);
    }

}

//双击事件
function dbClickP0509(strType, rowId) {

    //行对象
    objSelRowP0509 = $(this).getRowData(rowId);

    //弹出对话框
    if (objSelRowP0509.zt == "已启用") {
        showDialogP050901('3');
    }
    else {
        showDialogP050901('2');
    }
}

//排序
function sortDataP0509(index, colindex, sortorder) {

    //清除浮动层
    $("div.operate").hide();

    //分页排序
    objPageParamP0509.sortfield = index;
    objPageParamP0509.orderby = sortorder;

    //取数据
    loadGridData_Page(objPageParamP0509);

    //设置分页参数
    objPageParamP0509.flag = 0;

    return 'stop';
}

//搜索数据
function searchDataClickP0509(sortName, sortOrder) {

    //提成职员
    if (!$("#cmbZyP0509").combobox('getValue')) {
        $("#cmbZyP0509").combobox('setValue', "");
    }

    //组查询条件
    var strWhereJson = "";
    strWhereJson += "\"zydm\":\"" + $("#cmbZyP0509").combobox("getValue") + "\"";
    objPageParamP0509.where = strWhereJson;

    //取数据
    loadGridData_Page(objPageParamP0509);

    //设置分页参数
    objPageParamP0509.flag = 0;

    //清除浮动按钮
    $("div.operate").hide();

}

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

    //当页面信息已修改时，弹出提示保存
    if (isTextChange == true) {
        //函数名称
        window.parent.cihoAlert(
            msg.other.haveChange
            , msgBox.dlgBtn.YesNoCancel
            , function (strRet) {
                if (msgBox.dlgRst.Yes == strRet) {
                    saveMyData(strDialog, 0, strTable);
                }
                else if (msgBox.dlgRst.No == strRet) {
                    cihoDlgClose(strDialog);
                    if (strDialog == "divP050901") {
                        freeMemory_P050901();
                    }
                }
            });
    }
    else {
        //关闭预提规则区间设置
        if (strDialog == "divP050902" && RulesList.Rules.length != 0 && checkFormP050902(strDialog, strType) == false) {
            return;
        }
        //其他页面关闭
        cihoDlgClose(strDialog);

        //预提规则维护释放内存
        if (strDialog == "divP050901") {
            freeMemory_P050901();
        }
    }
}

//保存数据
function saveMyData(strDialog, strType, strTable) {

    try {
        if (strTable == strTableP050901) {
            saveDataP050901(strDialog, strType);
            changePageZt("p0509", "1");
        }
        else if (strTable == strTableP050902) {
            saveDataP050902(strDialog, strType);
        }
        else if (strTable == "TFlsz") {
            saveData_P06020101(strType);
        }
        else if (strTable == "Tp050904") {
            saveDataP050904();
        }
        else if (strTable == "TKjkm") {
            saveMyDataTp060601(strDialog, strType);
        }
        //添加分类
        else if (strTable == ciho.layal.table) {
            ciho.saveType();

            //刷新管理画面的职员
            var objZy = getComboboxData("TZyxx2");
            objZy.unshift({ mc: "全部职员", dm: "", selected: true });
            $("#cmbZyP0509").combobox("loadData", objZy);

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

//删除数据
function deleteDataP0509() {
    try {
        window.parent.cihoAlert(msg.del.delConfirm, msgBox.dlgBtn.YesNo, function (result) {
            if (result == msgBox.dlgRst.Yes) {
                //删除数据信息
                var objResult = ParseData(window.external.DoOptions(strTableP0509, 'Delete', "{\"gzguid\":\"" + objSelRowP0509.gzguid + "\"}"));
                //删除成功后，重新加载数据
                if (objResult.ReturnCode == 0) {
                    objPageParamP0509.flag = 2;
                    searchDataClickP0509();
                    changePageZt("p0509", "1");
                    changePageZt("p0509", "2");
                }
                else {
                    window.parent.cihoAlert(objResult.MSG);
                }
            }
        });
    }
    catch (e) {
        proceError("P0509", e.ToString());
    }
}

