
$(function () {

    initDict('currency,po_type,contract_pay_boot_item,signature_type,contractCategory,contract_item_subject_sap,contract_item_subject,invoice_type,sign_order,sign_type,payment_way,payment_stage,contractContentLink');
    // let isSap = $("#isSap").val();
    // if(isSap == 1){
    //     d = getDictList('contract_item_subject_sap')
    // }else{
    //     d = getDictList('contract_item_subject')
    // }
    initColumns();

    loadGrid();

});


function  initColumns(d) {

    $("#contractCover").combobox({
        valueField: 'code',
        textField: 'name',
        panelHeight: 'auto',
        editable: false,
        data: getDictList('contractContentLink')
    })


    //货币编码
    $("#contractCurrency").combobox({
        valueField: 'code',
        textField: 'name',
        panelHeight: 'auto',
        editable: false,
        data: getDictList('currency')
    })


    //发票类型
    $("#contractInvoiceCode").combobox({
        valueField: 'code',
        textField: 'name',
        panelHeight: 'auto',
        editable: false,
        data: getDictList('invoice_type')
    })


    //订单类型
    $("#contractOrderType").combobox({
        valueField: 'code',
        textField: 'name',
        panelHeight: 'auto',
        editable: false,
        data: getDictList('po_type')
    })


    //采购组织
    $("#contractPurchaseGroupCode").combobox({
        valueField: 'purchaseOrgCode',
        textField: 'codeWithDesc',
        limitToList: 'true',
        method: 'POST',
        prompt: '--- 请选择 ---',
        url: g.ctx + 'pc/sys/purchaseOrg/rest/listAll',
    });


    //采购组
    $("#contractPurchaseGroup").combobox({
        valueField: 'purchaseGroupCode',
        textField: 'codeWithDesc',
        limitToList: 'true',
        method: 'POST',
        prompt: '--- 请选择 ---',
        url: g.ctx + 'pc/sys/purchaseGroup/rest/listAll',
    });

    //付款方式
    $("#contractPaymentWay").combobox({
        valueField: 'code',
        textField: 'name',
        panelHeight: 'auto',
        editable: false,
        data: getDictList('payment_way')
    });



   $("#contractAmount").textbox({
        onChange:function (newValue, oldValue) {
            $('#contractAmountCapital').textbox('setValue',number_chinese(newValue));
        }
    })


    $('#contractCompanyName').textbox({
        buttonText:'选择',
        iconCls:'icon-man',
        iconAlign:'left',
        onClickButton:function () {
            layer.open({
                title: "我方公司选择",
                type: 2,
                area: ['600px', '550px'],
                content: '/pc/contract/manage/page/choseSupplier?type=1',
                btn: ['选择','关闭'],
                yes: function (index, layero) {
                    var body = layer.getChildFrame('body', index);
                    var iframeWin = window[layero.find('iframe')[0]['name']];
                    var name = $(layero).find("iframe")[0].contentWindow.document.getElementById("name").value;
                    var code = $(layero).find("iframe")[0].contentWindow.document.getElementById("code").value;
                    if(name!=undefined&&code!=''){
                        $('#contractCompanyName').textbox('setValue',name);
                        $('#contractCompanyCode').val(code);
                        layer.close(index);
                    }else{
                        layer.alert("未选择",{icon:2})
                    }
                },
            });
        }
    });


    $('#contractSupplierName').textbox({
        buttonText:'选择',
        iconCls:'icon-man',
        iconAlign:'left',
        onClickButton:function () {
            layer.open({
                title: "供应商选择",
                type: 2,
                area: ['650px', '550px'],
                content: '/pc/contract/manage/page/choseSupplier?type=2',
                btn: ['选择','关闭'],
                yes: function (index, layero) {
                    var body = layer.getChildFrame('body', index);
                    var iframeWin = window[layero.find('iframe')[0]['name']];
                    var name = $(layero).find("iframe")[0].contentWindow.document.getElementById("name").value;
                    var code = $(layero).find("iframe")[0].contentWindow.document.getElementById("code").value;
                    if(name!=undefined&&code!=''){
                        $('#contractSupplierName').textbox('setValue',name);
                        $('#contractSupplierCode').val(code);
                        layer.close(index);
                    }else{
                        layer.alert("未选择",{icon:2})
                    }
                },
            });
        }
    });

    $('#contractSealType').combobox({
        valueField: 'code',
        textField: 'name',
        panelHeight: 'auto',
        editable: false,
        data: getDictList('sign_type')
    });


    $('#contractSignOrder').combobox({
        valueField: 'code',
        textField: 'name',
        panelHeight: 'auto',
        editable: false,
        data: getDictList('sign_order')
    });


    $('#isMro').combobox({
        valueField: 'code',
        textField: 'name',
        panelHeight: 'auto',
        editable: false,
        data: [
            {"code":1,"name":"是"},
            {"code":2,"name":"否"}
        ], onLoadSuccess: function () {
            var id = $("#id").val();
            if (id == '') {
                $("#isMro").combobox('select',1);
                $("#mroDisplay").text('MRO数据展示');
            }
        },
        onSelect:function (d){
            let mro_flag = 0
            if(d.code == 1){
                mro_flag = 1
                $("#tbdsetMro").hide();
                $("#tbdsetOrder").show();
                $("#mroDisplay").text('MRO数据展示');
                loadGrid();
                //$("#table_tb").datagrid('reload');
            }else{
                $("#tbdsetMro").show();
                $("#tbdsetOrder").hide();
                $("#mroDisplay").text('数据展示');
                loadGrid();
               // $("#table_mro").datagrid('reload');

                //$("#table_mro").datagrid('reload');

            }

            $.ajax({
                url: '/pc/contract/manage/rest/getContractCategory',
                type: 'POST',
                async: false,
                data: {"mroFlag":mro_flag},
                success: function (res) {
                    $("#contractType").combobox({
                        valueField: 'code',
                        textField: 'name',
                        editable: false,
                        panelHeight: 'auto',
                        data: res
                    })
                },
                error: function (res) {
                    topWin.layer.alert(res.responseJSON.message, {icon: 2});
                }
            })
        }
    });


    $('#isSap').combobox({
        valueField: 'code',
        textField: 'name',
        panelHeight: 'auto',
        editable: false,
        data: [
            {"code":"1","name":"是"},
            {"code":"2","name":"否"}
        ]
    });


    $('#associationContract').textbox({
        buttonText:'选择',
        iconAlign:'left',
        onClickButton:function () {
            layer.open({
                title: "合同选择",
                type: 2,
                area: ['650px', '550px'],
                content: '/pc/contract/manage/page/choseContract',
                btn: ['选择','关闭'],
                yes: function (index, layero) {
                    var body = layer.getChildFrame('body', index);
                    var iframeWin = window[layero.find('iframe')[0]['name']];
                    var name = $(layero).find("iframe")[0].contentWindow.document.getElementById("name").value;
                    var code = $(layero).find("iframe")[0].contentWindow.document.getElementById("code").value;
                    if(name!=undefined&&code!=''){
                        $('#associationContract').textbox('setValue',code);
                        layer.close(index);
                    }else{
                        layer.alert("未选择",{icon:2})
                    }
                },
            });
        }
    });





}


