/*************************
*功能：期初维护
*创建人：张振华
*时间：2010-08-16
*备注：
*************************/

var strSelRowIdP0607;   //行ID
var objSelRowP0607; //选中行数据
var strTableNameP0607 = "Tqcwh";
var strDialogP0607 = "divP0607";
var strDialogP060701 = "divP060701";
var strTableNameP060701;  //库存起初录入，应收  应付 起初录入
var strKmdmP0607;   //科目代码
var strSaveSign;  //新增(1), 修改(2), 新增下一级(3), 删除(4)
var strSelRowIdP060701; //弹出页所选的行ID
var strBhP060701; //弹出页所选的行数据
var strRow = -1; //行索引
var strCol = -1; //列索引
var strTitleP0607;
var strStateDate;
var objPageParamP060701 = { sortfield: "", orderby: "", where: "", flag: 0 }; //分页控件使用

//会计科目刷新期初
function refreshInfos(obj) {

    if (obj && obj.page && obj.flag) {
        $("#" + strTableNameP0607).setGridParam({ treeANode: -1 });

        //会计科目刷新期初
        if (obj.page == "p0606" && obj.flag == "1") {
            loadTreeData(strTableNameP0607, ParseData(window.external.DoOptions(strTableNameP0607, 'GetList', '{}')).Records);
        }
        //共同刷新期初
        if (obj.page == "ciho" && obj.flag == "1") {
            loadTreeData(strTableNameP0607, ParseData(window.external.DoOptions(strTableNameP0607, 'GetList', '{}')).Records);
        }
    }
    $("#dvTip").empty();
}

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

//格式化单价
function formatterP0607Price(cellValue) {

    if (!isNaN(parseFloat(cellValue))) {
        return parseFloat(cellValue).toFixed(window.parent.strPricePlace);
    }
    else {
        return "&nbsp;";
    }
}

//格式化金额
function formatterP0607Money(cellValue, row1, row2) {

    if (!isNaN(parseFloat(cellValue))) {
        if ((strTableNameP060701 == "TYsqc" || strTableNameP060701 == "TYfqc") && row1.colModel.index == "a11" && cellValue == "0") {
            return "&nbsp;";
        }
        return parseFloat(cellValue).toFixed(window.parent.strMoneyPlace);
    }
    else {
        return "&nbsp;";
    }
}

// 主页面格式化
function Formatter(cellvalue, options, rowObject) {
    if (isNaN(parseFloat(cellvalue))) {
        cellvalue = "0";
    }
    return parseFloat(cellvalue).toFixed(window.parent.strPricePlace);

}

// 主页面格式化操作
function FormatterCz(cellvalue, options, rowObject) {
    if (rowObject.bh == "1003" || rowObject.bh == "1004"
    || rowObject.bh == "2001" || rowObject.bh == "2004") {
        return "<a href='#' style='text-decoration:none;' onclick='showDialog_P0607(\"1\", \"" + rowObject.bh + "\");return false;' >录入</a>";
    }
    else {
        return "&nbsp;";
    }
}

//弹出页浮动删除
function addCzHtmlP060701() {
    $("#" + strTableNameP060701).delegate("tr[id]:visible", "hover", function (e) {
        if (e.type == "mouseenter") {
            var strButtonHtml = "";
            strButtonHtml = "<a style=\"cursor:pointer;color:red;text-decoration:none;\" onclick=\"UpdatePop('2'," + this.id + ");return false;\">修改</a>";
            strButtonHtml += "<font color='red'>|</font>";
            strButtonHtml += "<a  style=\"cursor:pointer;color:red;text-decoration:none;\" onclick=\"DeletPop(" + this.id + ");return false;\">删除</a> ";
            $("#" + strTableNameP060701).jqGrid("setCell", this.id, "cz", strButtonHtml);
        }
        else if (e.type == "mouseleave") {
            $("#" + strTableNameP060701).jqGrid("setCell", this.id, "cz", "　");
        }
    });
}

//循环修改父节点的值
function GetParent(objCurrR) {
    var objTable = $("#" + strTableNameP0607);

    //一直找父节点直到最上级在推出递归
    var objParent = objTable.getNodeParent(objCurrR);
    if (objParent == null) {
        return;
    }
    var arrChildern = objTable.getNodeChildren(objParent);
    var fParentValue = 0;

    //找到父节点，循环兄弟节点计算合计
    for (var i = 0; i < arrChildern.length; i++) {

        var strValue = parseFloat(arrChildern[i].a16);
        if (isNaN(strValue)) {
            strValue = 0;
        }
        fParentValue += strValue;
    }

    //给父节点赋值
    objTable.setCell(objParent.bh, "a16", fParentValue);

    //清楚内存
    objTable = null;
    return GetParent(objParent);

}

