/*--------------------------文档信息-------------------------------------------
///功能：      应收单的查看单据
///创建人：  王群
///创建时间：2011年05月31日
///修改人：  --------------
///修改时间：--------------
///详细说明：--------------
-----------------------------------------------------------------------------*/
//定义全局变量
strTableP021503_ysd = "Tp020201";

//查看单据
function showDialogP021503_ysd(strDivP021503_ysd, strDjbh) {
    try {
        $(".operate").remove();                             //清除浮动按钮层
        $("#" + strDivP021503_ysd).empty();      //清空弹出窗口内容

        //把弹出窗口框架及底部按钮添加到父窗口创建dialog中
        creatDiv_ShowDlgHaveTbl(strDivP021503_ysd, "应收调整单", true, false, strTableP021503_ysd, "650");

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

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

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

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

//创建表单
function tableFormP021503_ysd(strDivP021503_ysd, strDjbh) {
    var strTablep021503_ysd = "";       //默认表格为空
    var strDownp021503_ysd = "";       //页尾默认为空
    var objp021503_ysd = {};                //存放列配置
    var strpageFooter = [];                    //存放页尾的列配置

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

    //获得jqGrid的列名和属性
    objp021503_ysd = ParseData(window.external.DoOptions(strTableP021503_ysd, 'GetTableConfig', '{}'));
    strpageFooter = objp021503_ysd.pageFooter;

    strTablep021503_ysd += "<table id='Tp020201'></table>";             //创建表格
    $("#" + strDivP021503_ysd + "_divform").append(strTablep021503_ysd);

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

    //释放内存
    strTablep021503_ysd = null;
    strDownp021503_ysd = null;
    objp021503_ysd = null;
    strpageFooter = null;
}

//从后台加载所有单据数据
function myListp021503_ysd(strDivP021503_ysd, strDjbh) {
    try {
        var objP021503_ysd = {};                    //存放列配置
        var objResultP021503_ysd = {};          //存放返回信息
        var myList = [];                                    //存放返回的数据集
        //获得jqGrid的列名和属性
        objP021503_ysd = ParseData(window.external.DoOptions(strTableP021503_ysd, 'GetTableConfig', '{}'));
        objResultP021503_ysd = ParseData(window.external.DoOptions(strTableP021503_ysd, 'GetList', '{"djbh":"' + strDjbh + '"}'));


        if (objResultP021503_ysd.Records == "{}") {
            objResultP021503_ysd.Records = {};
        }

        myList = objResultP021503_ysd.Records;       //把返回的数据给【myList】

        if (myList[0].a3) {     //金额列的格式化
            myList[0].a3 = parseFloat(myList[0].a3).toFixed(window.parent.strMoneyPlace);
        }
        if (myList[0].a2) {     //数量列的格式化
            myList[0].a2 = parseFloat(myList[0].a2).toFixed(window.parent.strCountPlace);
        }

        //创建表格
        createGrid_P021503_ysd(strTableP021503_ysd, objP021503_ysd.colNames, objP021503_ysd.colModel, []);
        //给表格赋值
        $("#" + strTableP021503_ysd).addRowData("1", myList);
        //给制单人赋值
        $("#czymc", $("#" + strDivP021503_ysd + "_divform")).val(myList[0].czymc);
        //给备注赋值
        $("#a4", $("#" + strDivP021503_ysd + "_divform")).val(escape(myList[0].a4));

        //释放内存
        objP021503_ysd = null;
        objResultP021503_ysd = null;
    } catch (e) { }
}

/*-------------------------------------------------------------
功能：创建普通表格
*****①strTableID：表格的ID
*****②objColNames:表格需要显示的列名
*****③objColModel：表格的列配置
-----------------------------------------------------------------*/
function createGrid_P021503_ysd(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).setLabel("rn", "序号");
    //给表格设置高度
    $("#" + strTableID).setGridHeight(47);
    //调整表格列宽度
    resizeGridScroll(strTableID);
}