/*-------------------------------文档信息-----------------------------------
///功能：预提余额结转单单据
///创建人: 翟新乐
///创建时间：----------------------
///修改人：------------------------
///修改时间：-----------------------
///修改原因：-----------------------
///详细说明：-----------------------
---------------------------------------------------------------------*/
var strTableP051102_ytjzd = "Tp050605";           //表格的ID                

/*-----------------------------------------------------------------------------
//功能：点击添加按钮，弹出对话框
//参数：
//strTableP051102_ytjzd 表名
-----------------------------------------------------------------------------*/
function showDialog_ytjzd(strDivP051102_ytjzd, strDjbh) {
    try {
        //清空弹出窗口内容
        $("#" + strDivP051102_ytjzd).empty();

        //创建弹出窗口dialog
        creatDiv_ShowDlgHaveTbl(strDivP051102_ytjzd, "预提余额结转单", false, false, strTableP051102_ytjzd, "700");

        //添加表单元素到窗口中
        tableFormP051102_ytjzd(strDivP051102_ytjzd, strDjbh);

        setDjValueP051102_ytjzd(strDivP051102_ytjzd, strDjbh);
        //窗口中的元素添加完毕后，给dialog定位
        $("#" + strDivP051102_ytjzd).dialog("option", "position", "center");
    } catch (e) { }
}

//创建表单
function tableFormP051102_ytjzd(strDlgID,strDjbh) {
    //获得jqGrid的列名和属性
    var objCongig_ytjzd = ParseData(window.external.DoOptions(strTableP051102_ytjzd, 'GetTableConfig', '{}'));
    //获取列配置
    var strPageHeader = objCongig_ytjzd.pageHeader;
    var strpageFooter = objCongig_ytjzd.pageFooter;
    //创建页头
    var pageHead = "<ul>";
    for (var i = 0; i < strPageHeader.length; i++) {
        pageHead += "<li>";
        pageHead += strPageHeader[i]["xsmc"] + "：";
        pageHead += "<input id='" + strPageHeader[i]["index"] + "' name='" + strPageHeader[i]["name"] + "' type='text'  maxlength='50' disabled";
        pageHead += " onkeypress='return checkValidate(event)' onpaste='return validatePaste()'/>"; //限制输入，粘贴特殊字符
        pageHead += "</li>";
    }
    pageHead += "</ul>";
    //创建表格
    $("#" + strDlgID + "_divform").append(pageHead);
    var tableP050605_ytjzd = "<table id='Tp050605'><table>";
    $("#" + strDlgID + "_divform").append(tableP050605_ytjzd);
    //创建页尾
    var pageFoot = "<ul>";
    for (var i = 0; i < strpageFooter.length; i++) {
        if (strpageFooter[i]["name"] == "czymc") {
            continue;
        }
        if (strpageFooter[i]["name"] == "a2") {
            pageFoot += "<li class='bz'>";
            pageFoot += strpageFooter[i]["xsmc"] + "：";
            pageFoot += "<input id='" + strpageFooter[i]["index"] + "' name='" + strpageFooter[i]["name"] + "' type='text' disabled ";
            pageFoot += " onkeypress='return checkValidate(event)' onpaste='return validatePaste()'/>"; //限制输入，粘贴特殊字符
            pageFoot += "</li>";
        }
        else {
            pageFoot += "<li class='inp_70'>";
            pageFoot += strpageFooter[i]["xsmc"] + "：";
            pageFoot += "<input id='" + strpageFooter[i]["index"] + "' name='" + strpageFooter[i]["name"] + "' type='text'  maxlength='50' disabled";
            pageFoot += " onkeypress='return checkValidate(event)' onpaste='return validatePaste()'/>"; //限制输入，粘贴特殊字符
            pageFoot += "</li>";
        }
    }
    pageFoot += "</ul>";
    $("#" + strDlgID + "_divform").append(pageFoot);
    //创建表格
    createGridP051102_ytjzd(strTableP051102_ytjzd, objCongig_ytjzd.colNames, objCongig_ytjzd.colModel);
    //$("#gbox_" + strTableP051102_ytjzd).css("height", "53");
    $("#" + strTableP051102_ytjzd).setGridHeight(53);
    resizeGridScroll(strTableP051102_ytjzd);
    //设定制单人
    $("#czydm", "#" + strDlgID + "_divform").attr("disabled", true);
    objCongig_ytjzd = {};
    strpageFooter = null;
    strPageHeader = null;
    pageFoot = null;
    pageHead = null;
    tableP050605 = null;
}

//修改时，设定单据的原值
function setDjValueP051102_ytjzd(strDlgId,strDjbh) {
    var objRetRecord = ParseData(window.external.DoOptions(strTableP051102_ytjzd, 'GetList', "{'djbh':'" + strDjbh + "'}"));
    if (!objRetRecord) {
        //"DB操作失败！"
        window.parent.cihoAlert(msg.other.dbOprateErr);
        return;
    }
    else {
        if (objRetRecord.Records == "{}") {
            //数据为空
            window.parent.cihoAlert(msg.other.dataEmp);
            return;
        }
        else {
            //加载数据
            $("#" + strTableP051102_ytjzd).setColProp("a1", { formatter: formatterP051102Money_ytjzd });
            //填充表格
            loadTreeData(strTableP051102_ytjzd, objRetRecord.Records);
        }
    }
    //加载资金转账单编号
    $("#idMust", $("#" + strDlgId)).append("NO:" + objRetRecord.Records[0].djbh);
    //转账日期
    $("#djdate", $("#" + strDlgId + "_divform")).val(objRetRecord.Records[0].djdate);
    $("#czydm", $("#" + strDlgId + "_divform")).val(objRetRecord.Records[0]["czymc"]);
    $("#a2", $("#" + strDlgId + "_divform")).val(escape(objRetRecord.Records[0].a2));
    //释放内存
    objRetRecord = null;
}

/*----------------------------------------------------
功能：创建一个jqGrid表格
******strTableID：表格的ID
******objColNames：表格的列名
******objColModel：表格的列配
-----------------------------------------------------*/
function createGridP051102_ytjzd(strTableID, objColNames, objColModel) {
    $("#" + strTableID).jqGrid({
        datatype: "local",
        colNames: objColNames,
        colModel: objColModel,
        data: [],
        rownumbers: true,
        rowNum: 9999,
        sortname: "id",
        autowidth: true,
//        width: 600,
//        height: "100%",
        cellEdit: false,
        cellsubmit: "clientArray",
        gridview: true
    });
    //增加表头‘序号’列
    //$("table.ui-jqgrid-htable th:first", $("#gbox_" + strTableID)).text("序号");
    $("#" + strTableID).setLabel("rn", "序号");
}

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