//单元格编辑事件
function afterEditCell(rowid, cellname, value, iRow, iCol) {

    //table对象，行ID
    var objTable = $("#" + strTableNameP0607);
    var arrIds = objTable.getDataIDs();

    for (var i = 0; i < arrIds.length; i++) {
        if (rowid != arrIds[i]) {
            continue;
        }
        var objTr = objTable.getRowData(arrIds[i]);

        //如果是父节点或者不可修改的则直接退出编辑状态
        if (objTr.isLeaf == "false") {
            objTable.restoreCell(iRow, iCol);
            break;
        }
        else if (objTr.flags == "false") {
            objTable.restoreCell(iRow, iCol);
            break;
        }
        else {
            $(":input").autoNumeric({ mDec: window.parent.strPricePlace, aNeg: '-' }).focus(function () { this.select(); }).css("ime-mode", "disabled");

            //添加keypress
            $(":input").keypress(function () {

                //数据修改显示提示信息
                $("#dvTip").text("数据已经修改请退出时保存");
            });

            //记录行所以列索引
            strRow = iRow
            strCol = iCol;
        }
    }

    //释放内存
    objTable = null;
}

//单元格保存事件
function afterSaveCell(rowid, cellname, value, iRow, iCol) {

    //table对象
    var objTable = $("#" + strTableNameP0607);

    //行对象
    var objCurrR = objTable.getRowData(rowid);

    //循环改变父节点的值
    GetParent(objCurrR);

    //资产类-负债类 = 实收资本
    var fFirst = objTable.getRowData("1");
    var fSecond = objTable.getRowData("2");
    if (!isNaN(fFirst.a16 - fSecond.a16)) {
        objTable.setCell("5", "a16", (fFirst.a16 - fSecond.a16));
        objTable.setCell("5001", "a16", (fFirst.a16 - fSecond.a16));
    }

    //释放内存
    objCurrR = null;
    objTable = null;
}

//释放内存
function freeMemory_P060701() {
    strSelRowIdP0607 = null;
    objSelRowP0607 = null;
    strSelRowIdP0607 = null;
    strSelRowIdP060701 = null;
    strSaveSign = null;
}

//应付和应收下拉框的值
function getCombobxData() {

    //下拉框的值
    var objZy = getComboboxData("TZyxx2");
    objZy.unshift({ "mc": "全部销售员", "dm": "", selected: true });
    var objGys = getComboboxData("Tgysxx2");
    objGys.unshift({ "mc": "全部供应商", "dm": "", selected: true });
    var objKh = getComboboxData("Tkhxx2");
    objKh.unshift({ "mc": "全部客户", "dm": "", selected: true });
    var objSp = getComboboxData("Tspxx2");
    objSp.unshift({ "mc": "全部药品", "dm": "", selected: true });

    //记载头部下拉框
    $("#gys", "#" + strDialogP0607).combobox({
        width: _iWidth150,
        listWidth: _iWidth150,
        textField: "mc",
        valueField: "dm",
        onfocus: function () {
            if ($(this).combobox("getText") == "全部供应商") {
                $(this).combobox("setText", "");
            }
        },
        onblur: function () {
            if ($(this).combobox("getText") == "") {
                $(this).combobox("setText", "全部供应商");
            }
        }
    });
    if (objGys != "{}") {
        $("#gys", "#" + strDialogP0607).combobox("loadData", objGys);
    }

    $("#sp", "#" + strDialogP0607).combobox({
        width: _iWidth150,
        listWidth: _iWidth150,
        textField: "mc",
        valueField: "dm",
        onfocus: function () {
            if ($(this).combobox("getText") == "全部药品") {
                $(this).combobox("setText", "");
            }
        },
        onblur: function () {
            if ($(this).combobox("getText") == "") {
                $(this).combobox("setText", "全部药品");
            }
        }
    });
    if (objSp != "{}") {
        $("#sp", "#" + strDialogP0607).combobox("loadData", objSp);
    }

    $("#zy", "#" + strDialogP0607).combobox({
        width: _iWidth150,
        listWidth: _iWidth150,
        textField: "mc",
        valueField: "dm",
        onfocus: function () {
            if ($(this).combobox("getText") == "全部销售员") {
                $(this).combobox("setText", "");
            }
        },
        onblur: function () {
            if ($(this).combobox("getText") == "") {
                $(this).combobox("setText", "全部销售员");
            }
        }
    });
    if (objZy != "{}") {
        $("#zy", "#" + strDialogP0607).combobox("loadData", objZy);
    }

    $("#kh", "#" + strDialogP0607).combobox({
        width: _iWidth150,
        listWidth: _iWidth150,
        textField: "mc",
        valueField: "dm",
        onfocus: function () {
            if ($(this).combobox("getText") == "全部客户") {
                $(this).combobox("setText", "");
            }
        },
        afterChange: function (newValue, newText) {
            $(this).combobox("setText", newText.replace(/&nbsp;/g, ""));
        },
        onblur: function () {
            if ($(this).combobox("getText") == "") {
                $(this).combobox("setText", "全部客户");
            }
        }
    });
    if (objKh != "{}") {
        $("#kh", "#" + strDialogP0607).combobox("loadData", objKh);
    }

}

