wtt
2025-01-18 7ad7452e09483c7faa1e6b09658e46e1a12170bb
tableselect输入框输入搜索添加防抖
2个文件已修改
37 ■■■■ 已修改文件
WebTM/layuiadmin/modules/tableSelect.js 35 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
WebTM/views/采购管理/采购订单/Cg_POOrderBillEdit.html 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
WebTM/layuiadmin/modules/tableSelect.js
@@ -10,7 +10,7 @@
        table = layui.table,
        form = layui.form;
    var tableSelect = function () {
        this.v = '1.3.0';
        this.v = '1.4.0';
    };
    /**
@@ -20,7 +20,7 @@
        var elem = $(opt.elem);
        
        //默认设置
        opt.searchKey = opt.searchKey || 'keyword';
        opt.searchKey = opt.searchKey || 'keyword';//可多个用,分割
        opt.table.page = opt.table.page || false;
        opt.table.height = opt.table.height || 290;
        elem.off('click').on('click', function(e) {
@@ -167,13 +167,36 @@
                }
                
            })
            // é˜²æŠ–函数
            function debounce(func, wait) {
                let timeout;
                return function () {
                    const context = this, args = arguments;
                    clearTimeout(timeout);
                    timeout = setTimeout(() => func.apply(context, args), wait);
                };
            }
            //输入框输入执行
            elem.off('input').on('input', function (e) {
            elem.off('input').on('input', debounce(
                function (e) {
                // é˜»æ­¢è¡¨å•提交(如果输入框在表单内)
                e.preventDefault();
                var searchKeyList = opt.searchKey.split(',');//获取查找的关键字搜索框
                //拼接sql字符串
                var sWhereStr = " and ("
                searchKeyList.forEach(function (value, index) {
                    if (index == 0) {
                        sWhereStr += (value + " like '%" + elem.val() + "%' ")
                    } else {
                        sWhereStr += ("or " + value + " like '%" + elem.val() + "%' ")
                    }
                })
                sWhereStr +=")"
                //后端分页搜索
                if (opt.table.where != undefined) {
                    opt.table.where['sWhere'] = opt.sWhere + " and " + opt.searchKey + " like '%" + elem.val() + "%' ";
                    opt.table.where['sWhere'] = opt.sWhere + sWhereStr;
                    tableSelect_table.reload({
                        where: opt.table.where,
                        page: {
@@ -181,13 +204,13 @@
                        }
                    });
                } else {
                    var sWhere = opt.sWhere + " and " + opt.searchKey + " like '%" + elem.val() + "%' ";
                    var sWhere = opt.sWhere + sWhereStr;
                    tableSelect_table.reload({
                        data: opt.ajaxSelect(sWhere)
                    });
                }
                
            })
            },200))
            //双击行选中
            table.on('rowDouble('+tableName+')', function(obj){
WebTM/views/²É¹º¹ÜÀí/²É¹º¶©µ¥/Cg_POOrderBillEdit.html
@@ -1015,7 +1015,7 @@
                //供应商输入框
                tableSelect.render({
                    elem: '#HSupName',//输入框dom选择
                    searchKey: '供应商名称',//查询的列名
                    searchKey: '供应商名称,HItemID',//查询的列名
                    sWhere: '',//table搜索sWhere条件 //默认筛选项
                    ajaxSelect: function (sWhere) {
                        var data = '';