function loadGrid(){

    let check = $("#check").val();

    var toolbar = [];
    if(check==1){
        toolbar = [
            {
                text: '新增',
                id: 'btn_add',
                iconCls: 'icon-add',
                handler: function () {
                    addPay();
                }
            },
            {
                text: '编辑',
                id: 'btn_edit',
                iconCls: 'icon-edit',
                handler: function () {
                    editPay();
                }
            },
            {
                text: '删除',
                id: 'btn_order',
                iconCls: 'icon-filter',
                handler: function (d) {
                    delPay();
                }
            },
        ];
    }


    //加载列表数据
    $("#table_pay").datagrid({
        iconCls: 'icon-list',
        url: '/pc/contract/manage/rest/selectPayListPage?conId='+$("#id").val(),
        height: 350,
        fitColumns:true,
        singleSelect: true,
        pagination: true,
        loadMsg: "数据加载中......",
        rownumbers: true,
        nowrap: true,
        striped: true,
        page: 1,
        pageSize: 10,
        // toolbar: toolbar,
        columns: [[
            {field: 'paymentStage', title: '付款阶段',width:'120',
                exportEnum:getDictList('payment_stage'),
                formatter: function (value) {
                    return getDicName('payment_stage',value);
                }},
            {field: 'paymentTime', title: '付款日期',width:'120',
                formatter: function (value) {
                    if (!value) {
                        return;
                    }
                    return moment(new Date(value)).format('YYYY-MM-DD');
                }},
            {field: 'paymentRatio', title: '付款比例',width:'120'},
            {field: 'paymentAmount', title: '付款金额',width:'120'},
            // {field: 'paymentAlreadyAmount', title: '未付款金额',width:'120'},
            {field: 'remark', title: '付款描述',width:'220'},
        ]] ,
    });


    var columns = [
        {field: 'subjectCode', title: '科目',width:'120',
            formatter: function (value, row) {
                if(Number($("#isSap").textbox('getValue')) === 1){
                    return getDicName('contract_item_subject_sap',value)
                }else{
                    return getDicName('contract_item_subject',value)
                }

            }},
        // {field: 'materialCode', title: '物料编码',width:'120'},
        {field: 'materialName', title: '物料名称',width:'120'},
        {field: 'materialSpec', title: '详细规格参数',width:'120'},
        {field: 'warrantyPeriod', title: '质保期(月)',width:'120'},
        {field: 'materialBrand', title: '品牌',width:'120',hidden:true},

        {field: 'materialGroupCode', title: '物料组编码',width:'120',hidden:true},
        {field: 'materialGroupName', title: '物料组',width:'120'},
        {field: 'materialCategory', title: '品类',width:'120'},
        {field: 'materialModel', title: '型号',width:'120',hidden:true},

        {field: 'basisUnit', title: '单位',width:'120 '},
        {field: 'price', title: '单价',width:'120 ' },
        {field: 'num', title: '数量',width:'120'},
        {field: 'amount', title: '总金额',width:'120',formatter: function (value, row) {
                if (row.price !=null && row.num) {
                    return (parseFloat(row.price) * parseFloat(row.num)).toFixed(4);
                }
            }},
        {field: 'taxRateCode', title: '税码',width:'120',hidden:true},
        {field: 'currencyCode', title: '币别',width:'120',hidden:true},
        {field: 'teamName', title: '请购部门',width:'220'},
        {field: 'requireName', title: '请购人',width:'120'},
        {field: 'purchaseCode', title: '采购申请单编码',width:'120',hidden:true},
        {field: 'itemCode', title: '采购申请行号',width:'120',hidden:true},
        {field: 'factoryCode', title: '工厂编码',width:'120',hidden:true},
        {field: 'factoryName', title: '工厂名称',width:'120'},
        {field: 'customerName', title: '服务客户名称',width:'180'},
        {field: 'driverAsset', title: '驱动因素',width:'120',
            formatter: function (value, row) {
                return getDicName('contract_pay_boot_item',value)

            }},
        {field: 'taxRateName', title: '税率',width:'120'},
        {field: 'cardNumber', title: '固定资产卡号',width:'120'},
        {field: 'bz', title: '备注',width:'200'},
        {field: 'purchaseCode', title: '采购申请单编码',width:'220'}
    ] ;


    var columnsMro = [
        {field: 'name', title: '文件名称',width:'120'},
        {field: 'num', title: '份数',width:'120'},
        {field: 'signTime', title: '签约日期',width:'120'},
        {field: 'ourPeople', title: '我方负责人',width:'120'},
        {field: 'otherPeople', title: '对方负责人',width:'120 '},
        {field: 'amount', title: '合同金额',width:'120 ' },
        {field: 'fileName', title: '附件',width:'120',
            formatter: function (value, row) {
                if (row.fileName) {
                    return '<a style="color: #108ee9" onclick="replyDownload(\'' + row.fileId + '\')">'+row.fileName+'</a>';
                } else {
                    return '--'
                }
            }
        },
    ] ;

    $("#table_tb").datagrid({
        iconCls: 'icon-list',
        url: '/pc/contract/manage/rest/selectContractDetailListPage?conId='+$("#id").val(),
        height: 350,
        fitColumns:true,
        singleSelect: true,
        pagination: true,
        loadMsg: "数据加载中......",
        rownumbers: true,
        nowrap: true,
        striped: true,
        page: 1,
        pageSize: 10,
        // toolbar: [
        //     {
        //         text: '新增',
        //         id: 'btn_add',
        //         iconCls: 'icon-add',
        //         handler: function () {
        //             addDetail();
        //         }
        //     },
        //     {
        //         text: '编辑',
        //         id: 'btn_edit',
        //         iconCls: 'icon-edit',
        //         handler: function () {
        //             editDetail();
        //         }
        //     },
        //     {
        //         text: '删除',
        //         id: 'btn_del',
        //         iconCls: 'icon-remove',
        //         handler: function (d) {
        //             delDetail();
        //         }
        //     },
        // ],
        columns: [columns] ,

    });


    $("#table_mro").datagrid({
        iconCls: 'icon-list',
        url: '/pc/contract/manage/rest/selectContractMroListPage?conId='+$("#id").val(),
        height: 350,
        fitColumns:true,
        singleSelect: true,
        pagination: true,
        loadMsg: "数据加载中......",
        rownumbers: true,
        nowrap: true,
        striped: true,
        page: 1,
        pageSize: 10,
        // toolbar: [
        //     {
        //         text: '新增',
        //         id: 'btn_add',
        //         iconCls: 'icon-add',
        //         handler: function () {
        //             addDetailMro();
        //         }
        //     },
        //     {
        //         text: '删除',
        //         id: 'btn_del',
        //         iconCls: 'icon-remove',
        //         handler: function (d) {
        //             delDetailMro();
        //         }
        //     },
        // ],
        columns: [columnsMro] ,

    });

}