//应收和应付有查询功能
function searchDataP060701() {

    //如果查询条件是不存在变成全部
    if (strTableNameP060701 == "TYfqc") {
        if ($("#sp", "#" + strDialogP0607).combobox('getValue') == undefined) {
            $("#sp").combobox("setValue", "");
        }
        if ($("#gys", "#" + strDialogP0607).combobox('getValue') == undefined) {
            $("#gys").combobox("setValue", "");
        }
    }
    else if (strTableNameP060701 == "TYsqc") {
        if ($("#kh", "#" + strDialogP0607).combobox('getValue') == undefined) {
            $("#kh").combobox("setValue", "");
        }
        if ($("#sp", "#" + strDialogP0607).combobox('getValue') == undefined) {
            $("#sp").combobox("setValue", "");
        }
        if ($("#zy", "#" + strDialogP0607).combobox('getValue') == undefined) {
            $("#zy").combobox("setValue", "");
        }
    }

    //查询字符串
    var strJson = "";
    var objResult;

    if (strTableNameP060701 == "TYfqc") {
        strJson = "\"gys\":\"" + $("#gys", "#" + strDialogP0607).combobox('getValue') + "\"";
        strJson += ",\"sp\":\"" + $("#sp", "#" + strDialogP0607).combobox('getValue') + "\""
    }
    else if (strTableNameP060701 == "TYsqc") {
        strJson = "\"kh\":\"" + $("#kh", "#" + strDialogP0607).combobox('getValue') + "\"";
        strJson += ",\"sp\":\"" + $("#sp", "#" + strDialogP0607).combobox('getValue') + "\"";
        strJson += ",\"zy\":\"" + $("#zy", "#" + strDialogP0607).combobox('getValue') + "\"";
    }

    //重新查询数据
    objPageParamP060701.where = strJson;
    objResult = loadGridData_Page(objPageParamP060701);

    //重新设置分页标志位
    objPageParamP060701.flag = 0;

    //计算合计
    if (objResult.Records.length == 0) {
        $("#" + strTableNameP060701).footerData('set', { rn: "合计", a10: "&nbsp", a11: "&nbsp;" });
    }
    else {
        $("#" + strTableNameP060701).footerData('set', { rn: "合计", a10: objResult.je, a11: objResult.wkje }, true);
    }


}

//应付账款和应收账款，关闭时重新取所有数据的合计数
function reloadAllData() {
    if (strTableNameP060701 == "TYfqc" || strTableNameP060701 == "TYsqc") {
        var objResult = ParseData(window.external.DoOptions(strTableNameP060701, "DoOthers", "{}"));
        objResult.wkje = "0";

        $("#" + strTableNameP060701).footerData('set', { rn: "合计", a10: objResult.je, a11: objResult.wkje }, true);

    }
}

