/*-------------------------------文档信息-----------------------------------
///功能：工资支付单单据
///创建人: 翟新乐
///创建时间：----------------------
///修改人：------------------------
///修改时间：-----------------------
///修改原因：-----------------------
///详细说明：-----------------------
---------------------------------------------------------------------*/
var strTableP051801_zfd = "Tp050803";       //表格ID
var strDlgId_zfd = "";                  //弹出层ID

//打开单据
function openP051801_Zfd(dlgId, strDjbh) {
    $("#" + dlgId).empty();
    strDlgId_zfd = dlgId;
    creatDiv_ShowDlgHaveTbl(dlgId, "工资支付单", false, false, strTableP051801_zfd, "600");

    var config = ParseData(window.external.DoOptions(strTableP051801_zfd, "GetTableConfig", "{}"));      // 向后台请求配置信息
    var header = createInputs(config.pageHeader);            // 根据头配置 生成表单元素 
    var footer = createInputs(config.pageFooter);              //根据脚信息   生成表单元素
    $("#" + strDlgId_zfd + "_divform").append(header).append('<table id="' + strTableP051801_zfd + '"></table>').append(footer);
    for (var i = 0; i < config.colModel.length; i++) {
        config.colModel[i].editable = false;
        if (config.colModel[i].index == "cz") {
            config.colModel[i].hidden=true;
        }
    }
    createDjGrid(strTableP051801_zfd, config.colNames, config.colModel);
    //$("#gbox_" + strTableP051801_zfd).css("height", "157");
    $("#" + strTableP051801_zfd).setGridHeight(141);
    //$("table.ui-jqgrid-htable th:first", "#" + strDlgId_zfd).text("序号");
    $("#" + strTableP051801_zfd).setLabel("rn", "序号");
    $("#" + strTableP051801_zfd).setColProp("yfhj", { formatter: formatMoneyPlace });
    $("#" + strTableP051801_zfd).setColProp("sfgz", { formatter: formatMoneyPlace });
    $("#" + strTableP051801_zfd).setColProp("ye", { formatter: formatMoneyPlace });
    initInputsProp(strTableP051801_zfd, strDlgId_zfd);
    var mylist = [];                                                                                // 修改，为标签赋值
    $("#idMust", "#" + strDlgId_zfd).text("NO:" + strDjbh);
    var record = ParseData(window.external.DoOptions(strTableP051801_zfd, "GetList", '{"djbh":"' + strDjbh + '","cztype":"2","djdate":"' + objSelRowP051801.djdate + '"}'));
    if (record.ReturnCode == 0) {
        $("#bz", "#" + strDlgId_zfd).val(escape(record.bz));
        $("#czydm", "#" + strDlgId_zfd).val(record.czymc);
        $("#djdate", "#" + strDlgId_zfd).val(record.djdate).attr("disabled", true);
        var $km = $("#kmdm", "#" + strDlgId_zfd);
        $km.combobox("setValue", record.kmdm);
        if ($km.combobox("getText") == record.kmdm) {
            $km.combobox("setText", record.kmmc);
        }
        if (record.Records instanceof Array) {
            mylist = record.Records;
        }
        $("#"+strDlgId_zfd).data("data", { "czydm": record.czydm, "czymc": record.czymc, "kmdm": record.kmdm, "kmmc": record.zhmc, "djbh": record.djbh });
    } else {
        window.parent.cihoAlert(record.MSG, msgBox.dlgBtn.Ok);
    }

    loadGridData(strTableP051801_zfd, mylist);
    //调整表格的自适应的高度
    resizeGridScroll(strTableP051801_zfd);
    $("#" + strDlgId_zfd).dialog("option", "position", "center");
    config = null;
    header = null;
    footer = null;
    mylist = {};
    record = {};
    $km = null;
}

//设置属性
function initInputsProp(tbId, dlgId) {
    $("#djdate,#kmdm,#czydm", "#" + dlgId).parent().addClass("inp_70");
    $("#bz", "#" + dlgId).parent().addClass("bz");

    $("#czydm", "#" + dlgId).attr("disabled", true);

    //为combobox下拉框加载选项。并注册事件
    $("#kmdm", "#" + dlgId).combobox({
        valueField: "dm",
        textField: "mc",
        width: _iWidth80,
        onSelect: function (option) {
            changeZt(tbId);
        }
    });
    var kmlist = getComboboxData("TKjkm");
    $("#kmdm", "#" + dlgId).combobox("loadData", kmlist);
    $(".layoutpanel").css("z-index", "50000009");
    kmlist = {};
}

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