
let el = {
    tb: '#tb',
    id: '#id',
    useState: '#useState',
    isRiskSupplier: '#isRiskSupplier',
}

$(function () {
    initDict('audit_reason,audit_result')
    //queryShow();
    initPageSelect();
    loadGrid();
});

/**
 * 初始化查询条件
 */
function queryShow(){
    // 刷新页面顶部供应商相关统计; isSup -> false:非供应商 true:供应商
    var isSup = $('#isSup').val();
    // 获取需要控制显示与隐藏的元素
    var supplierCodeItem = document.getElementById('supplierCodeItem');
    var supplierNameItem = document.getElementById('supplierNameItem');
    // 根据条件isSup的值来设置显示与隐藏
    if (isSup == "true") {
        supplierCodeItem.style.display = 'none'; // 隐藏供应商编码部分
        supplierNameItem.style.display = 'none'; // 隐藏供应商名称部分
    }else {
        supplierCodeItem.style.display = 'block'; // 显示供应商编码部分
        supplierNameItem.style.display = 'block'; // 显示供应商名称部分
    }
}

/**
 * 初始化页面下拉框数据
 */
function initPageSelect() {
    // 初始化使用状态下拉框
    $(el.useState).combobox({
        valueField: 'value',
        textField: 'label',
        value: -1,
        data: [
            {label: '全部', value: -1},
            {label: '使用', value: 0},
            {label: '未使用', value: 1}
        ],
        editable: false,
        prompt: '-- 请选择 --',
        panelHeight: 'auto'
    });
}