//弹出对话框
function showDialog_P0607(strType, strBh) {
    try {

        //存储当前节点的编号
        strBhP060701 = strBh;

        //顶级标题，所属
        var strBelong = "";
        var strTableId = "";
        var i = 0;
        var strForm = "";
        var item;

        //科目名称
        var strKmmc = "";

        //选中行对象
        var objTr = $("#" + strTableNameP0607).getRowData(strBhP060701);
        strKmdmP0607 = objTr.kmdm;

        //点期初录入
        if (strBh == "1003") {
            strTableNameP060701 = "TKcqc";
            strTitleP0607 = "库存期初录入";
            strKmmc = "库存商品";
            strBelong = "<a href=\"#\" onclick='AddPop(\"1\",\"库存期初录入\");return false;' >添加</a>"
            creatDiv_ShowDlgHaveTbl(strDialogP0607, strTitleP0607, true, false, strTableNameP0607, "700");
        }
        else if (strBh == "1004") {
            strTableNameP060701 = "TYsqc";
            strTitleP0607 = "应收账款期初录入";
            strKmmc = "应收账款";
            strBelong = "<a href=\"#\"  onclick='AddPop(\"1\",\"应收款期初录入\");return false;'>添加</a>";
            creatDiv_ShowDlgHaveTbl(strDialogP0607, strTitleP0607, true, false, strTableNameP0607, "955");
        }
        else if (strBh == "2001") {
            strTableNameP060701 = "TYfqc";
            strTitleP0607 = "应付账款期初录入";
            strKmmc = "应付账款";
            strBelong = "<a href=\"#\"  onclick='AddPop(\"1\",\"应付款期初录入\");return false;'>添加</a>";
            creatDiv_ShowDlgHaveTbl(strDialogP0607, strTitleP0607, true, false, strTableNameP0607, "955");
        }
        else if (strBh == "2004") {
            strTableNameP060701 = "TGzqc";
            strTitleP0607 = "工资期初录入";
            strKmmc = "工资期初";
            strBelong = "<a href=\"#\"  onclick='AddPop(\"1\",\"工资期初录入\");return false;'>添加</a>";
            creatDiv_ShowDlgHaveTbl(strDialogP0607, strTitleP0607, true, false, strTableNameP0607, "700");
        }

        //获取配置信息
        var arrConfig = ParseData(window.external.DoOptions(strTableNameP060701, "GetTableConfig", "{}"));
        var objData = [];
        if (strTableNameP060701 != "TYsqc" && strTableNameP060701 != "TYfqc") {
            objData = ParseData(window.external.DoOptions(strTableNameP060701, 'GetList', '{}'));
        }

        //设置头部
        $("#" + strDialogP0607 + "_pop_box_top").append("<h3 id='idH3'>科目：" + strKmmc + "</h3>" + strBelong);

        //配置显示头部
        strForm = "<ul>";
        for (i = 0; i < arrConfig.pageHeader.length; i++) {

            Item = arrConfig.pageHeader[i];
            if (Item.hidden == true) {
                continue;
            }
            if (Item.edittype == "text") {
                strForm += "<li class='inp_70'>";
                strForm += Item.xsmc + "：";
                strForm += "<input type='text'  name='" + Item.index + "' ";
                strForm += " value=''  ";
                strForm += " id='" + Item.index + "'>";
                strForm += "</li>";
            }
            else if (Item.edittype == "select") {
                strForm += "<li>";
                strForm += Item.xsmc + "：";
                strForm += "<select name='" + Item.index + "' id='" + Item.index + "'";
                strForm += " class='easyui-combobox' >";
                strForm += "</select>";
                strForm += "</li>";
            }
            else if (Item.edittype == "button") {
                strForm += "<li class='enter_pop'>";
                strForm += "<a id='btnSearch' href='#' title='查询'>查询</a>";
                strForm += "</li>";
            }
        }
        strForm += "</ul>";

        //表格
        strForm += "<table id=\"" + strTableNameP060701 + "\"></table>";

        //往弹出层里添加内容
        $("#" + strDialogP0607 + "_divform").append(strForm);

        //分页
        if (strTableNameP060701 == "TYsqc" || strTableNameP060701 == "TYfqc") {
            $(".filter", "#" + strDialogP0607).after("<div id=\"divPage" + strTableNameP060701 + "\" class=\"Page02\">");
        }

        //不同的模块列属性不同
        for (i = 0; i < arrConfig.colModel.length; i++) {

            switch (arrConfig.colModel[i].name) {
                case "a1":
                    arrConfig.colModel[i].formatter = formatterP0607Money;
                case "a3":
                    if (strTableNameP060701 == "TKcqc") {
                        arrConfig.colModel[i].formatter = formatterP0607Price;
                    }
                    break;
                case "a4":
                    if (strTableNameP060701 == "TKcqc") {
                        arrConfig.colModel[i].formatter = formatterP0607Count;
                    }
                    else {
                        arrConfig.colModel[i].formatter = formatterP0607Price;
                    }
                    break;
                case "a5":
                    if (strTableNameP060701 == "TKcqc") {
                        arrConfig.colModel[i].formatter = formatterP0607Money;
                    }
                    else {
                        arrConfig.colModel[i].formatter = formatterP0607Count;
                    }
                    break;
                case "a7":
                    arrConfig.colModel[i].formatter = "checkbox";
                    arrConfig.colModel[i].editoptions = { value: '1:0' };
                    break;
                case "a8":
                    arrConfig.colModel[i].formatter = formatterP0607Count;
                    break;
                case "a9":
                    arrConfig.colModel[i].formatter = formatterP0607Price;
                    break;
                case "a10":
                    arrConfig.colModel[i].formatter = formatterP0607Money;
                    break;
                case "a11":
                    arrConfig.colModel[i].formatter = formatterP0607Money;
                    break;
                default:

            }
            if (arrConfig.colModel[i].name == "a10" || arrConfig.colModel[i].name == "a11") {
                arrConfig.colModel[i].formatter = formatterP0607Money;
            }

        }

        //创建表格
        if (strTableNameP060701 == "TYsqc" || strTableNameP060701 == "TYfqc") {
            createGrid(strTableNameP060701, arrConfig.colNames, arrConfig.colModel, "{}", null, addCzHtmlP060701, true, funcDbClick);
        }
        else {
            createGrid(strTableNameP060701, arrConfig.colNames, arrConfig.colModel, objData.Records, null, addCzHtmlP060701, true, funcDbClick);
        }


        //应付应收的时候创建分页，和头部搜索条件
        if (strTableNameP060701 == "TYfqc" || strTableNameP060701 == "TYsqc") {

            //设置表格高度
            $("#" + strTableNameP060701).setGridHeight(337);

            //设置表格属性
            $("#" + strTableNameP060701).setGridParam({ onSortCol: sortDataP060701 });

            //创建分页
            createPage("divPage" + strTableNameP060701, strTableNameP060701);

            //设置分页
            $("#txtRowCount_Page").val("12");
            $("#hidOldRowCount_Page").val("12");


            //分页数据
            objPageParamP060701.sortfield = "id";
            objPageParamP060701.orderby = "desc";

            //头部下拉框和搜索条件
            getCombobxData();

            //绑定事件
            if (strTableNameP060701 == "TYfqc" || strTableNameP060701 == "TYsqc") {
                $("#btnSearch", "#" + strDialogP0607).unbind("click");
                $("#btnSearch", "#" + strDialogP0607).bind("click", function () {

                    objPageParamP060701.sortfield = "id";
                    objPageParamP060701.orderby = "desc";
                    objPageParamP060701.flag = 1;

                    searchDataP060701();
                });
            }

            //查询
            searchDataP060701();

            //重新设置分页样式
            $(".Page02", "#" + strDialogP060701).children("ul").children("li").each(function () {
                $(this).addClass("Page02_li");
            });

        }
        else {

            //设置表格高度
            $("#" + strTableNameP060701).setGridHeight(380);

            //设置表格滚动条
            resizeGridScroll(strTableNameP060701);
        }

        //非应付期初，应收期初前台自己计算合计
        if (strTableNameP060701 != "TYsqc" && strTableNameP060701 != "TYfqc") {
            GetTotal();
        }

        //重新定位层
        $('#' + strDialogP0607 + "_content").css("margin-top", "-95px");

        //释放内存
        arrConfig = null;
        objData = null;
        objTr = null;
    }
    catch (e) {
        proceError("P0603", e.ToString());
    }
}

