/*-------------------------------文档信息-----------------------------------
///功能：采购退货单单据
///创建人: 翟新乐
///创建时间：----------------------
///修改人：------------------------
///修改时间：-----------------------
///修改原因：-----------------------
///详细说明：-----------------------
---------------------------------------------------------------------*/
var strTableP011302_thd = "Tp010102";       //表格Id
var strDlgIdP011302_thd="" ;                //弹出层ID
var strRecordsP011302_thd = 1;       //添加空行
var strDjbh_thd;            //单据编号

//打开单据窗口
function showDialogP011302_fhd(strDialogId, strDjbh) {
    strDlgIdP011302_thd = strDialogId;
    strDjbh_thd = strDjbh;
    $(".operate").remove();
    $("#" + strDlgIdP011302_thd).empty();
    //创建窗口
    creatDiv_ShowDlgHaveTbl(strDlgIdP011302_thd, "采购退货单", false, false, strTableP011302_thd,"850");
    //$(".pop").css("width", "910");
    //取得列配置
    var objConfig = ParseData(window.external.DoOptions(strTableP011302_thd, "GetTableConfig", "{}"));
    for (var i = 0; i < objConfig.colModel.length; i++) {
        if (objConfig.colModel[i].index=="cz") {
            objConfig.colModel[i].hidden = true;
        }
    }
    //头部控件
    var header = tableFormP011302_thd(objConfig.pageHeader);
    //尾部控件
    var footer = tableFormP011302_thd(objConfig.pageFooter);
    //添加控件到div
    $("#idMust", $("#" + strDlgIdP011302_thd)).append("NO:" + strDjbh_thd);
    $("#" + strDlgIdP011302_thd + "_divform").append(header);
    $("#" + strDlgIdP011302_thd + "_divform").append('<table id="' + strTableP011302_thd + '"></table>');
    $("#" + strDlgIdP011302_thd + "_divform").append(footer);
    
    //设定combobox
    $("#gysdm", $("#" + strDlgIdP011302_thd + "_divform")).combobox();
    $("#ckdm", $("#" + strDlgIdP011302_thd + "_divform")).combobox();
    $("#zydm", $("#" + strDlgIdP011302_thd + "_divform")).combobox();
    $("#kmdm", $("#" + strDlgIdP011302_thd + "_divform")).combobox();
   
    //创建grid
    createGridP011302_thd(strTableP011302_thd, objConfig.colNames, objConfig.colModel);
    //$("#gbox_" + strTableP011302_thd).css("height", "53px");
    $("#" + strTableP011302_thd).setGridHeight(47);
    resizeGridScroll(strTableP011302_thd);
    var objTable = $("#" + strTableP011302_thd);
    //格式化
    objTable.setColProp("b1", { formatter: formatterP011302b1 });
    objTable.setColProp("b2", { formatter: formatterP011302b2 });
    objTable.setColProp("b3", { formatter: formatterP011302b3 });
    objTable.setColProp("tpje", { formatter: formatterP011302b3 });
    objTable.setColProp("tpdj", { formatter: formatterP011302b2 });
    objTable.setColProp("tpsl", { formatter: formatterP011302b1 });
    //加载数据
    myListP011302_thd();
    //$("#" + strDlgIdP011302_thd).dialog("option", "position", "center");
    header = null;
    footer = null;
    strTop = null;
    objTable = null;
    objConfig = {};
}

//表单
function tableFormP011302_thd(arrModel) {
    var strForm = "";
    strForm += "<ul>";
    for (var i = 0; i < arrModel.length; i++) {
        var Item = arrModel[i];
        if (Item.hidden == true) {
            continue;
        }
        else {
            if (Item["name"] == "djdate" || Item["name"] == "zydm" || Item["name"] == "ckdm" || Item["name"] == "kmdm"
        || Item["name"] == "sfkdate" || Item["name"] == "a5") {
                strForm += "<li class='inp_100'>";
                strForm += Item.xsmc + "：";
                strForm += "<input type='text'  name='" + Item.index + "' disabled ";
                strForm += " value=''  ";
                strForm += " id='" + Item.index + "'>";
                strForm += "</li>";
            }
            else if (Item["name"] == "gysdm" || Item["name"] == "czydm") {
                strForm += "<li class='inp_150'>";
                strForm += Item.xsmc + "：";
                strForm += "<input type='text'  name='" + Item.index + "' disabled ";
                strForm += " value=''  ";
                strForm += " id='" + Item.index + "'>";
                strForm += "</li>";
            }
            else {
                strForm += "<li class='bz'>";
                strForm += Item.xsmc + "：";
                strForm += "<input type='text'  name='" + Item.index + "' disabled ";
                strForm += " value=''  ";
                strForm += " id='" + Item.index + "'>";
                strForm += "</li>";
            }
         
        }
    }
    strForm += "</ul>";
    arrModel = null;
    Item = null;
    return strForm;
}

//加载数据
function myListP011302_thd() {
    var objResult = ParseData(window.external.DoOptions(strTableP011302_thd, "GetList", '{"djbh":"' + strDjbh_thd + '"}'))
    if (objResult.Records == "{}") {
        window.parent.cihoAlert(objResult.MSG);
        return;
    }
    else {
        for (var intI = 0; intI < objResult.Records.length; intI++) {
            if (objResult.Records[intI].a3=="False") {
                objResult.Records[intI].a3 = "否";
            }
            else {
                objResult.Records[intI].a3 = "是";
            }
        }
        loadTreeData(strTableP011302_thd, objResult.Records);
        
    }
    $("#djdate", $("#" + strDlgIdP011302_thd + "_divform")).val(objResult.djdate);
    $("#gysdm", $("#" + strDlgIdP011302_thd + "_divform")).combobox('setText', objResult.gysmc);
    $("#zydm", $("#" + strDlgIdP011302_thd + "_divform")).combobox('setText', objResult.zymc);
    $("#ckdm", $("#" + strDlgIdP011302_thd + "_divform")).combobox('setText', objResult.ckmc);
    $("#kmdm", $("#" + strDlgIdP011302_thd + "_divform")).combobox('setText', objResult.zhmc);
    if (!isNaN(parseFloat(objResult.a5))) {
        $("#a5", $("#" + strDlgIdP011302_thd + "_divform")).val(parseFloat(objResult.a5).toFixed(window.parent.strMoneyPlace));
    }
    else {
        $("#a5", $("#" + strDlgIdP011302_thd + "_divform")).val(objResult.a5);
    }
    $("#sfkdate", $("#" + strDlgIdP011302_thd + "_divform")).val(objResult.sfkdate);

    $("#a9", $("#" + strDlgIdP011302_thd + "_divform")).val(escape(objResult.a9));
    $("#czydm", $("#" + strDlgIdP011302_thd + "_divform")).val(objResult.Records[0]["czymc"]);
    objResult = {};
}

//grid
function createGridP011302_thd(strTableID, objColNames, objColModel) {
    $("#" + strTableID).jqGrid({
        datatype: "local",
        colNames: objColNames,
        colModel: objColModel,
        data: [],
        rownumbers: true,
        rowNum: 1,
        autowidth: true,
        sortable: false,
        //height: "100%",
        footerrow: false,
        gridview: true,
        rownumWidth: 30
    }); //.parent(".ui-jqgrid-bdiv").siblings().css("width", "100%");

    //增加表头‘序号’列
    //$("table.ui-jqgrid-htable th:first", $("#gbox_" + strTableID)).text("序号");
    $("#" + strTableID).setLabel("rn", "序号");
}

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

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

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