function loadGrid() {
    $('#tb').datagrid({
        url: g.ctx + "pc/spe/qmAuditManage/rest/list",
        iconCls: 'icon-list',
        title: '',
        height: gridheight,
        width: gridwidth,
        singleSelect: true,
        pagination: true,
        idField: 'id',
        autoHeight: true,
        loadMsg: "数据加载中......",
        rownumbers: true,
        fitColumns: false,
        remoteSort: true,
        queryParams: {
            // auditId:$(el.id).val(),
        },
        columns: [[
            {
                field: 'ck',
                checkbox: true
            },
            {
                field: 'status',
                title: '状态',
                width: '80px',
                align: 'left',
                exportEnum:[
                    {code:0,codeWithDesc:'待供应商回复'},
                    {code:1,codeWithDesc:'通过'},
                    {code:2,codeWithDesc:'驳回'},
                    {code:3,codeWithDesc:'新建'},
                    {code:4,codeWithDesc:'待审批'}
                ],
                formatter: function (value) {
                    switch (value) {
                        case 2:
                            return '<span style="color: red;">驳回</span>';
                        case 1:
                            return '<span style="color: green;">通过</span>';
                        case 0:
                            return '<span style="color: blue;">待供应商回复</span>';
                        case 3:
                            return '<span style="color: grey;">新建</span>';
                        case 4:
                            return '<span style="color: orange;">待审批</span>';
                        default:
                            return '';
                    }
                }

            },
            {
                field: 'supplierCode',
                title: '供应商编码',
                width: '80px',
                align: 'left'

            },

            // {
            //     field: 'status',
            //     title: '数据状态',
            //     width: '100',
            //     align: 'left',
            //     formatter: function (value, row, index) {
            //         if (value == 0) {
            //             return '<span style="color:blue">待供应回复</span>';
            //         } else if (value == 1) {
            //             return '<span style="color:green">通过</span>';
            //         } else if (value == 2) {
            //             return '<span style="color:red">驳回</span>';
            //         }
            //     }
            //
            // },
            {
                field: 'supplierName',
                title: '供应商名称',
                width: '175px',
                align: 'left'

            },
            {
                field: 'purchaseCategoryName',
                title: '物料类别',
                width: '110px',
                align: 'left'
            },
            {
                field: 'auditReason',
                title: '稽核原因',
                width: '120px',
                align: 'left',
                exportEnum:getDictList('audit_reason'),
                formatter: function (value) {
                    return getDicName('audit_reason',value);
                }
            },
            {
                field: 'planAuditTime',
                title: '计划稽核时间',
                width: '100px',
                align: 'left',
                formatter: function (value, row, index) {
                    return DateFormatMs(value);
                }
            },
            {
                field: 'actualAuditTime',
                title: '实际稽核时间',
                width: '120px',
                align: 'left',
                formatter: function (value, row, index) {
                    return DateFormatMs(value);
                }
            },
            {
                field: 'auditMasterName',
                title: '稽核组长',
                width: '65px',
                align: 'left'
            },
            {
                field: 'policyPurchaseName',
                title: '策略采购',
                width: '65px',
                align: 'left'
            },
            {
                field: 'purchaseMasterName',
                title: '采购主管',
                width: '65px',
                align: 'left'
            },
            {
                field: 'auditResult',
                title: '稽核结果',
                width: '120px',
                align: 'left',
                exportEnum:getDictList('audit_result'),
                formatter: function (value) {
                    return getDicName('audit_result',value);
                }
            },
            {
                field: 'isRiskSupplier',
                title: '是否风险供应商',
                width: '100px',
                align: 'left',
                exportEnum:[
                    {code:"0",codeWithDesc:'是'},
                    {code:"1",codeWithDesc:'否'}
                ],
                formatter: function (value) {
                    switch (value) {
                        case "0":
                            return '<span style="color: red;">是</span>';
                        case "1":
                            return '<span>否</span>';
                        default:
                            return '';
                    }
                }
            },
            {
                field: 'nextAuditTime',
                title: '下次稽核时间',
                width: '120px',
                align: 'left',
                formatter: function (value, row, index) {
                    return DateFormatMs(value);
                }
            },
            {
                field: 'supplierAdvantage',
                title: '供应商优势',
                width: '15%',
                align: 'left',
                formatter: function(value, row, index) {
                    return '<a href="#" style="color: black" title="' + value + '" class="note">' + value + '</a>';
                }
            },
            {
                field: 'supplierDisadvantage',
                title: '供应商劣势',
                width: '15%',
                align: 'left',
                formatter: function(value, row, index) {
                    return '<a href="#" style="color: black" title="' + value + '" class="note">' + value + '</a>';
                }
            },
            {
                field: 'auditAttachment',
                title: '稽核报告',
                width: '120px',
                align: 'left',
                exportHidden:true,
                // formatter: function (value, row ,rec) {
                //     var sty = "";
                //     if (!row.auditAttachment) {
                //         sty = "color: #0C0C0C";
                //     }
                //     return '<a href="javascript:" style="' + sty + '" onclick="uploadFilesDialog(' + rec + ')">上传/下载</a>';
                //     // return '<a href="javascript:" style="' + sty + '" onclick="uploadFilesDialog(\'' + row.auditAttachment + '\')">上传/下载</a>';
                // }
                formatter: function (value, row ,rec) {
                    //var row = $("#tb").datagrid("getChecked");

                    var sty = "";
                    if (!row.auditAttachment) {
                        sty = "color: #0C0C0C";
                    }
                    var fileIds = row.auditAttachment
                    var id = row.id
                    var status = row.status
                    return '<a href="#" style="' + sty + '" onclick="onNCRAttachLookUpDialog1(\'' + id + '\',\'' + fileIds + '\',' + status + ')">上传/下载</a>';
                }
            },

            {
                field: 'ncrAttachment',
                title: 'NCR回复上传',
                width: '120px',
                align: 'left',
                exportHidden:true,
                // formatter: function (value, row ,rec) {
                //     var sty = "";
                //     if (!row.ncrAttachment) {
                //         sty = "color: #0C0C0C";
                //     }
                //     return '<a href="#" style="' + sty + '" onclick="uploadFilesDialog1(\'' + row.ncrAttachment + '\')">上传/下载</a>';
                // }
                formatter: function (value, row ,rec) {
                    //var row = $("#tb").datagrid("getChecked");

                        var sty = "";
                        if (!row.ncrAttachment) {
                            sty = "color: #0C0C0C";
                        }
                    var fileIds = row.ncrAttachment
                    var id = row.id
                    var status = row.status
                    return '<a href="#" style="' + sty + '" onclick="onNCRAttachLookUpDialog(\'' + id + '\',\'' + fileIds + '\',' + status + ')">上传/下载</a>';
                }
                // handler: function () {
                //     var row = $("#tb").datagrid("getChecked");
                //     if (row.length == 0 || row.length != 1) {
                //         topWin.layer.msg("请选择一条数据");
                //         return;
                //     }
                //
                //     var fileIds = row[0].ncrAttachment
                //     var id = row[0].id
                //     onSiteAuthenticationFilesLookupDialog(id, fileIds);
                // }
            },
            {
                field: 'ncrExamine',
                title: 'NCR结案审批',
                width: '120px',
                align: 'left',
                exportEnum:[
                    {code:"0",codeWithDesc:'Onging'},
                    {code:"1",codeWithDesc:'Closed'}
                ],
                formatter: function (value) {
                    switch (value) {
                        case "1":
                            return '<span>Closed</span>';
                        case "0":
                            return '<span>Onging</span>';
                        default:
                            return '';
                    }
                }
            },
            {
                field: 'note',
                title: '备注',
                width: '120px',
                align: 'left',
                formatter: function(value, row, index) {
                    return '<a href="#" style="color: black" title="' + value + '" class="note">' + value + '</a>';
                }
            },
            {
                field: 'updateUserName',
                title: '创建人',
                width: '120px',
                align: 'left'
            },
            {
                field: 'updateTime',
                title: '创建日期',
                width: '120px',
                align: 'left',
                formatter: function (value, row, index) {
                    return DateFormatMs(value);
                }

            }
        ]],
        toolbar: ["-", {
            text: '新增',
            id: 'add',
            iconCls: 'icon-add',
            hidden: true,
            handler: function () {
                addOrEdit(0);
            }
        }, "-", {
            text: '编辑',
            id: 'edit',
            iconCls: 'icon-edit',
            handler: function () {
                addOrEdit(1);
            }
        }, "-", {
            text: '删除',
            id: 'delete',
            iconCls: 'icon-remove',
            handler: function () {
                delFactory();
            }
        }, "-", {
            text: '查看',
            id: 'look',
            iconCls: 'icon-edit',
            handler: function () {
                look(1);
            }
        }, "-", {
                id: 'ncrReply',
                text: 'NCR回复',
                iconCls: 'icon-reload',
                handler: function () {
                    NCRREPLY();
                   // uploadFilesDialog1(\'' + value + '\')
                   // uploadFilesDialog1(value)
                    //look(1);
                }
        },"-", {
            id: 'examine',
            text: 'NCR结案审批',
            iconCls: 'icon-ok',
            handler: function () {
                examine(1);
            }
        },
            "-", {
                id: 'import',
                text: '导入',
                iconCls: 'icon-import',
                handler: function () {
                    importDicItem();
                }
            },
            "-",{
            id: 'export',
            text: '导出',
            iconCls: 'icon-undo',
            handler: function () {
                // openExportDialog('pc/spe/qmAuditManage/rest/export','tb',{auditId:$(el.id).val()});
                // topWin.location.href = g.ctx + 'pc/spe/qmAuditManage/rest/export?' + searchQueryParams()
                var params = searchParams();
                openExportDialog('pc/spe/qmAuditManage/rest/export','tb',params);
            }
        }],
        onLoadSuccess: function () {
            displayButtonByUserRole("qmAuditManage");
            $(el.tb).datagrid('clearSelections');
        },
        onCheck:function (rowIndex, field, value) {
            var rows = $('#tb').datagrid('getRows');
            var flag = rows[rowIndex].status;
            if(flag==0){   //数据状态 0:待供应回复 1:通过 2:驳回 3:新建 4:待审批
                $('div.datagrid-toolbar a').eq(0).linkbutton('enable');
                $('div.datagrid-toolbar a').eq(1).linkbutton('disable');
                $('div.datagrid-toolbar a').eq(2).linkbutton('disable');
                $('div.datagrid-toolbar a').eq(3).linkbutton('enable');
                $('div.datagrid-toolbar a').eq(4).linkbutton('disable');
                $('div.datagrid-toolbar a').eq(5).linkbutton('disable');
                $('div.datagrid-toolbar a').eq(6).linkbutton('enable');
                $('div.datagrid-toolbar a').eq(7).linkbutton('enable');
            }else if(flag==1){ //数据状态 0:待供应回复 1:通过 2:驳回 3:新建 4:待审批
                $('div.datagrid-toolbar a').eq(0).linkbutton('enable');
                $('div.datagrid-toolbar a').eq(1).linkbutton('disable');
                $('div.datagrid-toolbar a').eq(2).linkbutton('disable');
                $('div.datagrid-toolbar a').eq(3).linkbutton('enable');
                $('div.datagrid-toolbar a').eq(4).linkbutton('disable');
                $('div.datagrid-toolbar a').eq(5).linkbutton('disable');
                $('div.datagrid-toolbar a').eq(6).linkbutton('enable');
                $('div.datagrid-toolbar a').eq(7).linkbutton('enable');
            }else if(flag==2){   //数据状态 0:待供应回复 1:通过 2:驳回 3:新建 4:待审批
                $('div.datagrid-toolbar a').eq(0).linkbutton('enable');
                $('div.datagrid-toolbar a').eq(1).linkbutton('enable');
                $('div.datagrid-toolbar a').eq(2).linkbutton('disable');
                $('div.datagrid-toolbar a').eq(3).linkbutton('enable');
                $('div.datagrid-toolbar a').eq(4).linkbutton('enable');
                $('div.datagrid-toolbar a').eq(5).linkbutton('disable');
                $('div.datagrid-toolbar a').eq(6).linkbutton('enable');
                $('div.datagrid-toolbar a').eq(7).linkbutton('enable');
            }else if(flag==3){   //数据状态 0:待供应回复 1:通过 2:驳回 3:新建 4:待审批
                $('div.datagrid-toolbar a').eq(0).linkbutton('enable');
                $('div.datagrid-toolbar a').eq(1).linkbutton('enable');
                $('div.datagrid-toolbar a').eq(2).linkbutton('enable');
                $('div.datagrid-toolbar a').eq(3).linkbutton('enable');
                $('div.datagrid-toolbar a').eq(4).linkbutton('enable');
                $('div.datagrid-toolbar a').eq(5).linkbutton('disable');
                $('div.datagrid-toolbar a').eq(6).linkbutton('enable');
                $('div.datagrid-toolbar a').eq(7).linkbutton('enable');
            }else if(flag==4){   //数据状态 0:待供应回复 1:通过 2:驳回 3:新建 4:待审批
                $('div.datagrid-toolbar a').eq(0).linkbutton('enable');
                $('div.datagrid-toolbar a').eq(1).linkbutton('disable');
                $('div.datagrid-toolbar a').eq(2).linkbutton('disable');
                $('div.datagrid-toolbar a').eq(3).linkbutton('enable');
                $('div.datagrid-toolbar a').eq(4).linkbutton('disable');
                $('div.datagrid-toolbar a').eq(5).linkbutton('enable');
                $('div.datagrid-toolbar a').eq(6).linkbutton('enable');
                $('div.datagrid-toolbar a').eq(7).linkbutton('enable');
            }
        },
        onClickCell: function (rowIndex, field, value) {
        }
    });
}

 function onNCRAttachLookUpDialog (id,fileIds,status) {
    if(status === 1){
        const uploadOptions = {
        title: 'NCR附件上传',
        lookFlag: true,
        width: '40%',
        height:'60%',
        fileIds: fileIds
        }
        if (id != undefined) {
            uploadOptions.callBack = function (fileIds) {
                $.ajax({
                    url: g.ctx + 'pc/spe/qmAuditManage/rest/saveOnFile',
                    method: "POST",
                    data: {fileIds: fileIds.join(','), id: id},
                    success: function (data) {
                        topWin.layer.alert("保存成功", {icon: 1}, function (idx) {
                            $("#tb").datagrid("reload")
                            topWin.layer.close(idx);
                        });
                    },

                    error: function (data) {
                        topWin.layer.alert(data.responseJSON.message, {icon: 2});
                    }
                });
            }
        }
        openFileUploadDialog("NCR附件上传", uploadOptions)
    }else{
        const uploadOptions = {
            title: 'NCR附件上传',
            lookFlag: false,
            width: '40%',
            height:'60%',
            fileIds: fileIds
        }
        if (id != undefined) {
            uploadOptions.callBack = function (fileIds) {
                $.ajax({
                    url: g.ctx + 'pc/spe/qmAuditManage/rest/saveOnFile',
                    method: "POST",
                    data: {fileIds: fileIds.join(','), id: id},
                    success: function (data) {
                        topWin.layer.alert("保存成功", {icon: 1}, function (idx) {
                            $("#tb").datagrid("reload")
                            topWin.layer.close(idx);
                        });
                    },

                    error: function (data) {
                        topWin.layer.alert(data.responseJSON.message, {icon: 2});
                    }
                });
            }
        }
        openFileUploadDialog("NCR附件上传", uploadOptions)
     }


}