function submitContractForm(type,call){
    let b ;
    let rows = $('#table_pay').datagrid('getRows');
    let rowsTableTb = $('#table_tb').datagrid('getRows');
    let totalAmoutnt = 0;

    if(rowsTableTb && rowsTableTb.length>0) {
        for (var i = 0; i < rowsTableTb.length; i++) {
            totalAmoutnt = totalAmoutnt + parseFloat(rowsTableTb[i].price * rowsTableTb[i].num);
        }
        $("#contractAmount").textbox('setValue', totalAmoutnt.toFixed(4));
        $('#contractAmountCapital').textbox('setValue', number_chinese(totalAmoutnt.toFixed(4)));
    }

    let formData = $("#form").serializeJson();
    let mroRows = $('#table_mro').datagrid('getRows');
    let dlist = JSON.stringify(rows);
    let rowsTableTblist = JSON.stringify(rowsTableTb);
    let rlist = JSON.stringify(mroRows);
    formData.contractState = type ;
    var attachData1 = $("#contractFiles").attr('data-fileIds')
    formData.contractFiles = attachData1;
    var attachData2 = $("#contractSignFiels").attr('data-fileIds')
    formData.contractSignFiels = attachData2
    formData.dlist = dlist;
    formData.mros = rlist;
    formData.rowsTableTblist = rowsTableTblist;
    formData.contractAmount = Number($("#contractAmount").textbox('getValue').replace(/,/g,''));
    if ($("#form").form('validate')) {
        $.ajax({
            url: '/pc/contract/manage/rest/form/save',
            type: 'POST',
            async: false,
            data: formData,
            success: function (res) {
                topWin.layer.alert("保存成功!", {icon: 1}, function (idx) {
                    topWin.layer.close(idx);
                    call()
                });
            },
            error: function (res) {
                topWin.layer.alert(res.responseJSON.message, {icon: 2});
            }
        });
    }
    return b ;
}


