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

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

        //把弹出窗口框架及底部按钮添加到父窗口创建dialog中
        creatDiv_ShowDlgHaveTbl(strDivP021103_thd, "销售退货单", false, false, strTableP021103_thd);

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

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

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

//创建表单
function tableFormP021103_thd(strDivP021103_thd, strDjbh) {
    var strHeadP021103_thd = "";        //存放页头内容
    var strTablep021103_thd = "";       //存放表格内容
    var strDownP021103_thd = "";       //存放页尾内容
    var objP021103_thd = {};               //存放表格的列配置
    var strPageHeader = [];                  //存放页头的配置
    var strpageFooter = [];                   //存放页尾的配置

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

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

    strHeadP021103_thd = "<ul>";
    for (var i = 0; i < strPageHeader.length; i++) {        //创建页头
        if (strPageHeader[i]["name"] == "gysmc" || strPageHeader[i]["name"] == "zymc" || strPageHeader[i]["name"] == "ckmc" || strPageHeader[i]["name"] == "khmc") {
            continue;
        }
        else if (strPageHeader[i]["name"] == "khdm" || strPageHeader[i]["name"] == "ckdm") {
            strHeadP021103_thd += "<li class='inp_150'>";
            strHeadP021103_thd += strPageHeader[i]["xsmc"] + "：";
            strHeadP021103_thd += "<input type='text'  value=''  name='" + strPageHeader[i]["name"] + "' disabled";
            strHeadP021103_thd += " id='" + strPageHeader[i]["name"] + "' maxlength='50'/>"; //限制输入长度
            strHeadP021103_thd += "</li>";
        }
        else {
            strHeadP021103_thd += "<li class='inp_70'>";
            strHeadP021103_thd += strPageHeader[i]["xsmc"] + "：";
            strHeadP021103_thd += "<input type='text'  value=''  name='" + strPageHeader[i]["name"] + "' disabled";
            strHeadP021103_thd += " id='" + strPageHeader[i]["name"] + "' maxlength='50'/>"; //限制输入长度
            strHeadP021103_thd += "</li>";
        }
    }
    strHeadP021103_thd += "</ul>";
    $("#" + strDivP021103_thd + "_divform").append(strHeadP021103_thd);
    strTablep021103_thd = "<table id='Tp020102'></table>";                   //创建表格
    $("#" + strDivP021103_thd + "_divform").append(strTablep021103_thd);

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

        }
    }
    strDownP021103_thd += "</ul>";
    $("#" + strDivP021103_thd + "_divform").append(strDownP021103_thd);
    //释放内存
    strHeadP021103_thd = null;
    strTablep021103_thd = null;
    strDownP021103_thd = null;
    objP021103_thd = null;
    strPageHeader = null;
    strpageFooter = null;
}

//从后台加载所查单据数据
function myListP021103_thd(strDivP021103_thd, strDjbh) {
    try {
        var objP021103_thd = {};                //存放表格的列配置
        var objResultP021103_thd = {};      //存放返回的信息
        var myList = [];                                //存放返回的数据
        var count = 1;                                  //默认表格显示5行数据

        //获得jqGrid的列名和属性
        objP021103_thd = ParseData(window.external.DoOptions(strTableP021103_thd, 'GetTableConfig', '{}'));
        objResultP021103_thd = ParseData(window.external.DoOptions(strTableP021103_thd, 'GetList', '{"djbh":"' + strDjbh + '"}'));
        for (var i = 0; i < objP021103_thd.colModel.length; i++) {      //隐藏操作列
            if (objP021103_thd.colModel[i].index == "cz") {
                objP021103_thd.colModel[i].hidden = true;
            }
        }

        //创建表格
        createGrid_P021103_thd(strTableP021103_thd, objP021103_thd.colNames, objP021103_thd.colModel);

        //给付款金额绑定值
        if (objResultP021103_thd.fkje != "") {
            $("#fkje", "#" + strDivP021103_thd + "_divform").val(parseFloat(objResultP021103_thd.fkje).toFixed(window.parent.strMoneyPlace));
        }
        $("#" + strTableP021103_thd).setColProp("a1", { formatter: formatCountPlace });
        $("#" + strTableP021103_thd).setColProp("a2", { formatter: formatMoneyPlace });
        $("#" + strTableP021103_thd).setColProp("thje", { formatter: formatMoneyPlace });
        $("#" + strTableP021103_thd).setColProp("a4", { formatter: formatCountPlace });
        $("#" + strTableP021103_thd).setColProp("a5", { formatter: formatMoneyPlace });
        $("#" + strTableP021103_thd).setColProp("tpje", { formatter: formatMoneyPlace });

        myList = objResultP021103_thd.Records;              //把后台返回的数据赋给变量【myList】
        count = myList.length > 1 ? myList.length : 1;        //最少显示【5】行数据

        //添加行并为行分配id，并计算合计
        for (var i = 0; i < count; i++) {
            if (myList[i]) {
                if (myList[i].a3) {
                    if (myList[i].a3 == "True") {       //true时值赋为【是】
                        myList[i].a3 = "是";
                    }
                    else if (myList[i].a3 == "False") {     //false时值赋为【否】
                        myList[i].a3 = "否";
                    }
                }

                $("#" + strTableP021103_thd).addRowData(i + 1, myList[i]);      //给表格加载数据
            }
        }

        resizeGridScroll(strTableP021103_thd);      //调整表格自适应的宽度

        //给返货日期绑定值
        $("#djdate", $("#" + strDivP021103_thd + "_divform")).val(objResultP021103_thd.djdate);
        //给客户绑定值
        $("#khdm", $("#" + strDivP021103_thd + "_divform")).val(objResultP021103_thd.khmc);
        //给经销人绑定值
        $("#zydm", $("#" + strDivP021103_thd + "_divform")).val(objResultP021103_thd.zymc);
        //给销售类型绑定值
        $("#ckdm", $("#" + strDivP021103_thd + "_divform")).val(objResultP021103_thd.ckmc);
        //给付款账户绑定值
        $("#kmdm", "#" + strDivP021103_thd + "_divform").val(objResultP021103_thd.kmmc);
        //给付款日期绑定值
        $("#fkdate", $("#" + strDivP021103_thd + "_divform")).val(objResultP021103_thd.fkdate);
        //给制单人绑定值
        $("#czydm", $("#" + strDivP021103_thd + "_divform")).val(objResultP021103_thd.czymc);
        //给备注绑定值
        $("#bz", $("#" + strDivP021103_thd + "_divform")).val(escape(objResultP021103_thd.bz));

        //释放一下内存
        objP021103_thd = null;
        objResultP021103_thd = null;
        myList = null;
    } catch (e) { }
}

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

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

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