function onNCRAttachLookUpDialog1 (id, fileIds,status) {
    if(status === 1) {
        const uploadOptions = {
            title: '稽核附件上传',
            lookFlag: true,
            width: '40%',
            height:'60%',
            fileIds: fileIds
        }
        if (id != undefined) {
            uploadOptions.callBack = function (fileIds) {
                $.ajax({
                    url: g.ctx + 'pc/spe/qmAuditManage/rest/saveOnFile1',
                    method: "POST",
                    data: {fileIds: fileIds.join(','), id: id},
                    success: function (data) {
                        topWin.layer.alert("保存成功", {icon: 1}, function (idx) {
                            $("#tb").datagrid("reload")
                            topWin.layer.close(idx);
                        });
                    },
                    error: function (data) {
                        topWin.layer.alert(data.responseJSON.message, {icon: 2});
                    }
                });
            }
        }
        openFileUploadDialog("稽核附件上传", uploadOptions)
    }else{
        const uploadOptions = {
            title: '稽核附件上传',
            lookFlag: false,
            width: '40%',
            height:'60%',
            fileIds: fileIds
        }
        if (id != undefined) {
            uploadOptions.callBack = function (fileIds) {
                $.ajax({
                    url: g.ctx + 'pc/spe/qmAuditManage/rest/saveOnFile1',
                    method: "POST",
                    data: {fileIds: fileIds.join(','), id: id},
                    success: function (data) {
                        topWin.layer.alert("保存成功", {icon: 1}, function (idx) {
                            $("#tb").datagrid("reload")
                            topWin.layer.close(idx);
                        });
                    },
                    error: function (data) {
                        topWin.layer.alert(data.responseJSON.message, {icon: 2});
                    }
                });
            }
        }
        openFileUploadDialog("稽核附件上传", uploadOptions)
    }

}
function NCRREPLY(){
    //var id= '';
        var cbox = $('#tb').datagrid('getSelected');
        if (cbox === null || cbox === undefined) {
            layer.msg("请选中一条记录");
            return;
        }
    //uploadFilesDialog1(cbox.ncrAttachment);
    onNCRAttachLookUpDialog(cbox.id,cbox.ncrAttachment,cbox.status);

}
/**
 * 附件上传
 **/
