/**
 * js供应商主数据管理
 * supplier/list.ftl
 * supplierController
 */
var submitFlag = 0
let el = {
    tb: '#tb',
    secondLevelPurchase: '#secondLevelPurchase',
    searchForm: '#searchForm',
    state: '#state',
    registerType:'#registerType',
    syncSap: '#syncSap',
    code: '#code',
    purchaseGroup: '#purchaseGroup',
    dataSyncDialog: '#dataSyncDialog',
    syncSupCode: '#syncSupCode',
    startDate: '#startDate',
    endDate: '#endDate',
    bodyHeight: document.documentElement.clientHeight,
    supplierType: '#supplierType',
    supplierGenre: '#supplierGenre',
    purchaseGroupCode:'#purchaseGroupCode',
    freezeFlagMain:'#freezeFlagMain',
    eliminateFlag:'#eliminateFlag'
};

$(function () {
    initDict("supplier_classify")
    initNecessaryData("pc/sys/purchaseGroup/rest/listAll", 'purchaseGroupCode', 'purchaseGroupName')
    loadGrid();
});


/**
 * 加载主数据
 */
function loadGrid() {

    let query = $(el.searchForm).serializeJson();
        query.supplierAttribution = 10;
    let searchHeight = $(el.searchForm).outerHeight();

    $(el.tb).datagrid({
        method: "GET",
        loadMsg: '数据加载中......',
        height: el.bodyHeight - searchHeight,
        url: g.ctx + 'pc/supplier/purchaseCategory/rest/mainDataList',
        singleSelect: false,
        pagination: true,
        autoHeight: true,
        rownumbers: true,
        striped: true,
        page: 1,
        pageSize: 10,
        queryParams: query,
        columns: [[
            {
                field: 'ck',
                checkbox: 'true'
            },
            {
                field: 'state',
                title: '供应商状态',
                width: '100',
                align: 'left',
                exportEnum: [
                    {code: 1, codeWithDesc: '注册'},
                    {code: 2, codeWithDesc: '潜在'},
                    {code: 3, codeWithDesc: '正式'},
                    {code: 4, codeWithDesc: '临时'},
                    {code: 5, codeWithDesc: '退出'},
                    {code: 6, codeWithDesc: '合格'},
                    {code: 7, codeWithDesc: '小批量'},
                    {code: "", codeWithDesc: '初始'}
                ],
                formatter: function (value) {
                    switch (value) {
                        case 1:
                            return '注册';
                        case 2:
                            return '潜在';
                        case 3:
                            return '正式';
                        case 4:
                            return '临时';
                        case 5:
                            return '退出';
                        case 6:
                            return '合格';
                        case 7:
                            return '小批量';
                        default:
                            return '初始';
                    }
                }
            },
            {
                field: 'signatureFlag',
                title: '电子签章',
                width: '60',
                align: 'left',
                exportEnum: [
                    {code: 1, codeWithDesc: '是'},
                    {code: "", codeWithDesc: '否'},
                    {code: 0, codeWithDesc: '否'}
                ],
                formatter: function (value) {
                    if (value === 1) {
                        return '<span style="color: red;">是</span>';
                    } else {
                        return '<span style="color: darkgreen;">否</span>';
                    }
                }
            },
            {
                field: 'monthFlag',
                title: '订单月度回签',
                width: '90',
                align: 'left',
                exportEnum: [
                    {code: 1, codeWithDesc: '是'},
                    {code: 0, codeWithDesc: '否'}
                ],
                formatter: function (value) {
                    if (value === 1) {
                        return '<span style="color: red;">是</span>';
                    } else {
                        return '<span style="color: darkgreen;">否</span>';
                    }
                }
            },
            {
                field: 'supplierFreeze',
                title: '是否冻结',
                width: '60',
                align: 'left',
                exportEnum: [
                    {code: 1, codeWithDesc: '是'},
                    {code: 0, codeWithDesc: '否'}
                ],
                formatter: function (value) {
                    if (value === 1) {
                        return '<span style="color: red;">是</span>';
                    } else {
                        return '<span style="color: darkgreen;">否</span>';
                    }
                }
            }, {
                field: 'eliminateFlag',
                title: '是否待淘汰',
                width: '60',
                align: 'left',
                exportEnum: [
                    {code: 1, codeWithDesc: '是'},
                    {code: 0, codeWithDesc: '否'}
                ],
                formatter: function (value) {
                    if (value === 1) {
                        return '<span style="color: red;">是</span>';
                    } else {
                        return '<span style="color: darkgreen;">否</span>';
                    }
                }
            },
            {
                field: 'supplierCode',
                title: '供应商编号',
                width: '120',
                align: 'left'
            },
            {
                field: 'supplierErpCode',
                title: '供应商ERP编码',
                width: '120',
                align: 'left'
            },
            {
                field: 'supplierName',
                title: '供应商名称',
                width: '200',
                align: 'left'

            },
            {
                field: 'registerType',
                title: '供应商区分',
                width: '160',
                align: 'left',
                exportEnum: [
                    {code: 1, codeWithDesc: '自主注册'},
                    {code: 0, codeWithDesc: '邀请注册'}
                ],
                formatter: function (value) {
                    switch (value) {
                        case 0:
                            return '<span style="color:green">邀请注册</span>';
                        case 1:
                            return '<span style="color:blue">自主注册</span>';
                        default:
                            return '<span style="color:grey">未知</span>';
                    }
                }
            },
            {
                field: 'templateName',
                title: '信息模板',
                width: '200',
                align: 'left'
            },
            {
                field: 'supplierGenre',
                title: '供应商类型',
                width: '150',
                align: 'left',
                exportEnum: getDictList('supplier_classify'),
                formatter: function (value) {
                    return getDicName('supplier_classify', value)
                }
            },
            {
                field: 'recommender', title: '创建人', width: '100',
            },
            {
                field: 'purchaseGroupCode',
                title: '对账采购组名称',
                width: '150',
                sortable: true,
                align: 'left',
                exportEnum: getNecessaryDataList('pc/sys/purchaseGroup/rest/listAll'),
                formatter: function (value) {
                    return getNecessaryDataName('pc/sys/purchaseGroup/rest/listAll', value)
                }
            },
            {
                field: 'signUpRemark',
                title: '审批意见',
                width: '160',
                align: 'left',
            },
            {
                field: 'apprState',
                title: '审批状态',
                width: '60',
                align: 'left',
                exportEnum: [
                    {code: 3, codeWithDesc: '驳回'},
                    {code: 2, codeWithDesc: '同意'},
                    {code: 1, codeWithDesc: '审批中'},
                    {code: 0, codeWithDesc: '新建'}
                ],
                formatter: function (value) {
                    if (value == 3) {
                        return '<span style="color: red">驳回</span>'
                    } else if (value == 2) {
                        return '<span style="color: green">同意</span>'
                    } else if (value == 1) {
                        return '<span style="color: grey">审批中</span>'
                    } else if (value == 0) {
                        return '<span style="color: grey">新建</span>'
                    }
                }
            },
            {
                field: 'oaId',
                title: 'OA流程编号',
                width: '245',
                align: 'left',
                formatter: function (value) {
                    return oaTrack(value, OaProcessType.SUPPLIER_ACCESS);
                }
            }
        ]],
        toolbar: [
            {
                text: '导出信息',
                id: 'btn-export-data',
                iconCls: 'icon-filter',
                handler: function () {
                    openExportDialog('pc/supplier/purchaseCategory/rest/export', 'tb', searchParams())
                    setOperationLog("导出信息按钮", "资源整合供应商主数据");
                }
            },
            '-',
            {
                text: '导出信息(银行)',
                id: 'btn-export-data',
                iconCls: 'icon-filter',
                handler: function () {
                    window.open(g.ctx + 'pc/supplier/purchaseCategory/rest/exportBankdm?q=' + encodeURI(JSON.stringify($(el.searchForm).serializeJson())));
                    setOperationLog("导出信息(银行)按钮", "资源整合供应商主数据");
                }
            },
            '-',
            {
                text: '导出信息(品类)',
                id: 'btn-export-data',
                iconCls: 'icon-filter',
                handler: function () {
                    window.open(g.ctx + 'pc/supplier/purchaseCategory/rest/exportProducttypedm?q=' + encodeURI(JSON.stringify($(el.searchForm).serializeJson())));
                    setOperationLog("导出信息(品类)按钮", "资源整合供应商主数据");
                }
            },
            '-',
            {
                text: '导出信息(联系人)',
                id: 'btn-export-data',
                iconCls: 'icon-filter',
                handler: function () {
                    window.open(g.ctx + 'pc/supplier/purchaseCategory/rest/exportContacts?q=' + encodeURI(JSON.stringify($(el.searchForm).serializeJson())));
                    setOperationLog("导出信息(联系人)按钮", "资源整合供应商主数据");
                }
            },
            '-',     {
                text: '供应主数据报表导出(总表)',
                id: 'btn-export-data',
                iconCls: 'icon-filter',
                handler: function () {
                    window.open(g.ctx + 'pc/supplier/purchaseCategory/rest/exportSupplierReport?q=' + encodeURI(JSON.stringify($(el.searchForm).serializeJson())));
                    setOperationLog("供应主数据报表导出(总表)按钮", "资源整合供应商主数据");
                }
            },
            '-',
            {
                text: '冻结',
                iconCls: 'icon-lock',
                id: 'btn-frozen',
                handler: function () {
                    lockState(1);
                }
            },
            '-',
            {
                text: '解冻',
                id: 'btn-thaw',
                iconCls: 'icon-ok',
                handler: function () {
                    lockState(0);
                }
            },
            '-',
            {
                text: '信息查看',
                id: 'btn-info-look',
                iconCls: 'icon-large-smartart',
                handler: function () {
                    information();
                }
            },
            '-',
            {
                text: '信息查看(品质)',
                id: 'btn-info-look',
                iconCls: 'icon-book',
                handler: function () {
                    information1();
                }
            },
            '-',
            {
                text: '签章设置',
                id: 'btn-signatureFlag',
                iconCls: 'icon-large-smartart',
                handler: function () {
                    let rows = $(el.tb).datagrid('getSelections');
                    if (rows.length < 1) {
                        parent.layer.msg('您未选中任何数据!');
                        return;
                    }
                    if (rows.length > 1) {
                        parent.layer.msg('该操作只能选中一条记录');
                        return;
                    }
                    let id = rows[0].supplierId;
                    let signatureFlag = rows[0].signatureFlag;
                    let title = '启用电子印章'
                    if (signatureFlag === 1) {
                        title = '停用电子印章'
                    }
                    if (submitFlag === 1) {
                        return;
                    }
                    topWin.layer.confirm('确认' + title + '吗?', {icon: 3}, function (index) {
                        var load = topWin.layer.load(1);
                        submitFlag = 1
                        $.ajax({
                            url: g.ctx + 'pc/supplier/rest/updateSignatureFlag',
                            type: 'POST',
                            data: {id: id},
                            complete: function () {
                                topWin.layer.close(load)
                                submitFlag = 0
                            },
                            success: function () {
                                topWin.layer.msg('保存成功', {icon: 1});
                                topWin.layer.close(index);
                                $(el.tb).datagrid("reload")
                            },
                            error: function (data) {
                                topWin.layer.alert(data.responseJSON.message, {icon: 2});
                            }
                        });
                    })
                }
            },
            '-',
            {
                text: '订单月度回签设置',
                id: 'btn-monthFlag',
                iconCls: 'icon-large-smartart',
                handler: function () {
                    let rows = $(el.tb).datagrid('getSelections');
                    if (rows.length < 1) {
                        parent.layer.msg('您未选中任何数据!');
                        return;
                    }
                    if (rows.length > 1) {
                        parent.layer.msg('该操作只能选中一条记录');
                        return;
                    }
                    let id = rows[0].supplierId;
                    let monthFlag = rows[0].monthFlag;
                    let title = '启用订单月度回签'
                    if (monthFlag === 1) {
                        title = '停用订单月度回签'
                    }
                    if (submitFlag === 1) {
                        return;
                    }
                    topWin.layer.confirm('确认' + title + '吗?', {icon: 3}, function (index) {
                        var load = topWin.layer.load(1);
                        submitFlag = 1
                        $.ajax({
                            url: g.ctx + 'pc/supplier/rest/updateMonthFlagFlag',
                            type: 'POST',
                            data: {id: id},
                            complete: function () {
                                topWin.layer.close(load)
                                submitFlag = 0
                            },
                            success: function () {
                                topWin.layer.msg('保存成功', {icon: 1});
                                topWin.layer.close(index);
                                $(el.tb).datagrid("reload")
                            },
                            error: function (data) {
                                topWin.layer.alert(data.responseJSON.message, {icon: 2});
                            }
                        });
                    })
                }
            },
            '-',
            {
                text: '导入',
                id: 'btn-data-in',
                iconCls: 'icon-upload',
                handler: function () {
                    var a = openImportExcelDialog("static/excel/supplier_import_template.xlsx", "供应商信息导入", function (file) {
                        let formData = new FormData();
                        formData.append("file", file);
                        formData.append("supplierAttribution","0");
                        var xhr = new XMLHttpRequest();
                        xhr.responseType = "arraybuffer";
                        xhr.open("POST", g.ctx + 'pc/supplier/rest/import', true);
                        xhr.onload = function () {
                            try {
                                let enc = new TextDecoder('utf-8')
                                let data = JSON.parse(enc.decode(new Uint8Array(this.response)));
                                if (data.statusCode === 'OK') {
                                    topWin.layer.alert("导入成功", {icon: 1, shadeClose: true, title: '温馨提示'});
                                    topWin.layer.alert("导入成功", {icon: 1}, function (idx) {
                                        a.dialog('close');
                                        $(el.tb).datagrid("reload")
                                        topWin.layer.close(idx);
                                    });
                                }
                            } catch (e) {
                                console.log(e)
                                var fileName = xhr.getResponseHeader("Content-disposition").replace('attachment;filename=', '');
                                const blob = new Blob([this.response], {type: "application/vnd.ms-excel"});
                                if (window.navigator.msSaveOrOpenBlob) {
                                    navigator.msSaveOrOpenBlob(blob, decodeURI(fileName))
                                } else {
                                    const aLink = document.createElement('a');
                                    aLink.style.display = 'none';
                                    aLink.href = window.URL.createObjectURL(blob);
                                    aLink.download = decodeURI(fileName);
                                    document.body.appendChild(aLink);
                                    aLink.click();
                                    document.body.removeChild(aLink);
                                    parent.layer.alert('部分导入成功，请在下载的excel中查看错误数据', {
                                        icon: 1,
                                        shadeClose: true,
                                        title: '导入成功'
                                    }, function (idx) {
                                        a.dialog('close');
                                        $(el.tb).datagrid("reload")
                                        topWin.layer.close(idx);
                                    });
                                }
                            }
                        };
                        xhr.send(formData);
                    })
                    setOperationLog("导入按钮", "资源整合供应商主数据");

                }
            },
            '-',
            {
                text: '提交OA审批',
                id: 'btn-convert-import-smallbatch',
                iconCls: 'icon-ok',
                handler: function () {
                    if (submitFlag == 1) {
                        return;
                    }
                    let rows = $(el.tb).datagrid('getSelections');
                    if (rows.length == 0) {
                        topWin.layer.msg('请选择至少一条数据', {icon: 0});
                        return;
                    }
                    //需要判断选中的数据中是否存在审批中，
                    //需要判断oaId是否全部相同，否则无法转小批量
                    //需要判断supplierId是否全部相同，否则无法转小批量
                    let tipMsg = []
                    let oaIdMap = {}
                    let supplierIdMap = {}
                    $.each(rows, function (index, row) {
                        oaIdMap[row.oaId] = 1
                        supplierIdMap[row.supplierId] = 1
                        if (row.apprState === 2 || row.apprState === 1) {
                            tipMsg.push("选中的第" + (index + 1) + "条数据审批状态不正确")
                        }
                    })
                    // 检查 oaIdMap 的键是否重复
                    const oaIdKeys = Object.keys(oaIdMap);
                    const oaIdSet = new Set(oaIdKeys);
                    const oaIdDuplicate = oaIdKeys.length !== oaIdSet.size;

                    if (oaIdDuplicate) {
                        tipMsg.push("不同的OA单据无法一起提交")
                    }
                    // 检查 supplierIdMap 的键是否重复
                    const supplierIdKeys = Object.keys(supplierIdMap);
                    const supplierIdSet = new Set(supplierIdKeys);
                    const supplierIdDuplicate = supplierIdKeys.length !== supplierIdSet.size;

                    if (supplierIdDuplicate) {
                        tipMsg.push("不同的供应商数据无法一起提交")
                    }
                    if (tipMsg.length > 0) {
                        topWin.layer.msg(tipMsg.join("<br/>"), {icon: 0});
                        return;
                    }
                    submitFlag = 1;
                    topWin.layer.load(1);
                    $.ajax({
                        url: g.ctx + 'pc/supplier/purchaseCategory/rest/importSupplierApproval',
                        type: 'POST',
                        data: {
                            ids: rows.map(row => row.id).join(",")
                        },
                        success: function (data) {
                            topWin.layer.closeAll('loading');
                            submitFlag = 0;
                            topWin.layer.alert("操作成功!", {icon: 1})
                            $(el.tb).datagrid("reload")
                        },
                        error: function (data) {
                            submitFlag = 0;
                            topWin.layer.closeAll('loading');
                            topWin.layer.alert(data.responseJSON.message, {icon: 2});
                        }
                    })
                }
            },
            '-',
            {
                id: 'btn-purchase-group-setting', text: '采购组设置', iconCls: 'icon-edit', handler: function () {
                    var rows = $("#tb").datagrid("getChecked")
                    if (rows.length !== 1) {
                        topWin.layer.alert("请选中一条数据修改采购", {icon: 2})
                        return
                    }
                    var purchaseGroupCode = rows[0].purchaseGroupCode
                    let html = [];
                    html.push("<form class='form form-horizontal pl-10 pr-10'>");
                    html.push("<div class='ui-form-row ui-form-row-margin' style='margin-top: 10px !important;margin-bottom: 5px !important;'>");
                    html.push("<table class='ui-form-table topline'>");
                    html.push("    <colgroup>");
                    html.push("        <col style='width:80px'>");
                    html.push("        <col>");
                    html.push("    </colgroup>");
                    html.push("    <tbody>");
                    html.push("        <tr>");
                    html.push("            <td class='ui-form-row-column title required'>");
                    html.push("                <span class='ui-form-item-title'>采购组</span>");
                    html.push("            </td>");
                    html.push("            <td class='ui-form-row-column'>");
                    html.push("                <select id='purchaseGroup' style='width: 100%'></select>");
                    html.push("            </td>");
                    html.push("        </tr>");
                    html.push("    </tbody>");
                    html.push("</table>");
                    html.push("</div>");
                    html.push("</form>");

                    topWin.layer.open({
                        type: 1,
                        area: ['420px', '200px'], // 宽高
                        title: '修改采购组', // 不显示标题栏
                        closeBtn: 0,
                        shadeClose: true, // 点击遮罩关闭层
                        content: html.join(""),
                        btn: ['确定', '关闭'],
                        success: function (layero, index, that) {
                            // 弹层的最外层元素的 jQuery 对象
                            $.ajax({
                                url: g.ctx + 'pc/sys/purchaseGroup/rest/listAll',
                                method: 'get',
                                success: function (data) {
                                    var options = []
                                    $.each(data, function (i, t) {
                                        if (purchaseGroupCode === t.code) {
                                            options.push("<option selected value='" + t.code + "'>" + t.codeWithDesc + "</option>")
                                        } else {
                                            options.push("<option value='" + t.code + "'>" + t.codeWithDesc + "</option>")
                                        }

                                    })
                                    layero.find("#purchaseGroup").html(options.join(""))
                                }
                            })
                        },
                        btn1: function (index, layero, that) {
                            let purchaseGroup = layero.find("#purchaseGroup").val();
                            if (!purchaseGroup) {
                                topWin.layer.msg("请选择采购组");
                                return;
                            }
                            $.ajax({
                                url: g.ctx + 'pc/supplier/rest/updatePurchaseGroup',
                                type: 'post',
                                data: {id: rows[0].supplierId, purchaseGroup: purchaseGroup},
                                success: function () {
                                    topWin.layer.alert("保存成功", {icon: 1}, function (idx) {
                                        topWin.layer.close(idx);
                                        topWin.layer.close(index);
                                        $("#tb").datagrid("reload")
                                    });

                                },
                                error: function (data) {
                                    topWin.layer.alert(data.responseJSON.message, {icon: 2});
                                }
                            })
                        },
                        btn2: function (index, layero, that) {
                            topWin.layer.close(index);
                        },
                    });
                }
            }
        ],
        onLoadSuccess: function () {
           // displayButtonByUserRole('SupplierInfoManage');
            displayButtonByUserRole('SupplierInfoImportManage');
            $(el.tb).datagrid('clearSelections');
            $(el.tb).datagrid('clearChecked');
        }
    });

}

