| | |
| | | table = layui.table, |
| | | form = layui.form; |
| | | var tableSelect = function () { |
| | | this.v = '1.3.0'; |
| | | this.v = '1.4.0'; |
| | | }; |
| | | |
| | | //物料表格下拉搜索框使用案例 |
| | | //tableSelect.render({ |
| | | // elem: '#HMATERIALNAME', |
| | | // checkedKey: 'HItemID', |
| | | // searchKey: '物料代码,物料名称', |
| | | // sWhere: '',//table搜索sWhere条件 |
| | | // table: { |
| | | // url: GetWEBURL() + 'Gy_Material/page', |
| | | // where: { user: sessionStorage["HMaker"], "Organization": sessionStorage["Organization"] }, |
| | | // cols: [[ |
| | | // { type: 'checkbox', fixed: 'left' }, |
| | | // { field: 'HItemID', title: 'HItemID' }, |
| | | // { field: '物料代码', title: '物料代码' }, |
| | | // { field: '物料名称', title: '物料名称' }, |
| | | // ]], |
| | | // page: true, |
| | | // limit: 5, |
| | | // limits: [5] |
| | | // }, |
| | | // done: function (elem, data) { |
| | | // if (data != []) { |
| | | // //获取数据 |
| | | // /*$("#HMATERIALNAME").blur();//单元格失去焦点*/ |
| | | // $("#HMATERIALID").val(data.data[0].HItemID); |
| | | // $("#HMATERIALNAME").val(data.data[0].物料名称); |
| | | // get_FastQuery() |
| | | // } |
| | | |
| | | // } |
| | | //}) |
| | | //工序表格下拉搜索框 |
| | | //tableSelect.render({ |
| | | // elem: 'td[data-field="工序"] .layui-table-edit', |
| | | // searchKey: '工序代码,工序名称', |
| | | // sWhere: " and 明细标记 = 'Y' and 禁用标记 != 'Y'",//table搜索sWhere条件 |
| | | // ajaxSelect: function (sWhere) { |
| | | // var data = ''; |
| | | // $.ajax({ |
| | | // url: GetWEBURL() + '/Gy_Process/list', |
| | | // type: "GET", |
| | | // data: { "sWhere": sWhere, "user": sessionStorage["HUserName"] }, |
| | | // async: false, |
| | | // success: function (data1) { |
| | | // if (data1.count == 1) { |
| | | // data = data1.data |
| | | // } |
| | | // }, |
| | | // error: function () { |
| | | // layer.alert('获取列表失败!', { icon: 15, title: '通信错误' }); |
| | | // } |
| | | // }); |
| | | // return data; |
| | | // },//设置前端分页时可以设置的 |
| | | // table: { |
| | | // cols: [[ |
| | | // { type: 'radio', fixed: 'left' }, |
| | | // { field: 'HItemID', title: 'HItemID', hide: true }, |
| | | // { field: '工序代码', title: '工序代码' }, |
| | | // { field: '工序名称', title: '工序名称' }, |
| | | // { field: 'HProcMulID', title: 'HProcMulID', hide: true }, |
| | | // { field: '工段名称', title: '工段名称' } |
| | | // ]], |
| | | // page: true, |
| | | // limit: 5, |
| | | // //limits: [5] |
| | | // }, |
| | | // done: function (elem, data) { |
| | | // $(".layui-table-edit").blur();//单元格失去焦点 |
| | | // //setTableByHMater(obj, data); |
| | | // } |
| | | //}) |
| | | |
| | | /** |
| | | * 初始化表格选择器 |
| | |
| | | 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) { |
| | | elem.off('keyup').on('keyup', function(e) { |
| | | e.stopPropagation(); |
| | | if($('div.tableSelect').length >= 1){ |
| | | //输入字符小于二或者特殊按钮不显示 |
| | | if ($('div.tableSelect').length >= 1 || elem.val().length <= 2 || event.key == "F7" || event.key == "F8" || event.key == "F6") { |
| | | return false; |
| | | } |
| | | |
| | |
| | | //渲染TABLE |
| | | opt.table.elem = "#"+tableName; |
| | | opt.table.id = tableName; |
| | | //若没有where表示为前端分页 |
| | | if (opt.table.url != undefined) { |
| | | opt.table.where['sWhere'] = opt.sWhere |
| | | } else { |
| | | opt.table.data = opt.ajaxSelect(opt.sWhere); |
| | | //若没有url表示为前端分页 |
| | | //if (opt.table.url != undefined) { |
| | | // opt.table.where['sWhere'] = opt.sWhere |
| | | //} else { |
| | | // opt.table.data = opt.ajaxSelect(opt.sWhere); |
| | | //} |
| | | //让一次加载显示数据 |
| | | //当字符长度等于3时第一次加载 |
| | | if (elem.val().length == 3) { |
| | | searchFirst() |
| | | } |
| | | opt.table.request={//设置页参数 |
| | | pageName: 'page', // 页码的参数名称,默认:page |
| | |
| | | "data": res.data // 解析数据列表 |
| | | }; |
| | | } |
| | | //用jump替代原来表格pagejump用于更新按钮选中数量此功能发现无用删除 |
| | | //opt.table.done = function (res, curr, count, origin) { |
| | | // this.page.jump = jump; |
| | | //} |
| | | |
| | | var tableSelect_table = table.render(opt.table); |
| | | |
| | | //jump分页触发函数 |
| | | //function jump(obj, first) { |
| | | // table.reload(tableName); |
| | | // //更新按钮 |
| | | // updataButton(table.checkStatus(tableName).data.length) |
| | | //} |
| | | |
| | | //更新选中数量 |
| | | function updataButton (n) { |
| | | tableBox.find('.tableSelect_btn_select span').html(n==0?'':'('+n+')') |
| | | } |
| | | |
| | | //数组去重 |
| | | function uniqueObjArray(arr, type){ |
| | | var newArr = []; |
| | | var tArr = []; |
| | | if(arr.length == 0){ |
| | | return arr; |
| | | }else{ |
| | | if(type){ |
| | | for(var i=0;i<arr.length;i++){ |
| | | if(!tArr[arr[i][type]]){ |
| | | newArr.push(arr[i]); |
| | | tArr[arr[i][type]] = true; |
| | | } |
| | | } |
| | | return newArr; |
| | | }else{ |
| | | for(var i=0;i<arr.length;i++){ |
| | | if(!tArr[arr[i]]){ |
| | | newArr.push(arr[i]); |
| | | tArr[arr[i]] = true; |
| | | } |
| | | } |
| | | return newArr; |
| | | } |
| | | } |
| | | } |
| | | |
| | | //FIX位置如何下面放不下放上面 |
| | | var overHeight = (elem.offset().top + elem.outerHeight() + tableBox.outerHeight() - $(window).scrollTop()) > $(window).height(); |
| | |
| | | if (tr.length == 0) { |
| | | tableElem.find('tr:first').children('td').eq(0).click(); |
| | | } else { |
| | | tr.children('td').click(); |
| | | tr['prev']().children('td').click(); |
| | | tr.children('td').eq(0).click(); |
| | | tr['prev']().children('td').eq(0).click(); |
| | | } |
| | | break; |
| | | case "ArrowDown"://下键 |
| | | if (tr.length == 0) { |
| | | tr = tableElem.find('tr:first').children('td').eq(0).click(); |
| | | tableElem.find('tr:first').children('td').eq(0).click(); |
| | | } else { |
| | | tr.children('td').click(); |
| | | tr['next']().children('td').click(); |
| | | tr.children('td').eq(0).click(); |
| | | tr['next']().children('td').eq(0).click(); |
| | | } |
| | | break; |
| | | case "Enter"://回车 |
| | |
| | | } |
| | | |
| | | }) |
| | | //输入框输入执行 |
| | | elem.off('input').on('input', function (e) { |
| | | // 阻止表单提交(如果输入框在表单内) |
| | | e.preventDefault(); |
| | | // 防抖函数 |
| | | function debounce(func, wait) { |
| | | let timeout; |
| | | return function () { |
| | | const context = this, args = arguments; |
| | | clearTimeout(timeout); |
| | | timeout = setTimeout(() => func.apply(context, args), wait); |
| | | }; |
| | | } |
| | | //搜索函数第一次加载 |
| | | function searchFirst() { |
| | | 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; |
| | | } else { |
| | | var sWhere = opt.sWhere + sWhereStr; |
| | | opt.table.data = opt.ajaxSelect(sWhere); |
| | | } |
| | | } |
| | | |
| | | //输入框输入执行 |
| | | 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 + sWhereStr; |
| | | tableSelect_table.reload({ |
| | | where: opt.table.where, |
| | | page: { |
| | |
| | | } |
| | | }); |
| | | } else { |
| | | var sWhere = opt.sWhere + " and " + opt.searchKey + " like '%" + elem.val() + "%' "; |
| | | var sWhere = opt.sWhere + sWhereStr; |
| | | tableSelect_table.reload({ |
| | | data: opt.ajaxSelect(sWhere) |
| | | }); |
| | | } |
| | | |
| | | }) |
| | | },500)) |
| | | |
| | | //双击行选中 |
| | | table.on('rowDouble('+tableName+')', function(obj){ |
| | |
| | | //按钮选中 |
| | | tableBox.find('.tableSelect_btn_select').on('click', function() { |
| | | var checkStatus = table.checkStatus(tableName); |
| | | selectDone(checkStatus); |
| | | if (checkStatus.data.length > 0) { |
| | | selectDone(checkStatus); |
| | | } else { |
| | | tableBox.remove(); |
| | | delete table.cache[tableName]; |
| | | } |
| | | |
| | | }) |
| | | |
| | | //写值回调和关闭 |
| | |
| | | opt.done(elem, checkStatus); |
| | | tableBox.remove(); |
| | | delete table.cache[tableName]; |
| | | $(opt.elem).blur(); |
| | | } |
| | | |
| | | //点击其他区域关闭 |