//保存按钮
function SaveQuwh() {

    //tabled对象，行数据
    var objGrid = $("#" + strTableNameP0607);
    var arrIds = objGrid.getDataIDs();

    //数据库操作结果
    var s = null;

    //保存单元格
    objGrid.saveCell(strRow, strCol);

    //循环所有行
    var strRecords = "[";
    for (var i = 0; i < arrIds.length; i++) {
        var objRow = objGrid.getRowData(arrIds[i]);

        strRecords += "{"
        strRecords += "\"kmdm\":\"" + objRow.kmdm + "\",";
        strRecords += "\"a16\":\"" + objRow.a16 + "\"";
        strRecords += "},";
    }
    strRecords = strRecords.substring(0, strRecords.length - 1);
    strRecords += "]";

    //操作数据库
    s = ParseData(window.external.DoOptions(strTableNameP0607, "Edit", strRecords));

    //数据库操作失败弹出提示
    if (s.ReturnCode != "0") {
        window.parent.cihoAlert(s.MSG);
        return;
    }

    $("#dvTip").empty();

    //释放内存
    objGrid = null;
}

//计算合计
function GetTotal() {
    var objTable = $("#" + strTableNameP060701);
    var arrIds = objTable.getDataIDs();
    var strTotal = 0;
    var strTotal_1 = 0;
    var strTotal_2 = 0;

    for (var i = 0; i < arrIds.length; i++) {
        if (!isNaN(parseFloat(objTable.getCell(arrIds[i], "a1")))) {
            strTotal_2 += parseFloat(objTable.getCell(arrIds[i], "a1"));
        }
        if (!isNaN(parseFloat(objTable.getCell(arrIds[i], "a10")))) {
            strTotal += parseFloat(objTable.getCell(arrIds[i], "a10"));
        }
        if (!isNaN(parseFloat(objTable.getCell(arrIds[i], "a11")))) {
            strTotal_1 += parseFloat(objTable.getCell(arrIds[i], "a11"));
        }
    }
    objTable.footerData('set', { rn: "合计", a10: strTotal, a11: strTotal_1, a1: strTotal_2 }, true);
    objTable = null;
}