/**
 * 供应商信息查看
 */
function information() {
    let rows = $(el.tb).datagrid('getSelections');
    if (rows.length < 1) {
        parent.layer.msg('您未选中任何数据!');
        return;
    }
    if (rows.length > 1) {
        parent.layer.msg('该操作只能选中一条记录');
        return;
    }
    let id = rows[0].supplierId;
    var url = g.ctx + 'pc/supplier/detail?id=' + id
    var invitationEditDialog = openDialog('invitationEditDialog', url, {
        title: '查看供应商信息',
        width: "90%",
        height: "100%",
        cache: false,
        modal: true,
        border: false,
        draggable: true,
        shadow: false,
        onClose: function () {
            invitationEditDialog.dialog('destroy');
        },
        buttons: [{
            text: itablei8n.close, handler: function () {
                invitationEditDialog.dialog('close');
            }
        }]
    })
}

function information1() {
    let row = $("#tb").datagrid('getSelected');
    if (!row) {
        layer.msg("请选中一条记录");
        return;
    }
    let id = row.supplierId;
    var url = g.ctx + 'pc/supplier/detailPz?id=' + id
    var invitationEditDialog = openDialog('invitationEditDialog', url, {
        title: '查看供应商信息',
        width: "90%",
        height: "100%",
        cache: false,
        modal: true,
        border: false,
        draggable: true,
        shadow: false,
        onClose: function () {
            invitationEditDialog.dialog('destroy');
        },
        buttons: [{
            text: itablei8n.close, handler: function () {
                invitationEditDialog.dialog('close');
            }
        }]
    })
}