function uploadFilesDialog(val){
    console.log(JSON.stringify(val))
    console.log(999999999999988)
    var rows = $('#tb').datagrid('getRows');
    var row = rows[val];
    openFileUploadDialog('uploadFilesDialog',{
        title:'附件上传',
        fileIds : row.auditAttachment,
        lookFlag: false,
        height: '75%',
        callBack : function (fileIds) {
            console.log(fileIds)
            returnAddRequirefileUpload(fileIds.join(','))
        },
    });
}
// 选择附件回调
function returnAddRequirefileUpload(ids) {
    console.log(787878787878787878)
    console.log(ids)
    var rows = $('#tb').datagrid('getSelected');
    var inx = $('#tb').datagrid('getRowIndex', rows);
    $('#tb').datagrid('endEdit', inx);
    $('#tb').datagrid('updateRow', {
        index: inx,
        row: {
            auditAttachment: ids
        }
    });
    $('#tb').datagrid('beginEdit',inx);

    $.ajax({
        type: "POST",
        url: "/updateAuditAttachment",
        contentType: "application/json",
        data: JSON.stringify(ids),
        success: function(response) {
            console.log("Attachment updated successfully");
        },
        error: function(xhr, status, error) {
            console.error("Error updating attachment");
        }
    });
    // $.ajax({
    //     url: g.ctx + 'pc/spe/qmAuditManage/rest/saveOrUpdate',
    //     type: 'POST',
    //     data: { auditAttachment: ids },
    //     success: function(response) {
    //         // 处理成功响应
    //         console.log('Data saved to the database successfully.');
    //     },
    //     error: function(xhr, status, error) {
    //         // 处理错误
    //         console.error('Error saving data to the database.');
    //     }
    // });
}

