/******************************************************查看付款单**************************************************************
*             功能描述:  提供查看付款的功能
*             创建人:    李孟昌        
*             版  本:    实现查看功能  
*             测试情况:  实现功能 尚未测试
*             修改人：   翟新乐
*             修改时间: 
*             测试日期:
******************************************************************************************************************************/

var strTableNameP0110401_fkd;           //展示的表格id
var strTableNameP010103;                //获取数据的表格id
var strMoneyPlace = window.parent.strMoneyPlace;

//创建弹出窗口
function showDialog_P010103(djbh,strDialogId) {
    strTableNameP0110401_fkd = "Tp011401_fkd";
    strTableNameP010103 = "Tp010103";
    var config = [];
    config = ParseData(window.external.DoOptions(strTableNameP010103, 'GetTableConfig', '{}'));
    for (var i = 0; i < config.colModel.length; i++) {   //修改model
        if (config.colModel[i]["index"] == "cz") {
            config.colModel[i]["hidden"] = true;
        }        
    }
    var s = ParseData(window.external.DoOptions(strTableNameP010103, 'GetList', "{\"djbh\":\"" + djbh + "\"}"));
    creatDiv_ShowDlgHaveTbl(strDialogId, '付款单', true, false, strTableNameP0110401_fkd,600);
    $("#idMust", $("#" + strDialogId)).append("NO:" + djbh);
    var header = createInputsP011401_fkd(config.pageHeader);
    $("#" + strDialogId + "_divform").append(header);
    var myData = s.Records;
    if (myData == "{}") {      //如果数据等于空 那么设置 myData 为空
        myData = [];
    }
    var dataCount = myData.length > 5 ?  myData.length: 5;
    $("#" + strDialogId + "_divform").append("<table id='Tp011401_fkd'></table><br/>");
    addColFormatter_P011401_fkd(config.colModel);  //格式化
    createGridP011401_fkd(strTableNameP0110401_fkd, config.colNames, config.colModel);
    $("#" + strTableNameP0110401_fkd).setGridHeight(141)
    resizeGridScroll(strTableNameP0110401_fkd);
    var sfJinE = 0;
    for (var i = 0; i < dataCount; i++) {
        if (myData[i]) {
            sfJinE += parseFloat(myData[i].a2);
            $("#" + strTableNameP0110401_fkd).addRowData(i + 1, myData[i]);
        }
        else {
            $("#" + strTableNameP0110401_fkd).addRowData(i + 1, { "editable": "True", "gysdm": "", "e1": "", "d1": "", "cz": "", "c1": "", "a3": "", "a2": "", "a1": "", "djdate": "", "zydm": "", "kmdm": "", "djbh": "", "mxguid": "", "fkdate": "" });
        }
    }
    creatDialogItem_P011401_fkd(s);     //填充界面元素 
    LoadStyle();                   //格式化的灰化效果
    $("#" + strTableNameP0110401_fkd).footerData("set", { rn: "合计", a2: sfJinE.toFixed(strMoneyPlace) });
    //$("#" + strDialogId).dialog("option", "position", "center");
    config = {};
    s = {};
    header = null;
    myData = {};
    dataCount = 5;
    sfJinE = 0;
}

//创建jqGrid 创建一个 Grid 此时不提供数据
function createGridP011401_fkd(strTableID, objColNames, objColModel) {
    $("#" + strTableID).jqGrid({
        datatype: "local",
        colNames: objColNames,
        colModel: objColModel,
        data: [],
        rownumbers: true,
        rowNum: 9999,
        sortname: "id",
        rownumWidth: 30,
        autowidth: true,
//        width: 600,
//        height: "100%",
        footerrow: true,
        gridview: true
    }); //.parent(".ui-jqgrid-bdiv").siblings().css("width", "100%");

    //增加表头‘序号’列
    //$("table.ui-jqgrid-htable th:first", $("#gbox_" + strTableID)).text("序号");
    $("#" + strTableID).setLabel("rn", "序号");
}

//填充样式
function LoadStyle() {
    var arrIds = $("#" + strTableNameP0110401_fkd).jqGrid("getDataIDs");
    for (var i = 0; i < arrIds.length; i++) {
        var strEditable = $("#" + strTableNameP0110401_fkd).jqGrid("getCell", arrIds[i], "editable");
        if (strEditable == "False") {
            $("#" + strTableNameP0110401_fkd).setCell(arrIds[i], "fkdate", "", "yanse");
            $("#" + strTableNameP0110401_fkd).setCell(arrIds[i], "d1", "", "yanse");
            $("#" + strTableNameP0110401_fkd).setCell(arrIds[i], "e1", "", "yanse");
            $("#" + strTableNameP0110401_fkd).setCell(arrIds[i], "a1", "", "yanse");
            $("#" + strTableNameP0110401_fkd).setCell(arrIds[i], "a2", "", "yanse");
            $("#" + strTableNameP0110401_fkd).setCell(arrIds[i], "a3", "", "yanse");
        }
    }
    arrIds = null;
}

//给页面元素赋值
function creatDialogItem_P011401_fkd(data) {
    $("#djdateTp011401_fkd").val(data.djdate);
    $("#gysdmTp011401_fkd").val(data.gysmc);
    $("#wfjeTp011401_fkd").val(parseFloat(data.wfje).toFixed(strMoneyPlace));
}

//格式列中数据
function addColFormatter_P011401_fkd(objColModel) {
    for (var intI = 0; intI < objColModel.length; intI++) {
        if (objColModel[intI]["name"] == "a1") {
            objColModel[intI].formatter = function (cellvalue, options, rowObject) {
                if (cellvalue != "") {
                    return parseFloat(cellvalue).toFixed(window.parent.strMoneyPlace);
                }
                else {
                    return "&nbsp;";
                }
            }
        }
        //优惠
        else if (objColModel[intI]["name"] == "a2") {
            objColModel[intI].formatter = function (cellvalue, options, rowObject) {
                if (cellvalue != "") {
                    return parseFloat(cellvalue).toFixed(window.parent.strMoneyPlace);
                }
                else {
                    return "&nbsp;";
                }
            }
        }

    }
}

//从config里面获得表头的数据
function createInputsP011401_fkd(arr) {
    var strForm = "<ul>";
    for (i = 0; i < arr.length; i++) {
        var Item = arr[i];
        if (!Item.hidden) {
            if (Item.edittype == "text") {
                strForm += "<li class='inp_70'>";
                strForm += Item.xsmc + "：";
                strForm += "<input type='text'  name='" + Item.index + strTableNameP0110401_fkd + "' ";
                if (!Item.editable) {
                    strForm += "disabled='disabled' "; ;
                }
                strForm += " value=''  ";
                strForm += " id='" + Item.index + strTableNameP0110401_fkd + "'";
                strForm += " onkeypress='return checkValidate(event)' onpaste='return validatePaste()'/>";
                strForm += "</li>";
            }
        }
    }
    strForm += "</ul>";
    Item = null;
    return strForm;
}