/**
 * 冻结、解冻
 * @param state 1.正常 0.冻结
 */
function lockState(state) {
    let rows = $(el.tb).datagrid('getSelections');
    if (rows.length < 1) {
        parent.layer.msg('您未选中任何数据!');
        return;
    }
    if (rows.length > 1) {
        parent.layer.msg('该操作只能选中一条记录');
        return;
    }
    let id = rows[0].supplierId;
    let title = state === 1 ? '冻结' : '解冻'
    //冻结需要选采购组织
    var url = g.ctx + "pc/supplier/purchaseCategory/page/selector?single=0&supplierId=" + id;
    var purchaseCategorySelectDialog = openDialog('purchaseCategorySelectDialog', url, {
        title: title + '供应商',
        width: '80%',
        height: '70%',
        cache: false,
        modal: true,
        border: 'thin',
        onClose: function () {
            purchaseCategorySelectDialog.dialog('destroy');
        },
        buttons: [
            {
                text: '确定',
                iconCls: 'icon-ok',
                handler: function () {
                    topWin.frames['purchaseCategorySelectDialog'].chooseRow(function (data) {
                        const purchaseOrgCodes = data.map(item => item.purchaseOrgCode);
                        topWin.layer.confirm("确定要" + title + "吗?", {icon: 3}, function (index) {
                            $.ajax({
                                url: g.ctx + 'pc/supplier/purchaseCategory/rest/updateFreeze?state=' + state + '&supplierId=' + id,
                                type: 'POST',
                                contentType: "application/json",
                                data: JSON.stringify(purchaseOrgCodes),
                                success: function (data) {
                                    topWin.layer.alert(title + "成功", {icon: 1}, function (idx) {
                                        purchaseCategorySelectDialog.dialog('close');
                                        $(el.tb).datagrid("reload")
                                        topWin.layer.close(index);
                                        topWin.layer.close(idx);
                                    });
                                },
                                error: function (data) {
                                    topWin.layer.alert(data.responseJSON.message, {icon: 2});
                                }
                            })
                        })

                    });
                }
            },
            {
                text: '关闭',
                iconCls: 'icon-cancel',
                handler: function () {
                    purchaseCategorySelectDialog.dialog('close');
                }
            }
        ]
    });


}
//重置信息
function resetSearch() {
    $('#searchForm').form("clear");
    $('input').not('[type="radio"]').val('');
    $('.Wdate').val('');
    $('.select2').val('0');
    //遍历所有select2重置
    $('.select2').each(function () {
        $(this).val(null).trigger("change");
    });
    $('#tb').datagrid('options').queryParams = $('#searchForm').serializeJson();
    $('#tb').datagrid('options').queryParams.supplierAttribution=10;
    $('#tb').datagrid('load');
}

function searchInfo() {
    // 原有的代码逻辑

    // 监听键盘事件

    $('#tb').datagrid('options').queryParams = searchParams();
    $('#tb').datagrid('options').queryParams.supplierAttribution=10;
    $('#tb').datagrid('load');
}