/*--------------------------文档信息-------------------------------------------
///功能：      采购返现单
///创建人：  王群
///创建时间：2011年05月31日
///修改人：  --------------
///修改时间：--------------
///详细说明：--------------
-----------------------------------------------------------------------------*/
//定义全局变量
strTableP011202_fxd = "Tp010202";       //表格的ID

//查看采购返现的单据
function showDialogP011202_fxd(strDivP011202_fxd, strDjbh) {
    try {
        $(".operate").remove();                 //清除浮动按钮层
        $("#divP011202_fxd").empty();    //清空弹出窗口内容

        //把弹出窗口框架及底部按钮添加到父窗口创建dialog中
        creatDiv_ShowDlgHaveTbl(strDivP011202_fxd, "返现单据", false, false, strTableP011202_fxd, "600");

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

        //调用所查数据同时加载到所对应的控件
        myListp011202_fxd(strDivP011202_fxd, strDjbh);

        //重新设定dialog位置
        //$("#" + strDivP011202_fxd).dialog("option", "position", "center");

        //释放内存
        strDivP011202_fxd = null;
        strDjbh = null;
    } catch (e) { }
}

//创建表单
function tableFormP011202_fxd(strDivP011202_fxd, strDjbh) {
    var strHeadp011202_fxd = "";            //存放页头的内容
    var strTablep011202_fxd = "";           //存放表格的内容
    var strDownp011202_fxd = "";           //存放页尾的内容
    var objp011202_fxd = {};                   //存放列配置
    var strPageHeader = [];                     //存放页头列配置
    var strpageFooter = [];                      //存放页尾列配置

    //加载编号的语句
    $("#idMust", $("#divP011202_fxd")).append("NO:" + strDjbh);

    //获得jqGrid的列名和属性
    objp011202_fxd = ParseData(window.external.DoOptions("Tp010202", 'GetTableConfig', '{}'));
    strPageHeader = objp011202_fxd.pageHeader;
    strpageFooter = objp011202_fxd.pageFooter;

    strHeadp011202_fxd = "<ul>";
    for (var i = 0; i < strPageHeader.length; i++) {        //创建页头
        if (strPageHeader[i]["name"] == "gysmc" || strPageHeader[i]["name"] == "jsrmc" || strPageHeader[i]["name"] == "djbh") {
            continue;
        }
        else {
            if (strPageHeader[i]["name"] == "gysdm") {
                strHeadp011202_fxd += "<li class='inp_150'>";
                strHeadp011202_fxd += strPageHeader[i]["xsmc"] + "：";
                strHeadp011202_fxd += "<input type='text'  value=''  name='" + strPageHeader[i]["name"] + "' disabled";
                strHeadp011202_fxd += " id='" + strPageHeader[i]["name"] + "' maxlength='50'/>"; //限制输入长度
                strHeadp011202_fxd += "</li>";
            }
            else {
                strHeadp011202_fxd += "<li class='inp_70'>";
                strHeadp011202_fxd += strPageHeader[i]["xsmc"] + "：";
                strHeadp011202_fxd += "<input type='text'  value=''  name='" + strPageHeader[i]["name"] + "' disabled";
                strHeadp011202_fxd += " id='" + strPageHeader[i]["name"] + "' maxlength='50'/>"; //限制输入长度
                strHeadp011202_fxd += "</li>";
            }
        }
    }
    strHeadp011202_fxd += "</ul>";
    $("#" + strDivP011202_fxd + "_divform").append(strHeadp011202_fxd);

    strTablep011202_fxd += "<table id='Tp010202'></table>";           //创建表格
    $("#" + strDivP011202_fxd + "_divform").append(strTablep011202_fxd);

    strDownp011202_fxd = "<ul>";
    for (var i = 0; i < strpageFooter.length; i++) {        //创建页尾
        if (strpageFooter[i]["name"] == "zdrmc" || strpageFooter[i]["name"] == "skje") {
            continue;
        }
        else {
            if (strpageFooter[i]["name"] == "bz") {
                strDownp011202_fxd += "<li class='bz'>";
                strDownp011202_fxd += strpageFooter[i]["xsmc"] + "：";
                strDownp011202_fxd += "<input type='text'  value=''  name='" + strpageFooter[i]["name"] + "' disabled";
                strDownp011202_fxd += " id='" + strpageFooter[i]["name"] + "'  class='decimal'/> "; //限制输入长度
                strDownp011202_fxd += "</li>";
            }
            else if (strpageFooter[i]["name"] == "czydm") {
                strDownp011202_fxd += "<li class='inp_70'>";
                strDownp011202_fxd += strpageFooter[i]["xsmc"] + "：";
                strDownp011202_fxd += "<input type='text'  value=''  name='" + strpageFooter[i]["name"] + "' disabled";
                strDownp011202_fxd += " id='" + strpageFooter[i]["name"] + "' maxlength='50' class='decimal'/> "; //限制输入长度
                strDownp011202_fxd += "</li>";
            }
            else {
                strDownp011202_fxd += "<li class='inp_150'>";
                strDownp011202_fxd += strpageFooter[i]["xsmc"] + "：";
                strDownp011202_fxd += "<input type='text'  value=''  name='" + strpageFooter[i]["name"] + "' disabled";
                strDownp011202_fxd += " id='" + strpageFooter[i]["name"] + "' maxlength='50' class='decimal'/> "; //限制输入长度
                strDownp011202_fxd += "</li>";
            }
        }
    }
    strDownp011202_fxd += "</ul>";
    $("#" + strDivP011202_fxd + "_divform").append(strDownp011202_fxd);

    //释放内存
    strHeadp011202_fxd = null;
    strTablep011202_fxd = null;
    strDownp011202_fxd = null;
    objp011202_fxd = null;
    strPageHeader = null;
    strpageFooter = null;
}