function uploadFilesDialog1(val){

    openFileUploadDialog('uploadFilesDialog1',{
        title:'附件上传',
        fileIds : val,
        lookFlag: false,
        height: '75%',
        callBack : function (fileIds) {
            returnAddRequirefileUpload1(fileIds.join(','))
        },
    });
}
function returnAddRequirefileUpload1(ids) {

    var rows = $('#tb').datagrid('getSelected');
    var inx = $('#tb').datagrid('getRowIndex', rows);
    $('#tb').datagrid('endEdit', inx);
    $('#tb').datagrid('updateRow', {
        index: inx,
        row: {
            ncrAttachment: ids
        }
    })}
/**
 *新增编辑
 */
function addOrEdit(flag) {
    var id= '';
    if(flag===1){
        var cbox = $('#tb').datagrid('getSelected');
        if (cbox === null || cbox === undefined) {
            layer.msg("请选中一条记录");
            return;
        }
        id = cbox.id;
    }

    var moldFormDialog = openDialog('moldForm', g.ctx + 'pc/spe/qmAuditManage/detail?id=' + id + '&flag=' + flag , {
        title: flag===0?'新增':'编辑',
        width: '80%',
        height: '80%',
        cache: false,
        modal: true,
        border: false,
        draggable: false,
        shadow: false,
        onClose: function () {
            moldFormDialog.dialog('destroy');
        },
        buttons: [
            {
                text: itablei8n.submit,
                iconCls: 'icon-save',
                handler: function () {
                    topWin.frames['moldForm'].submit(function () {
                        topWin.layer.msg('数据提交成功', {icon: 1});
                        moldFormDialog.dialog('close');
                        $(el.tb).datagrid('reload');
                    });
                }
            },
            {
                text: itablei8n.save,
                iconCls: 'icon-save',
                handler: function () {
                    topWin.frames['moldForm'].saveOrUpdate(function () {
                        topWin.layer.msg('数据保存成功', {icon: 1});
                        moldFormDialog.dialog('close');
                        $(el.tb).datagrid('reload');
                    });
                }
            },
            {
                text: itablei8n.close,
                iconCls: 'icon-cancel',
                handler: function () {
                    moldFormDialog.dialog('close');
                }
            }
        ]
    });
}

