fs-danaus
2023-06-26 2e5389660d216dabf6ebee15e7a3fa6eab73d01d
提交 | 用户 | age
025fd1 1 var selectGridRowsDom = {}
F 2 $(function () {
3     selectGridRowsDom.openSelectedList=$('.icon-liebiao-open'); //打开选择列表
4     selectGridRowsDom.closeSelectedList=$('.icon-liebiao-close'); //关闭选择列表
5     selectGridRowsDom.iconContainer=$('.selected-icon-container'); //列表图标容器
6     selectGridRowsDom.layer=$('.selected-list-container'); //弹窗
7     selectGridRowsDom.isDrag=false; //是否正在拖拽
8     selectGridRowsDom.isOpen = false;//是否已经打开选择列表弹窗
9     selectGridRowsDom.selectedListLayerIndex = null ;// 选择列表弹窗的index
10     selectGridRowsDom.selectedData =[]; //选中的列表数据
11     selectGridRowsDom.selectFields="";//三点外表字段列表
12     selectGridRowsDom.refGrid=null;//当前引用的grid
13      // 打开选择列表弹窗
14      selectGridRowsDom.openSelectedList.on('mouseup', function (e) {
15          if (selectGridRowsDom.isDrag || selectGridRowsDom.isOpen
16             ||selectGridRowsDom.selectedData.length==0
17             ) return;
18          selectGridRowsDom.selectedListLayerIndex = layer.open({
19              type: 1,
20              area: ['800px', '610px'],
21              closeBtn: 0,
22              isOutAnim: false,
23              // offset: ['100px', '650px'],
24              title: ['已选择0条记录', 'font-size:18px;text-align:center;font-weight:600;'],
25              resize: false,
26              fixed: false,
27              shade: 0,
28              content: $('.selected-list-container'),
29              move: false,
30              success: function (layero, index) {
31                  // 设置弹窗位置
32                  var layerPosition = selectGridRowsDom.getLayerPosition();
33                  layer.style(index, {
34                      top: layerPosition.top + 'px',
35                      left: layerPosition.left + 'px',
36                  });
37                  selectGridRowsDom.isOpen = true;
38                  setTimeout(function () {
39                      selectGridRowsDom.openSelectedList.removeClass('icon-open');
40                      selectGridRowsDom.openSelectedList.addClass('icon-close');
41                  }, 200);
42                  // 获取已经选中的列表数据,渲染到弹窗中
43                  selectGridRowsDom.createSelectedListDom(selectGridRowsDom.selectedData);
44                  selectGridRowsDom.updateSelectedListLength(index);
45                  // 为弹窗添加拖拽事件
46                  addDragLayerEvent();
47                  //  弹窗内删除选择列表记录,同时取消页面内选择列表记录的选中状态
48                  $('.layui-layer-content').on('click', '.deleteTableRow', function () {
49                      var pkObj = $(this).data('index').split(";");//主键数据
50                      var delObj={};
51                      var curObj=null;
52                     selectGridRowsDom.selectedData.forEach(function(item,index){
53                         var flag=false;
54                         var obj1="";
55                         var obj2="";
56                         for(var i=0;i<pkObj.length;i++){
57                             if(pkObj[i]=="") continue;
58                             var obj=pkObj[i].split(":");
59                             delObj[obj[0]]=obj[1];
60                             obj1+=obj[1]+"";
61                             obj2+=item[obj[0]]+"";
62                         }
63                         if(obj1!=""&&obj1==obj2){//比较由主键串起来的内容,如果一样表明是同一个
64                             curObj=item;
65                             selectGridRowsDom.selectedData.remove(item);
66                            return;
67                         }
68                     });
69                      $(this).parents('.selected-list-data-item').remove();
70                      selectGridRowsDom.updateSelectedListLength();
71                      //取消表格选择
72                     selectGridRowsDom.refGrid.unSelectRow(delObj,curObj);
73                  });
74              }
75
76          });
77      });
78
79
80      //  图标拖拽移动
81      zxxDrag(document.querySelector('.icon-liebiao-open'), {
82          target: document.querySelector('.selected-icon-container'),
83          onMove: function (e) {
84             selectGridRowsDom.isDrag = true;
85              selectGridRowsDom.openSelectedList.css({
86                  cursor: 'move'
87              });
88          },
89          onEnd: function (e) {
90             selectGridRowsDom.isDrag = false;
91              selectGridRowsDom.openSelectedList.css({
92                  cursor: 'pointer'
93              });
94          }
95      });
96
97
98      // 选择列表弹窗选好了按钮点击获取选中的列表数据
99      $('#btn-confirm').on('click', function () {
100          var grid=selectGridRowsDom.refGrid;
101          grid.dbPopCont(grid.FRow ? grid.FRow : grid.ARow,null,true);
102          closeSelectedListLayer();
103      });
104      $('#btn-close').on('click', function () {
105         closeSelectedListLayer();
106     });
107      //  选择列表弹窗右上角按钮点击关闭弹窗
108      selectGridRowsDom.closeSelectedList.on('click', function () {
109          closeSelectedListLayer();
110      });
111      selectGridRowsDom.getFieldsLength=function(parm){
112         //取得需要显示的字段,因为有可能会有重复字段,所以需要过滤
113         var num=0;
114         var tempTile={};
115         var grid=selectGridRowsDom.refGrid;
116         for(var i=0;i<parm.length;i++){
117             if(grid.Cols[parm[i]]!=undefined&&grid.Cols[parm[i]].Visible!=undefined&&grid.Cols[parm[i]].Visible==0) continue;
118             if(tempTile[parm[i]]!=undefined) continue;
119             tempTile[parm[i]]=1;
120             num++;
121         }
122         return num;
123      }
124 //加标题
125      selectGridRowsDom.createSelectedListTitle=function(grid) {
126            selectGridRowsDom.refGrid=grid;
127            selectGridRowsDom.selectFields=grid.gridInfo().formP.toLowerCase();
128            var parm=selectGridRowsDom.selectFields.split(";");
129            var tempTile={};
130            var num=selectGridRowsDom.getFieldsLength(parm);
2e5389 131            var width=(num+1)*100;
F 132            if(width<800){
133             width=800;
025fd1 134            }
2e5389 135            var htmlTitle='<ul class="selected-list-th flex-row"  style="width:'+width+'px;"><li class="selected-list-tr">操作</li>';
025fd1 136            for(var i=0;i<parm.length;i++){
F 137             if(grid.Cols[parm[i]]!=undefined&&grid.Cols[parm[i]].Visible!=undefined&&grid.Cols[parm[i]].Visible==0) continue;
138             if(tempTile[parm[i]]!=undefined) continue;
139            htmlTitle+='<li class="selected-list-tr">'+grid.Header[parm[i]]+'</li>';
140                 tempTile[parm[i]]=1;
141            }
142            htmlTitle+="</ul>";
143            $('#gridTitle').html(htmlTitle);
144     }
145      //  在弹窗内生成页面已选列表数据Dom
146      selectGridRowsDom.createSelectedListDom=function(data,grid) {
147         if(grid!=undefined) selectGridRowsDom.refGrid=grid;
148          var html = '';
149          var parm=selectGridRowsDom.selectFields.split(";");
150          var num=selectGridRowsDom.getFieldsLength(parm);
2e5389 151          var width=(num+1)*100;
F 152            if(width<800){
153             width=800;
025fd1 154            }
F 155          var gt=selectGridRowsDom.refGrid;
156          var pkey=gt.primeKey.split(";");//表格的主键
157          data.forEach(function (item, index) {
158             var pkObj="";//主键数据
159             for(var k=0;k<pkey.length;k++){
160                if(pkey[k]!=""){
161                 if(pkObj==""){
162                     pkObj+=pkey[k]+":"+item[pkey[k]];
163                 }else{
164                     pkObj+=";"+pkey[k]+":"+item[pkey[k]];
165                 }
166                
167                }
168            }
169              html += '<li class="selected-list-tr selected-list-data-item">' +
2e5389 170                  '<ul class="selected-list-ul flex-row" style="width:'+width+'px;margin:0;">' +
025fd1 171                  '<li class="selected-list-tr pointer smark deleteTableRow" data-index="' +
F 172                  pkObj + '">[取消]</li>'
173                  var tempTile={};
174                  for(var i=0;i<parm.length;i++){
175                     if(gt.Cols[parm[i]]!=undefined&&gt.Cols[parm[i]].Visible!=undefined&&gt.Cols[parm[i]].Visible==0) continue;
176                     var value=item[parm[i]];
177                     if(tempTile[parm[i]]!=undefined) continue;
178                     if(value!=""&&gt.Cols[parm[i]].Type == "Enum"){
179
180                         //下拉框情况需要转换成显示值输出
181                         var keys = gt.Cols[parm[i]].EnumKeys.split("|");
182                             var val = gt.Cols[parm[i]].Enum.split("|");
183                             var indexd = null;
184                             var isFound=false;
185                             for (var sx = 0; sx < val.length; sx++) {
186                                 if (keys[sx] == value) {//9802设置是实际值,应该是取实际值
187                                     indexd = sx;
188                                     isFound=true;
189                                     break;
190                                 }
191                             }
192                             if(!isFound){
193                             for (var sx = 0; sx < val.length; sx++) {
194                                 if (val[sx] == value) {//9802设置是显示值,应该是取显示值
195                                     indexd = sx;
196                                     break;
197                                 }
198                             }
199                         }
200                         if(indexd!=null&&indexd!=-1){
201                         value=val[indexd];
202                         }
203                     }
204                     html +=  '<li class="selected-list-tr">' + value + '</li>' ;
205                     tempTile[parm[i]]=1;
206                  }
207                 html +=  '</ul></li>';
208          });
209          $('.layui-layer-content .selected-list-tbody').html(html);
210      }
211
212      function closeSelectedListLayer() {
213         layer.close(selectGridRowsDom.selectedListLayerIndex);
214          selectGridRowsDom.isOpen = false;
215          selectGridRowsDom.openSelectedList.removeClass('icon-close');
216          selectGridRowsDom.openSelectedList.addClass('icon-open');
217      }
218
219      //  为弹窗标题添加拖拽事件
220      function addDragLayerEvent() {
221          zxxDrag(document.querySelector('.selected-list-layer .layui-layer-title'), {
222              target: document.querySelector('.layui-layer.layui-layer-page'),
223          });
224      }
225
226      //  页面更新已选列表数据长度
227      selectGridRowsDom.updateSelectedListLength=function(index) {
228          if (index && typeof index == 'number') {
229             selectGridRowsDom.selectedListLayerIndex = index;
230          }
231          var title = '已选择' + selectGridRowsDom.selectedData.length + '条记录';
232          layer.title(title, selectGridRowsDom.selectedListLayerIndex);
233          $('.selected-icon-container .icon-dot').text(selectGridRowsDom.selectedData.length);
234          // 如果选中的列表数据长度大于0,显示红点
235          if (selectGridRowsDom.selectedData.length > 0) {
236              $('.selected-icon-container .icon-dot').show();
237          } else {
238              $('.selected-icon-container .icon-dot').hide();
239          }
240      }
241
242      // 计算弹窗的位置
243      selectGridRowsDom.getLayerPosition=function() {
244          var layerWidth = selectGridRowsDom.layer.innerWidth();
245          var layerHeight = selectGridRowsDom.layer.innerHeight();
246          var iconWidth = selectGridRowsDom.iconContainer.innerWidth();
247          var iconHeight = selectGridRowsDom.iconContainer.innerHeight();
248          var offsetTop = selectGridRowsDom.iconContainer.offset().top;
249          var offsetLeft = selectGridRowsDom.iconContainer.offset().left - layerWidth + iconWidth;
250          // 对offsetTop进行判断,如果超出屏幕高度,则设置为贴底的位置
251          if (offsetTop + iconHeight + layerHeight > $(window).height()) {
252              offsetTop = $(window).height() - layerHeight - iconHeight;
253          }
254          //  对offsetLeft进行判断,如果为负数,则设置为0
255          if (offsetLeft < 0) {
256              offsetLeft = 0;
257          }
258          return {
259              top: offsetTop,
260              left: offsetLeft
261          };
262      }
263     })