//从后台加载所查单据数据
function myListp011202_fxd(strDivP011202_fxd, strDjbh) {
    try {
        var objp011202_fxd = {};                //存放列配置
        var objResultp011202_fxd = {};      //存放查看返回的结果
        var myList = [];                                //存放返回的数据

        //获得jqGrid的列名和属性
        objp011202_fxd = ParseData(window.external.DoOptions("Tp010202", 'GetTableConfig', '{}'));
        objResultp011202_fxd = ParseData(window.external.DoOptions(strTableP011202_fxd, 'GetList', '{"djbh":"' + strDjbh + '"}'));
        if (objResultp011202_fxd.Records == "{}") {
            objResultp011202_fxd.Records = {};
        }

        //获取一下返回的结果赋给myList
        myList = objResultp011202_fxd.Records;

        if (myList[0].fxje != "") {
            myList[0].fxje = parseFloat(myList[0].fxje).toFixed(window.parent.strMoneyPlace);
        }

        //创建表格
        createGrid_P011202_fhd("Tp010202", objp011202_fxd.colNames, objp011202_fxd.colModel, []);
        //给表格加载数据
        $("#" + strTableP011202_fxd).addRowData("1", myList);

        //给返货日期绑定值
        $("#fxdate").val(objResultp011202_fxd.fxdate);
        //给供应商绑定值
        $("#gysdm", $("#" + strDivP011202_fxd + "_divform")).val(myList[0].gysmc);
        //给经销人绑定值
        $("#zydm", $("#" + strDivP011202_fxd + "_divform")).val(myList[0].jsrmc);
        //给付款账户绑定值
        $("#zhmc", $("#" + strDivP011202_fxd + "_divform")).val(myList[0].zhmc);
        //给付款金额绑定值
        $("#skje", $("#" + strDivP011202_fxd + "_divform")).val(parseFloat(objResultp011202_fxd.skje).toFixed(window.parent.strMoneyPlace));
        //给付款日期赋值
        $("#skdate", $("#" + strDivP011202_fxd + "_divform")).val(objResultp011202_fxd.skdate);
        //给制单人赋值
        $("#czydm", $("#" + strDivP011202_fxd + "_divform")).val(myList[0].zdrmc);
        //给备注赋值
        $("#bz", $("#" + strDivP011202_fxd + "_divform")).val(escape(myList[0].bz));
        //增加表头‘序号’列
        $("#" + strTableP011202_fxd).setLabel("rn", "序号");

        //释放内存
        objp011202_fxd = null;
        objResultp011202_fxd = null;
        myList = null;
    } catch (e) { }
}

/*-------------------------------------------------------------
功能：创建普通表格
*****①strTableID：表格的ID
*****②objColNames:表格需要显示的列名
*****③objColModel：表格的列配置
*****④objJsonData：表格中需要加载的数据
-----------------------------------------------------------------*/
function createGrid_P011202_fxd(strTableID, objColNames, objColModel, objJsonData) {
    $("#" + strTableID).jqGrid({
        datatype: "local",
        colNames: objColNames,
        colModel: objColModel,
        data: objJsonData,
        rownumbers: true,
        rowNum: 1,
        sortname: "id",
        cellEdit: false,
        cellsubmit: "clientArray",
        autowidth: true
    });
    //设置表格高度
    $("#" + strTableID).setGridHeight(47);
    //设置表格的列宽度
    resizeGridScroll(strTableID);
}