function addPay(){

    var addPayDialog = openDialog('addPay', g.ctx+'pc/contract/manage/page/formPay?conId='+$("#id").val()+"&payId=", {
        title: '编辑',
        width: '550px',
        height:'70%',
        cache: false,
        modal: true,
        border: 'thin',
        onClose: function () {
            addPayDialog.dialog('destroy');
        },
        buttons: [
            {
                text:'保存',
                iconCls:'icon-save',
                handler:function() {
                    topWin.frames['addPay'].savePayDetail(function (data) {

                        var d = $("#table_pay").datagrid('getRows');
                        let je = 0;
                        let bl = 0;
                        d.forEach(function (v,n) {
                            bl += parseFloat(v.paymentRatio);
                        });
                        if((parseFloat(bl.toFixed(2))+parseFloat(data.paymentRatio))>1){
                            topWin.layer.alert("付款比例超出",{icon:2});
                            return ;
                        }else{
                            let contractAmount = $("#contractAmount").textbox('getValue');
                            data.paymentAmount = ((parseFloat(data.paymentRatio) * parseFloat(contractAmount))).toFixed(4)  ;
                            $("#table_pay").datagrid('appendRow',data);
                            d = $("#table_pay").datagrid('getRows');
                            d.forEach(function (v,n) {
                                je = (parseFloat(je) + parseFloat(v.paymentAmount) );
                                v.paymentAlreadyAmount = je.toFixed(4)  ;
                                $("#table_pay").datagrid('updateRow',{index:n,row:d[n]})
                                $('#table_pay').datagrid('refreshRow',n);
                            });

                            addPayDialog.dialog('close');
                            $('#tb').datagrid('reload');
                        }
                    });
                }
            },
            {
                text:'关闭',
                iconCls:'icon-cancel',
                handler:function() {
                    addPayDialog.dialog('close');
                }
            }
        ]
    });

}


