fs-danaus
2023-06-26 2e5389660d216dabf6ebee15e7a3fa6eab73d01d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
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<pkObj.length;i++){
                            if(pkObj[i]=="") continue;
                            var obj=pkObj[i].split(":");
                            delObj[obj[0]]=obj[1];
                            obj1+=obj[1]+"";
                            obj2+=item[obj[0]]+"";
                        }
                        if(obj1!=""&&obj1==obj2){//比较由主键串起来的内容,如果一样表明是同一个
                            curObj=item;
                            selectGridRowsDom.selectedData.remove(item);
                           return;
                        }
                    });
                     $(this).parents('.selected-list-data-item').remove();
                     selectGridRowsDom.updateSelectedListLength();
                     //取消表格选择
                    selectGridRowsDom.refGrid.unSelectRow(delObj,curObj);
                 });
             }
 
         });
     });
 
 
     //  图标拖拽移动
     zxxDrag(document.querySelector('.icon-liebiao-open'), {
         target: document.querySelector('.selected-icon-container'),
         onMove: function (e) {
            selectGridRowsDom.isDrag = true;
             selectGridRowsDom.openSelectedList.css({
                 cursor: 'move'
             });
         },
         onEnd: function (e) {
            selectGridRowsDom.isDrag = false;
             selectGridRowsDom.openSelectedList.css({
                 cursor: 'pointer'
             });
         }
     });
 
 
     // 选择列表弹窗选好了按钮点击获取选中的列表数据
     $('#btn-confirm').on('click', function () {
         var grid=selectGridRowsDom.refGrid;
         grid.dbPopCont(grid.FRow ? grid.FRow : grid.ARow,null,true);
         closeSelectedListLayer();
     });
     $('#btn-close').on('click', function () {
        closeSelectedListLayer();
    });
     //  选择列表弹窗右上角按钮点击关闭弹窗
     selectGridRowsDom.closeSelectedList.on('click', function () {
         closeSelectedListLayer();
     });
     selectGridRowsDom.getFieldsLength=function(parm){
        //取得需要显示的字段,因为有可能会有重复字段,所以需要过滤
        var num=0;
        var tempTile={};
        var grid=selectGridRowsDom.refGrid;
        for(var i=0;i<parm.length;i++){
            if(grid.Cols[parm[i]]!=undefined&&grid.Cols[parm[i]].Visible!=undefined&&grid.Cols[parm[i]].Visible==0) continue;
            if(tempTile[parm[i]]!=undefined) continue;
            tempTile[parm[i]]=1;
            num++;
        }
        return num;
     }
//加标题
     selectGridRowsDom.createSelectedListTitle=function(grid) {
           selectGridRowsDom.refGrid=grid;
           selectGridRowsDom.selectFields=grid.gridInfo().formP.toLowerCase();
           var parm=selectGridRowsDom.selectFields.split(";");
           var tempTile={};
           var num=selectGridRowsDom.getFieldsLength(parm);
           var width=(num+1)*100;
           if(width<800){
            width=800;
           }
           var htmlTitle='<ul class="selected-list-th flex-row"  style="width:'+width+'px;"><li class="selected-list-tr">操作</li>';
           for(var i=0;i<parm.length;i++){
            if(grid.Cols[parm[i]]!=undefined&&grid.Cols[parm[i]].Visible!=undefined&&grid.Cols[parm[i]].Visible==0) continue;
            if(tempTile[parm[i]]!=undefined) continue;
           htmlTitle+='<li class="selected-list-tr">'+grid.Header[parm[i]]+'</li>';
                tempTile[parm[i]]=1;
           }
           htmlTitle+="</ul>";
           $('#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<pkey.length;k++){
               if(pkey[k]!=""){
                if(pkObj==""){
                    pkObj+=pkey[k]+":"+item[pkey[k]];
                }else{
                    pkObj+=";"+pkey[k]+":"+item[pkey[k]];
                }
               
               }
           }
             html += '<li class="selected-list-tr selected-list-data-item">' +
                 '<ul class="selected-list-ul flex-row" style="width:'+width+'px;margin:0;">' +
                 '<li class="selected-list-tr pointer smark deleteTableRow" data-index="' +
                 pkObj + '">[取消]</li>'
                 var tempTile={};
                 for(var i=0;i<parm.length;i++){
                    if(gt.Cols[parm[i]]!=undefined&&gt.Cols[parm[i]].Visible!=undefined&&gt.Cols[parm[i]].Visible==0) continue;
                    var value=item[parm[i]];
                    if(tempTile[parm[i]]!=undefined) continue;
                    if(value!=""&&gt.Cols[parm[i]].Type == "Enum"){
 
                        //下拉框情况需要转换成显示值输出
                        var keys = gt.Cols[parm[i]].EnumKeys.split("|");
                            var val = gt.Cols[parm[i]].Enum.split("|");
                            var indexd = null;
                            var isFound=false;
                            for (var sx = 0; sx < val.length; sx++) {
                                if (keys[sx] == value) {//9802设置是实际值,应该是取实际值
                                    indexd = sx;
                                    isFound=true;
                                    break;
                                }
                            }
                            if(!isFound){
                            for (var sx = 0; sx < val.length; sx++) {
                                if (val[sx] == value) {//9802设置是显示值,应该是取显示值
                                    indexd = sx;
                                    break;
                                }
                            }
                        }
                        if(indexd!=null&&indexd!=-1){
                        value=val[indexd];
                        }
                    }
                    html +=  '<li class="selected-list-tr">' + value + '</li>' ;
                    tempTile[parm[i]]=1;
                 }
                html +=  '</ul></li>';
         });
         $('.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
         };
     }
    })