//保存
function saveMyData(dialog, strType, strTableName) {

    try {
        //保存
        switch (strTableName) {
            case "TKcqc":
                saveKcqc(strType);
                GetTotal();
                break;
            case "TYsqc":
                SaveYsqc(strType);
                break;
            case "TYfqc":
                SaveYfqc(strType);
                break;
            case "TGzqc":
                SaveGzqc(strType);
                GetTotal();
                break;
            case ciho.layal.table:
                ciho.saveType();
                getCombobxData();
                break;
        }

    }
    catch (e) {
        proceError("P0607", e.ToString());
    }
}

//弹出层点修改
function AddPop(strType, strTitle) {
    try {
        //弹出层内容
        creatDiv_ShowDialog(strDialogP060701, strTitle, false, true, strTableNameP060701);

        //保存标志位
        strSaveSign = strType;

        //弹出层里添加内容
        if (strTableNameP060701 == "TKcqc") {
            tableKcForm();
        }
        else if (strTableNameP060701 == "TYsqc") {
            tableYsqcForm();
        }
        else if (strTableNameP060701 == "TYfqc") {
            tableYfqcForm();
        }
        else if (strTableNameP060701 == "TGzqc") {
            tableGzqcForm();
        }
    }
    catch (e) {
        proceError("P0607", e.ToString());
    }

}

//修改弹出层
function UpdatePop(strType, id) {
    try {
        //弹出空曾
        creatDiv_ShowDialog(strDialogP060701, strTitleP0607, false, true, strTableNameP060701);

        //存储保存标志位
        strSaveSign = strType;

        //往层里添加内容
        if (strTableNameP060701 == "TKcqc") {
            tableKcForm(id);
        }
        else if (strTableNameP060701 == "TYsqc") {
            tableYsqcForm(id);
        }
        else if (strTableNameP060701 == "TYfqc") {
            tableYfqcForm(id);
        }
        else if (strTableNameP060701 == "TGzqc") {
            tableGzqcForm(id);
        }

        //记录选中行的ID
        strSelRowIdP060701 = id;
    }
    catch (e) {
        proceError("P0607", e.ToString());
    }

}

//删除弹出层
function DeletPop(id) {
    try {
        if (strTableNameP060701 == "TKcqc") {
            deletekcRow(id);
        }
        else if (strTableNameP060701 == "TYsqc") {
            deleteYsqcRow(id);
        }
        else if (strTableNameP060701 == "TYfqc") {
            deleteYfqcRow(id);
        }
        else {
            deleteGzqcRow(id);
        }
    }
    catch (e) {
        proceError("P0607", e.ToString());
    }
}