/**
 *查看
 */
function look(flag) {
    var id= '';
    if(flag===1){
        var cbox = $('#tb').datagrid('getSelected');
        if (cbox === null || cbox === undefined) {
            layer.msg("请选中一条记录");
            return;
        }
        id = cbox.id;
    }

    var moldFormDialog = openDialog('moldForm', g.ctx + 'pc/spe/qmAuditManage/look?id=' + id, {
        title: '查看',
        width: '80%',
        height: '80%',
        cache: false,
        modal: true,
        border: false,
        draggable: false,
        shadow: false,
        onClose: function () {
            moldFormDialog.dialog('destroy');
        },
        buttons: [
            {
                text: itablei8n.close,
                iconCls: 'icon-cancel',
                handler: function () {
                    moldFormDialog.dialog('close');
                }
            }
        ]
    });
}
/**
 *查看
 */
function examine(flag) {
    var id= '';
    if(flag===1){
        var cbox = $('#tb').datagrid('getSelected');
        if (cbox === null || cbox === undefined) {
            layer.msg("请选中一条记录");
            return;
        }
        id = cbox.id;
    }

    var moldFormDialog = openDialog('moldForm', g.ctx + 'pc/spe/qmAuditManage/examine?id=' + id, {
        title: '结案审批',
        width: '1100px',
        height: '680px',
        cache: false,
        modal: true,
        border: false,
        draggable: false,
        shadow: false,
        onClose: function () {
            moldFormDialog.dialog('destroy');
        },
        buttons: [
            {
                text: "通过",
                iconCls: 'icon-save',
                handler: function () {
                    topWin.frames['moldForm'].saveOrUpdate1(function () {
                        topWin.layer.msg('数据保存成功', {icon: 1});
                        moldFormDialog.dialog('close');
                        $(el.tb).datagrid('reload');
                    });
                }
            },
            {
                text: "拒绝",
                iconCls: 'icon-save',
                handler: function () {
                    var refuseFlag = 0;
                    topWin.frames['moldForm'].saveOrUpdate2(function () {
                        topWin.layer.msg('审批拒绝', {icon: 1});
                        moldFormDialog.dialog('close');
                        $(el.tb).datagrid('reload');
                    });
                }
            },
            {
                text: itablei8n.close,
                iconCls: 'icon-cancel',
                handler: function () {
                    moldFormDialog.dialog('close');
                }
            }
        ]
    });
}
//删除
function delFactory() {
    var cbox = $('#tb').datagrid('getSelected');
    if (cbox === null || cbox === undefined) {
        layer.msg("请选中一条记录");
        return;
    }

    var qmAuditManage = cbox.id;

    parent.layer.confirm('是否删除？', function (index) {
        var loading = top.layer.msg('处理中', {icon: 16, shade: [0.1, '#000'], time: false});
        var url = g.ctx + 'pc/spe/qmAuditManage/rest/remove';
        $.ajax({
            url: url,
            method: "post",
            data: {id: qmAuditManage},
            success: function (data) {
                parent.layer.close(index);
                $(el.tb).datagrid('reload');
            },
            complete: function(data) {
                top.layer.close(loading);
            },
            error: function (data) {
                layer.close(index);
                layer.alert(JSON.parse(data.responseText).message);
            }
        });
    });
}

/**
 * 导入
 */
function importDicItem() {
    var a = openImportExcelDialog("static/excel/audit_manage_list.xlsx", '稽核整改导入', function (file) {
        let formData = new FormData();
        formData.append("file", file);
        //formData.append("dictTypeId", $('#id').val())
        //取到fileId然后进行数据导入操作
        $.ajax({
            url: g.ctx + 'pc/spe/qmAuditManage/rest/import',
            method: "POST",
            contentType: false,
            processData: false,
            data: formData,
            success: function (data) {
                topWin.layer.alert("导入成功", {icon: 1}, function (idx) {
                    topWin.layer.close(idx);
                    a.dialog('close');
                    $('#tb').datagrid('reload');
                });
            },
            error: function (data) {
                topWin.layer.alert(data.responseJSON.message, {icon: 2});
            }
        });
    });
}