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

//查看采购返货的单据事件方法
function showDialogP011202_fhd(strDialogIdP011202_fhd, strDjbh) {
    try {
        $(".operate").remove();                    //清除浮动按钮层
        $("#divP011202_fhd").empty();       //清空弹出窗口内容

        //把弹出窗口框架及底部按钮添加到父窗口创建dialog中
        creatDiv_ShowDlgHaveTbl(strDialogIdP011202_fhd, "返货单据", false, false, strTableP011202_fhd, "900");

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

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

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

//创建表单
function tableFormP011202_fhd(strDialogIdP011202_fhd, strDjbh) {
    var strHeadp011202_fhd = "";           //存放页头的内容
    var strTablep011202_fhd = "";           //存放表格的内容
    var strDownp011202_fhd = "";           //存放页尾的内容
    var objp011202_fhd = {};                   //存放从后获得列配置
    var strPageHeader = [];                      //存放页头的列配置
    var strpageFooter = [];                       //存放页尾的列配置
    
    //加载编号的语句
    $("#idMust", $("#" + strDialogIdP011202_fhd)).append("NO:" + strDjbh);

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

    strHeadp011202_fhd = "<ul>";
    for (var i = 0; i < strPageHeader.length; i++) {        //创建页头
        if (strPageHeader[i]["name"] == "gysmc" || strPageHeader[i]["name"] == "jsrmc" || strPageHeader[i]["name"] == "ckmc") {
            continue;
        }
        if (strPageHeader[i]["name"] == "fhdate") {
            strHeadp011202_fhd += "<li class='inp_70'>";
            strHeadp011202_fhd += strPageHeader[i]["xsmc"] + "：";
            strHeadp011202_fhd += "<input type='text'  value=''  name='" + strPageHeader[i]["name"] + "' disabled";
            strHeadp011202_fhd += " id='" + strPageHeader[i]["name"] + "'/>"; //限制输入长度
            strHeadp011202_fhd += "</li>";
        }
        else {
            strHeadp011202_fhd += "<li class='inp_150'>";
            strHeadp011202_fhd += strPageHeader[i]["xsmc"] + "：";
            strHeadp011202_fhd += "<input type='text'  value=''  name='" + strPageHeader[i]["name"] + "' disabled";
            strHeadp011202_fhd += " id='" + strPageHeader[i]["name"] + "'/> "; //限制输入长度
            strHeadp011202_fhd += "</li>";
        }
    }
    strHeadp011202_fhd += "</ul>";

    $("#" + strDialogIdP011202_fhd + "_divform").append(strHeadp011202_fhd);
    strTablep011202_fhd += "<table id='Tp010201'></table>";         //创建表格
    $("#" + strDialogIdP011202_fhd + "_divform").append(strTablep011202_fhd);
    strDownp011202_fhd += "<ul>";
    strDownp011202_fhd += "<li class='unline'>";
    strDownp011202_fhd += "<input type='checkbox'  value=''  name='fy'";
    strDownp011202_fhd += " id='fy' disabled/>"; //限制输入长度
    strDownp011202_fhd += "开票费用";
    strDownp011202_fhd += "</li>";
    for (var i = 0; i < strpageFooter.length; i++) {            //创建页尾
        if (strpageFooter[i]["name"] == "zhmc" || strpageFooter[i]["name"] == "zdrmc") {
            continue;
        }
        else {
            if (strpageFooter[i]["name"] == "fkdate" || strpageFooter[i]["name"] == "fkje" || strpageFooter[i]["name"] == "kmdm") {
                strDownp011202_fhd += "<li class='inp_150'>";
                strDownp011202_fhd += strpageFooter[i]["xsmc"] + "：";
                strDownp011202_fhd += "<input type='text'  value=''  name='" + strpageFooter[i]["name"] + "' disabled";
                strDownp011202_fhd += " id='" + strpageFooter[i]["name"] + "' maxlength='50' class='decimal'/> "; //限制输入长度
                strDownp011202_fhd += "</li>";
            }
            else if (strpageFooter[i]["name"] == "czydm") {
                strDownp011202_fhd += "<li class='inp_70'>";
                strDownp011202_fhd += strpageFooter[i]["xsmc"] + "：";
                strDownp011202_fhd += "<input type='text'  value=''  name='" + strpageFooter[i]["name"] + "' disabled";
                strDownp011202_fhd += " id='" + strpageFooter[i]["name"] + "' maxlength='50' class='decimal' />"; //限制输入长度
                strDownp011202_fhd += "</li>";
            }
            else {
                strDownp011202_fhd += "<li class='bz'>";
                strDownp011202_fhd += strpageFooter[i]["xsmc"] + "：";
                strDownp011202_fhd += "<input type='text'  value=''  name='" + strpageFooter[i]["name"] + "' disabled";
                strDownp011202_fhd += " id='" + strpageFooter[i]["name"] + "'  class='decimal' />"; //限制输入长度
                strDownp011202_fhd += "</li>";
            }
        }
    }
    strDownp011202_fhd += "</ul>";
    $("#" + strDialogIdP011202_fhd + "_divform").append(strDownp011202_fhd);

    //释放内存
    strHeadp011202_fhd = null;
    strTablep011202_fhd = null;
    strDownp011202_fhd = null;
    objp011202_fhd = null;
    strPageHeader = null;
    strpageFooter = null;
}

//从后台加载所查单据数据
function myListp011202_fhd(strDialogIdP011202_fhd, strDjbh) {
    try {
        var objp011202_fhd = {};                    //存放从后台取得列配置
        var objResultp011202_fhd = {};          //存放从后台返回的结果
        var myList = [];                                    //存放从后取得数据集
        //获得jqGrid的列名和属性
        objp011202_fhd = ParseData(window.external.DoOptions("Tp010201", 'GetTableConfig', '{}'));
        objResultp011202_fhd = ParseData(window.external.DoOptions(strTableP011202_fhd, 'GetList', '{"djbh":"' + strDjbh + '"}'));
        if (objResultp011202_fhd.Records == "{}") {
            objResultp011202_fhd.Records = [];
        }
        myList = objResultp011202_fhd.Records;

        if (myList[0].a3 == "True") {   //值为true时就给其赋值为【是】
            myList[0].a3 = "是";
        }
        else if (myList[0].a3 == "False") {     //值为false时就给其赋值为【否】
            myList[0].a3 = "否";
        }
        if (myList[0].kmdm != "") {
            $("#fy").attr("checked", true);
            //给付款账户绑定值
            $("#kmdm", $("#" + strDialogIdP011202_fhd + "_divform")).val(myList[0].zhmc);
            //给付款金额绑定值
            $("#fkje", $("#" + strDialogIdP011202_fhd + "_divform")).val(parseFloat(objResultp011202_fhd.fkje).toFixed(window.parent.strMoneyPlace));
            //给付款日期赋值
            $("#fkdate", $("#" + strDialogIdP011202_fhd + "_divform")).val(objResultp011202_fhd.fkdate);
        }
        if (myList[0].a1) {      //格式化返货数量
            myList[0].a1 = parseFloat(myList[0].a1).toFixed(window.parent.strCountPlace);
        }
        if (myList[0].a2) {     //格式化返货单价
            myList[0].a2 = parseFloat(myList[0].a2).toFixed(window.parent.strPricePlace);
        }
        if (myList[0].fhje) {    //格式化返货金额
            myList[0].fhje = parseFloat(myList[0].fhje).toFixed(window.parent.strMoneyPlace);
        }
        if (myList[0].a4) {     //格式化开票数量
            myList[0].a4 = parseFloat(myList[0].a4).toFixed(window.parent.strCountPlace);
        }
        if (myList[0].a5) {     //格式化开票单价
            myList[0].a5 = parseFloat(myList[0].a5).toFixed(window.parent.strPricePlace);
        }
        if (myList[0].kpje) {    //格式化开票金额
            myList[0].kpje = parseFloat(myList[0].kpje).toFixed(window.parent.strMoneyPlace);
        }

        //创建表格
        createGrid_P011202_fhd("Tp010201", objp011202_fhd.colNames, objp011202_fhd.colModel, []);
        //给表格加载数据
        $("#" + strTableP011202_fhd).addRowData("1", myList);
        //给返货日期绑定值
        $("#fhdate", $("#" + strDialogIdP011202_fhd + "_divform")).val(objResultp011202_fhd.fhdate);
        //给供应商绑定值
        $("#gysdm", $("#" + strDialogIdP011202_fhd + "_divform")).val(myList[0].gysmc);
        //给经销人绑定值
        $("#zydm", $("#" + strDialogIdP011202_fhd + "_divform")).val(myList[0].jsrmc);
        //给仓库绑定值
        $("#ckdm", $("#" + strDialogIdP011202_fhd + "_divform")).val(myList[0].ckmc);
        //给制单人赋值
        $("#czydm", $("#" + strDialogIdP011202_fhd + "_divform")).val(myList[0].zdrmc);
        //给备注赋值
        $("#bz", $("#" + strDialogIdP011202_fhd + "_divform")).val(escape(myList[0].bz));
        //释放内存
        objp011202_fhd = null;
        objResultp011202_fhd = null;
        myList = null;
    } catch (e) { }
}

/*-------------------------------------------------------------
功能：创建普通表格
*****①strTableID：表格的ID
*****②objColNames:表格需要显示的列名
*****③objColModel：表格的列配置
*****④objJsonData：表格中需要加载的数据
-----------------------------------------------------------------*/
function createGrid_P011202_fhd(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);
}