function editPay(){

    let row = $("#table_pay").datagrid('getSelected');
    if (!row) {
        layer.msg("请选中一条记录");
        return;
    }
    let indexRow = $("#table_pay").datagrid('getRowIndex',row);
    var editPayDialog = openDialog('editPay', '/pc/contract/manage/page/formPay?conId='+$("#id").val()+"&rowId="+row.id+"&paymentStage="+row.paymentStage+"&paymentTime="+row.paymentTime+"&paymentRatio="+row.paymentRatio, {
        title: '编辑',
        width: '550px',
        height:'70%',
        cache: false,
        modal: true,
        border: 'thin',
        onClose: function () {
            editPayDialog.dialog('destroy');
        },
        buttons: [
            {
                text:'保存',
                iconCls:'icon-save',
                handler:function() {
                    topWin.frames['editPay'].savePayDetail(function (data) {

                        var d = $("#table_pay").datagrid('getRows');
                        let je = 0;
                        let bl = 0;
                        d.forEach(function (v,n) {
                            if(n!=indexRow){
                                bl += parseFloat(v.paymentRatio);
                            }
                        });
                        console.log(row,bl);
                        if((parseFloat(bl.toFixed(2))+parseFloat(data.paymentRatio))>1){
                            //还原
                            topWin.layer.alert("付款比例超出",{icon:2});
                            return ;
                        }else{
                            let contractAmount = $("#contractAmount").textbox('getValue');
                            data.paymentAmount = ((parseFloat(data.paymentRatio) * parseFloat(contractAmount))).toFixed(4)  ;
                            //更新行数据
                            $("#table_pay").datagrid('updateRow',{index:indexRow,row:data })
                            d = $("#table_pay").datagrid('getRows');
                            d.forEach(function (v,n) {
                                je = (parseFloat(je) + parseFloat(v.paymentAmount) );
                                v.paymentAlreadyAmount = je.toFixed(4)  ;
                                $("#table_pay").datagrid('updateRow',{index:n,row:d[n]})
                                $('#table_pay').datagrid('refreshRow',n);
                            });

                            editPayDialog.dialog('close');
                            $('#tb').datagrid('reload');
                        }
                    });
                }
            },
            {
                text:'关闭',
                iconCls:'icon-cancel',
                handler:function() {
                    editPayDialog.dialog('close');
                }
            }
        ]
    });

}


function addDetail(){
    let isSap = $("#isSap").textbox('getValue');
    var addDetailsDialog = openDialog('addDetails',
        g.ctx+'pc/contract/manage/page/formDetail?detailId=&isSap='+isSap, {
        title: '新增',
        width: '70%',
        height:'80%',
        cache: false,
        modal: true,
        border: 'thin',
        onClose: function () {
            addDetailsDialog.dialog('destroy');
        },
        buttons: [
            {
                text:'保存',
                iconCls:'icon-save',
                handler:function() {
                    topWin.frames['addDetails'].saveContractDetail(function (data) {
                        $("#table_tb").datagrid('appendRow',data);
                        addDetailsDialog.dialog('close');
                        $('#tb').datagrid('reload');
                    });
                }
            },
            {
                text:'关闭',
                iconCls:'icon-cancel',
                handler:function() {
                    addDetailsDialog.dialog('close');
                }
            }
        ]
    });
}

