/*--------------------------文档信息-------------------------------------------
///功能：      移库单的查看单据
///创建人：  王群
///创建时间：2011年05月31日
///修改人：  --------------
///修改时间：--------------
///详细说明：--------------
-----------------------------------------------------------------------------*/
//先定义一下全局变量
strTableP031201_ykd = "Tp030201";

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

        //把弹出窗口框架及底部按钮添加到父窗口创建dialog中
        creatDiv_ShowDlgHaveTbl(strDivP031201_ykd, "移库单", false, false, strTableP031201_ykd);

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

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

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

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

//创建表单
function tableFormP031201_ykd(strDivP031201_ykd, strDjbh) {
    var strHeadP031201_ykd = "";                 //页头默认为空
    var strFormTableP031201_ykd = "";        //表格默认为空
    var strDownP031201_ykd = "";                //页尾默认为空
    var objP031201_ykd = {};                        //存放列配置
    var strPageHeader = [];                           //存放页头的配置
    var strpageFooter = [];                            //存放页尾的配置

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

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

    strPageHeader = objP031201_ykd.pageHeader;
    strpageFooter = objP031201_ykd.pageFooter;

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

    strFormTableP031201_ykd += "<table id='Tp030201'></table>";         //创建表格
    $("#" + strDivP031201_ykd + "_divform").append(strFormTableP031201_ykd);

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

//从后台加载所查单据数据
function myListP031201_ykd(strDivP031201_ykd, strDjbh) {
    try {
        var objP031201_ykd = {};                    //存放列配置
        var objResultP031201_ykd = {};          //存放返回的信息
        var myList = [];                                    //存放返回的数据
        var count = 5;                                      //表格默认最少显示5条数据

        //获得jqGrid的列名和属性
        objP031201_ykd = ParseData(window.external.DoOptions(strTableP031201_ykd, 'GetTableConfig', '{}'));
        for (var i = 0; i < objP031201_ykd.colModel.length; i++) {
            if (objP031201_ykd.colModel[i].index == "cz") {
                objP031201_ykd.colModel[i].hidden = true;
            }
            if (objP031201_ykd.colModel[i].index == "spmc" || objP031201_ykd.colModel[i].index == "a1") {
                objP031201_ykd.colModel[i].align = "center";
            }
        }
        objResultP031201_ykd = ParseData(window.external.DoOptions(strTableP031201_ykd, 'GetList', '{"djbh":"' + strDjbh + '"}'));
        createGrid_P031201_ykd(strTableP031201_ykd, objP031201_ykd.colNames, objP031201_ykd.colModel);
        $("#" + strTableP031201_ykd).setColProp("a1", { formatter: formatCountPlace });
        myList = objResultP031201_ykd.Records;
        count = myList.length > 5 ? myList.length : 5;
        var sl = 0;
        for (var i = 0; i < count; i++) {
            if (myList[i]) {
                if (myList[i].a1) {                                     //移库数量存在时
                    sl += parseFloat(myList[i].a1);
                }
                $("#" + strTableP031201_ykd).addRowData(i + 1, myList[i]);
            }
            else {
                $("#" + strTableP031201_ykd).addRowData(i + 1, {});
            }
        }
        //调整表格列宽度自适应
        resizeGridScroll(strTableP031201_ykd);

        //给单据日期赋值
        $("#djdate", $("#" + strDivP031201_ykd + "_divform")).val(objResultP031201_ykd.djdate);
        //给移库类型赋值
        $("#yklxdm", $("#" + strDivP031201_ykd + "_divform")).val(objResultP031201_ykd.yklxmc);
        //给经手人赋值
        $("#zydm", $("#" + strDivP031201_ykd + "_divform")).val(objResultP031201_ykd.zymc);
        //给调出仓库赋值
        $("#outckdm", $("#" + strDivP031201_ykd + "_divform")).val(objResultP031201_ykd.outckmc);
        //给调入仓库赋值
        $("#inckkhdm", $("#" + strDivP031201_ykd + "_divform")).val(objResultP031201_ykd.inckkhmc);
        //给制单人赋值
        $("#czydm", $("#" + strDivP031201_ykd + "_divform")).val(objResultP031201_ykd.czymc);
        //给备注赋值
        $("#bz", $("#" + strDivP031201_ykd + "_divform")).val(escape(objResultP031201_ykd.bz));

        //给最后一行加上图片
        $("#" + strTableP031201_ykd).footerData("set", { rn: "合计", a1: sl.toFixed(window.parent.strCountPlace) });
    } catch (e) { }
}

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

/*-------------------------------------------------------------
功能：创建普通表格
*****①strTableID：表格的ID
*****②objColNames:表格需要显示的列名
*****③objColModel：表格的列配置
-----------------------------------------------------------------*/
function createGrid_P031201_ykd(strTableID, objColNames, objColModel) {
    $("#" + strTableID).jqGrid({
        datatype: "local",
        colNames: objColNames,
        colModel: objColModel,
        rownumbers: true,
        rownumWidth: 30,
        footerrow: true,
        autowidth: true
    });
    //设置表格高度
    $("#" + strTableID).setGridHeight(141);
    //给列头加上序号
    $("#" + strTableID).setLabel("rn", "序号");
}