//期初录入数据之后关闭改变期初维护画面的值
function ChangeValue() {

    //table对象
    var objTable = $("#" + strTableNameP0607);

    //选中行的父节点的值
    var objParent = objTable.getRowData(strBhP060701);

    //改变当前节点的值
    if (strTableNameP060701 == "TGzqc") {
        $("#" + strTableNameP0607).setCell(strBhP060701, "a16", $("#" + strTableNameP060701).footerData('get').a1);
    }
    else {
        $("#" + strTableNameP0607).setCell(strBhP060701, "a16", $("#" + strTableNameP060701).footerData('get').a10);
    }

    //递归改变父节点的金额值
    GetParent(objParent);

    //应付应收改变应交税金
    var objSj = ParseData(window.external.DoOptions(strTableNameP0607, "DoOthers", "{}"));

    if (objSj.ReturnCode == 0) {
        objTable.setCell("2002", "a16", objSj.Records[0].a16);
        objParent = objTable.getRowData("2002");
        GetParent(objParent);
    }

    // 资产类-负债类 = 实收资本
    var objMoney = objTable.getRowData("1");
    var objZhai = objTable.getRowData("2");
    if (!isNaN((objMoney.a16 - objZhai.a16))) {
        objTable.setCell("5001", "a16", (objMoney.a16 - objZhai.a16));
        objTable.setCell("5", "a16", (objMoney.a16 - objZhai.a16));
    }

    //释放内存
    objTable = null;
    objParent = null;
}

//拼接字符串
function getSaveDataInfo() {

    var strJsonData = "";

    //input标签控件的查找
    $(":input", $("#" + strDialogP060701 + "_divform")).each(function () {
        if ($(this).attr("id") != null && $(this).attr("id") != "") {

            if ($(this).attr("type") == "text") {

                if ($(this).attr("id") == "a8") {
                    //                    if ($("#a7").attr("checked") == true) {
                    strJsonData += "\"a8\":\"" + trim($(this).val()) + "\",";
                    //}

                }
                else if ($(this).attr("id") == "a9") {
                    //                    if ($("#a7").attr("checked") == true) {
                    strJsonData += "\"a9\":\"" + trim($(this).val()) + "\",";
                    //                    }

                }
                else if ($(this).attr("id") == "a11") {
                    //                    if ($("#a7").attr("checked") == true) {
                    strJsonData += "\"a11\":\"" + trim($(this).val()) + "\",";
                    //                    }
                }
                else {
                    strJsonData += "\"" + $(this).attr("id") + "\":\"" + trim($(this).val()) + "\",";
                }
            }
            else if ($(this).attr("type") == "checkbox" || $(this).attr("type") == "radio") {
                strJsonData += "\"" + $(this).attr("id") + "\":\"" + $(this)[0].checked + "\",";
            }
        }
    });
    strJsonData = "{" + strJsonData.substr(0, strJsonData.length - 1) + "}";
    return strJsonData;

}

//关闭层
function closeMyDlg(dvName, strType, strTableName) {

    //数据有变化
    if ($("#" + dvName + "_divform").data("change")) {
        window.parent.cihoAlert(msg.other.haveChange, msgBox.dlgBtn.YesNoCancel, function (result) {
            if (result == msgBox.dlgRst.Yes) {
                saveMyData(dvName, strType, strTableName);
            }
            else if (result == msgBox.dlgRst.No) {
                cihoDlgClose(dvName);
                freeMemory_P060701();
            }
        });
    }
    else {
        //0：关闭编辑窗口
        if (strType == "0") {
            if (dvName != "divAddType") {
                reloadAllData();
                ChangeValue();
            }
            cihoDlgClose(dvName);

            if (dvName != "divAddType") {
                cihoDlgClose(dvName);
            }
        }
    }
}

//双击行
function funcDbClick(strType, rowId) {
    UpdatePop("2", rowId);
}

//排序
function sortDataP060701(index, colindex, sortorder) {

    //设置排序
    objPageParamP060701.sortfield = index;
    objPageParamP060701.orderby = sortorder;

    var objResult = loadGridData_Page(objPageParamP060701);

    //重新设置分页标志位
    objPageParamP060701.flag = 0;

    //计算合计
    if (objResult.Records.length == 0) {
        $("#" + strTableNameP060701).footerData('set', { rn: "合计", a10: "&nbsp", a11: "&nbsp;" });
    }
    else {
        $("#" + strTableNameP060701).footerData('set', { rn: "合计", a10: objResult.je, a11: objResult.wkje }, true);
    }

    return 'stop';
}