function addDetailMro(){
    var addDetailsMroDialog = openDialog('addDetailsMro',
    g.ctx+'pc/contract/manage/page/formDetailMro?detailId=', {
        title: '新增',
        width: '70%',
        height:'60%',
        cache: false,
        modal: true,
        border: 'thin',
        onClose: function () {
            addDetailsMroDialog.dialog('destroy');
        },
        buttons: [
            {
                text:'保存',
                iconCls:'icon-save',
                handler:function() {
                    topWin.frames['addDetailsMro'].appendDetailMro(function (data) {
                        $("#table_mro").datagrid('appendRow',data);
                        addDetailsMroDialog.dialog('close');
                        $('#tb').datagrid('reload');
                    });
                }
            },
            {
                text:'关闭',
                iconCls:'icon-cancel',
                handler:function() {
                    addDetailsMroDialog.dialog('close');
                }
            }
        ]
    });
}


function editDetail(){
    let row = $("#table_tb").datagrid('getSelected');
    if (!row) {
        layer.msg("请选中一条记录");
        return;
    }
    let indexRow = $("#table_tb").datagrid('getRowIndex',row);
    let isSap = $("#isSap").textbox('getValue');
    decodeURI(row)
    var editDetailsDialog = openDialog('editDetails',
        g.ctx+'pc/contract/manage/page/formDetail?detailId='+row.id+'&isSap='+isSap+'&subjectCode='+row.subjectCode+'&materialCode='+row.materialCode+'&materialName='+row.materialName+'&materialGroupCode='+row.materialGroupCode+'&materialGroupName='+row.materialGroupName+'&materialCategory='+row.materialCategory+'&materialSpec='+row.materialSpec+'&materialModel='+row.materialModel+'&materialBrand='+row.materialBrand+'&basisUnit='+row.basisUnit+'&price='+row.price+'&num='+row.num+'&taxRateName='+row.taxRateName+'&taxRateCode='+row.taxRateCode+'&cardNumber='+row.cardNumber+'&bz='+row.bz+'&currencyCode='+row.currencyCode+'&purchaseCode='+row.purchaseCode+'&factoryCode='+row.factoryCode+'&factoryName='+row.factoryName+'&itemCode='+row.itemCode+'&customerCode='+row.customerCode+'&driverAsset='+row.driverAsset, {
        title: '编辑',
        width: '70%',
        height:'80%',
        cache: false,
        modal: true,
        border: 'thin',
        onClose: function () {
            editDetailsDialog.dialog('destroy');
        },
        buttons: [
            {
                text:'保存',
                iconCls:'icon-save',
                handler:function() {
                    topWin.frames['editDetails'].saveContractDetail(function (data) {
                        $("#table_tb").datagrid('updateRow',{ index:indexRow ,row:data});
                        editDetailsDialog.dialog('close');
                        $('#tb').datagrid('reload');
                    });
                }
            },
            {
                text:'关闭',
                iconCls:'icon-cancel',
                handler:function() {
                    editDetailsDialog.dialog('close');
                }
            }
        ]
    });
}

function delPay() {

    let row = $("#table_pay").datagrid('getSelected');
    if (!row) {
        layer.msg("请选中一条记录");
        return;
    }
    topWin.layer.confirm("是否删除", function (index) {
        var rowIndex = $("#table_pay").datagrid('getRowIndex', row);
        $("#table_pay").datagrid('deleteRow', rowIndex);
        var ds = $("#table_pay").datagrid('getRows');
        let je = 0;
        ds.forEach(function (v,n) {
            je = (je + v.paymentAmount );
            v.paymentAlreadyAmount = je.toFixed(4) ;
            $("#table_pay").datagrid('updateRow',{index:n,row:ds[n]})
            $('#table_pay').datagrid('refreshRow',n);
        });
        topWin.layer.close(index);
    })
}

function delDetail() {
    let row = $("#table_tb").datagrid('getSelected');
    if (!row) {
        layer.msg("请选中一条记录");
        return;
    }
    topWin.layer.confirm("是否删除", function (index) {
        var rowIndex = $("#table_tb").datagrid('getRowIndex', row);
        $("#table_tb").datagrid('deleteRow', rowIndex);
        topWin.layer.close(index);
    })
}

function delDetailMro(){
    let row = $("#table_mro").datagrid('getSelected');
    if (!row) {
        layer.msg("请选中一条记录");
        return;
    }
    topWin.layer.confirm("是否删除", function (index) {
        var rowIndex = $("#table_mro").datagrid('getRowIndex', row);
        $("#table_mro").datagrid('deleteRow', rowIndex);
        topWin.layer.close(index);
    })
}