var selectGridRowsDom = {} $(function () { selectGridRowsDom.openSelectedList=$('.icon-liebiao-open'); //打开选择列表 selectGridRowsDom.closeSelectedList=$('.icon-liebiao-close'); //关闭选择列表 selectGridRowsDom.iconContainer=$('.selected-icon-container'); //列表图标容器 selectGridRowsDom.layer=$('.selected-list-container'); //弹窗 selectGridRowsDom.isDrag=false; //是否正在拖拽 selectGridRowsDom.isOpen = false;//是否已经打开选择列表弹窗 selectGridRowsDom.selectedListLayerIndex = null ;// 选择列表弹窗的index selectGridRowsDom.selectedData =[]; //选中的列表数据 selectGridRowsDom.selectFields="";//三点外表字段列表 selectGridRowsDom.refGrid=null;//当前引用的grid // 打开选择列表弹窗 selectGridRowsDom.openSelectedList.on('mouseup', function (e) { if (selectGridRowsDom.isDrag || selectGridRowsDom.isOpen ||selectGridRowsDom.selectedData.length==0 ) return; selectGridRowsDom.selectedListLayerIndex = layer.open({ type: 1, area: ['800px', '610px'], closeBtn: 0, isOutAnim: false, // offset: ['100px', '650px'], title: ['已选择0条记录', 'font-size:18px;text-align:center;font-weight:600;'], resize: false, fixed: false, shade: 0, content: $('.selected-list-container'), move: false, success: function (layero, index) { // 设置弹窗位置 var layerPosition = selectGridRowsDom.getLayerPosition(); layer.style(index, { top: layerPosition.top + 'px', left: layerPosition.left + 'px', }); selectGridRowsDom.isOpen = true; setTimeout(function () { selectGridRowsDom.openSelectedList.removeClass('icon-open'); selectGridRowsDom.openSelectedList.addClass('icon-close'); }, 200); // 获取已经选中的列表数据,渲染到弹窗中 selectGridRowsDom.createSelectedListDom(selectGridRowsDom.selectedData); selectGridRowsDom.updateSelectedListLength(index); // 为弹窗添加拖拽事件 addDragLayerEvent(); // 弹窗内删除选择列表记录,同时取消页面内选择列表记录的选中状态 $('.layui-layer-content').on('click', '.deleteTableRow', function () { var pkObj = $(this).data('index').split(";");//主键数据 var delObj={}; var curObj=null; selectGridRowsDom.selectedData.forEach(function(item,index){ var flag=false; var obj1=""; var obj2=""; for(var i=0;i
  • 操作
  • '; for(var i=0;i'; tempTile[parm[i]]=1; } htmlTitle+=""; $('#gridTitle').html(htmlTitle); } // 在弹窗内生成页面已选列表数据Dom selectGridRowsDom.createSelectedListDom=function(data,grid) { if(grid!=undefined) selectGridRowsDom.refGrid=grid; var html = ''; var parm=selectGridRowsDom.selectFields.split(";"); var num=selectGridRowsDom.getFieldsLength(parm); var width=(num+1)*100; if(width<800){ width=800; } var gt=selectGridRowsDom.refGrid; var pkey=gt.primeKey.split(";");//表格的主键 data.forEach(function (item, index) { var pkObj="";//主键数据 for(var k=0;k' + '
  • [取消]
  • ' var tempTile={}; for(var i=0;i' ; tempTile[parm[i]]=1; } html += ''; }); $('.layui-layer-content .selected-list-tbody').html(html); } function closeSelectedListLayer() { layer.close(selectGridRowsDom.selectedListLayerIndex); selectGridRowsDom.isOpen = false; selectGridRowsDom.openSelectedList.removeClass('icon-close'); selectGridRowsDom.openSelectedList.addClass('icon-open'); } // 为弹窗标题添加拖拽事件 function addDragLayerEvent() { zxxDrag(document.querySelector('.selected-list-layer .layui-layer-title'), { target: document.querySelector('.layui-layer.layui-layer-page'), }); } // 页面更新已选列表数据长度 selectGridRowsDom.updateSelectedListLength=function(index) { if (index && typeof index == 'number') { selectGridRowsDom.selectedListLayerIndex = index; } var title = '已选择' + selectGridRowsDom.selectedData.length + '条记录'; layer.title(title, selectGridRowsDom.selectedListLayerIndex); $('.selected-icon-container .icon-dot').text(selectGridRowsDom.selectedData.length); // 如果选中的列表数据长度大于0,显示红点 if (selectGridRowsDom.selectedData.length > 0) { $('.selected-icon-container .icon-dot').show(); } else { $('.selected-icon-container .icon-dot').hide(); } } // 计算弹窗的位置 selectGridRowsDom.getLayerPosition=function() { var layerWidth = selectGridRowsDom.layer.innerWidth(); var layerHeight = selectGridRowsDom.layer.innerHeight(); var iconWidth = selectGridRowsDom.iconContainer.innerWidth(); var iconHeight = selectGridRowsDom.iconContainer.innerHeight(); var offsetTop = selectGridRowsDom.iconContainer.offset().top; var offsetLeft = selectGridRowsDom.iconContainer.offset().left - layerWidth + iconWidth; // 对offsetTop进行判断,如果超出屏幕高度,则设置为贴底的位置 if (offsetTop + iconHeight + layerHeight > $(window).height()) { offsetTop = $(window).height() - layerHeight - iconHeight; } // 对offsetLeft进行判断,如果为负数,则设置为0 if (offsetLeft < 0) { offsetLeft = 0; } return { top: offsetTop, left: offsetLeft }; } })