var locDetlLayerIdx; var locDetlData = []; function getCol() { var cols = [ ]; arrRemove(plaCols, 'type', 'checkbox'); cols.push.apply(cols, plaCols); cols.push({fixed: 'right', title:'操作', align: 'center', toolbar: '#operate', width: 80}) return cols; } layui.config({ base: baseUrl + "/static/layui/lay/modules/" }).use(['table','laydate', 'form', 'admin'], function() { var table = layui.table; var $ = layui.jquery; var layer = layui.layer; var form = layui.form; var admin = layui.admin; tableIns = table.render({ elem: '#chooseData', headers: {token: localStorage.getItem('token')}, data: [], totalRow: true, // 开启合计行 height: function(){ var otherHeight = $('.function-area').outerHeight() + $('#search-box').outerHeight(); // 自定义其他区域的高度 console.log($(window).height() - otherHeight); return $(window).height() - otherHeight - 100; // 返回 number 类型 }, //height: 'full', even: true, toolbar: '#toolbar', cellMinWidth: 50, cols: [function(){ var arr = getCol(); // 初始化筛选状态 var local = layui.data('table-filter-test'); // 获取对应的本地记录 layui.each(arr, function(index, item){ if(item.field in local){ item.hide = local[item.field]; } }); return arr; }() ], request: { pageName: 'curr', pageSize: 'limit' }, parseData: function (res) { console.log(res) return { 'code': res.code, 'msg': res.msg, 'count': res.data.total, 'data': res.data.records, } }, response: { statusCode: 200 }, done: function(res, curr, count) { // 记录筛选状态 var that = this; that.elem.next().on('mousedown', 'input[lay-filter="LAY_TABLE_TOOL_COLS"]+', function(){ var input = $(this).prev()[0]; // 此处表名可任意定义 layui.data('table-filter-test', { key: input.name ,value: input.checked }) }); //$(".lavui-table-grid-down").hide(); if (res.code === 403) { top.location.href = baseUrl+"/"; } tableData = table.cache.locDetl; console.log(tableData); pageCurr=curr; limit(); form.on('checkbox(tableCheckbox)', function (data) { var _index = $(data.elem).attr('table-index')||0; if(data.elem.checked){ res.data[_index][data.value] = 'Y'; }else{ res.data[_index][data.value] = 'N'; } }); let headerTop = $('.layui-table-header').offset().top; //获取表格头到文档顶部的距离 let headerPage = $('.layui-table-page').offset().top; //获取表格底部文档顶部的距离 $(window).scroll(function () { if ((headerTop - $(window).scrollTop()) < 0) { //超过了 $('.layui-table-header').addClass('table-header-fixed'); //添加样式,固定住表头 } else { //没超过 $('.layui-table-header').removeClass('table-header-fixed'); //移除样式 } }); } }); // 页面修改 table.on('edit(chooseData)', function (obj) { let index = obj.tr.attr("data-index"); let data = locDetlData[index]; let modify = true; if (obj.field === 'count'){ let vle = Number(obj.value); if (isNaN(vle)) { layer.msg("请输入数字", {icon: 2}); modify = false; } else { if (vle <= 0) { layer.msg("数量必须大于零", {icon: 2}); modify = false; } if (vle > Number(data.anfme)) { layer.msg("出库数量不得大于库存数量", {icon: 2}); modify = false; } } } if (modify) { data[obj.field] = obj.value; } tableIns.reload({data: locDetlData}); }); // 监听头工具栏事件 table.on('toolbar(chooseData)', function (obj) { switch (obj.event) { case 'outbound': if (locDetlData.length === 0){ layer.msg('请先提取商品库存', {icon: 2}); } else { var data = locDetlData; // var brand; for(var i=0; i item.brand !== res); tableIns.reload({data: locDetlData}); // parent.location.reload(); // console.log(locDetlData) }