zhuguifei
2026-03-10 2c1fd10c6fbabb8e9f0e9f07fe66fb36c008e883
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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
/**
    @name Edo.controls.Lov
    @class
    @typeName lov
    @description 页面弹出框
    @extend Edo.controls.TextInput
*/
Edo.controls.Lov = function(){
    Edo.controls.Lov.superclass.constructor.call(this);
    
    this.windowConfig = {
        width: 500,
        height: 300,
        left: 'center',
        top: 'middle',
        toolbar: 'no',
        scrollbars: 'no',
        menubar: 'no',
        resizable: 'no',
        location: 'no',
        status: 'no'
    };
    this.pageConfig = {
        
    };
    
    /**
        @name Edo.controls.Lov#beforeopen
        @event        
        @description 打开页面前事件
    */    
    /**
        @name Edo.controls.Lov#open
        @event        
        @description 打开页面事件
    */    
    /**
        @name Edo.controls.Lov#close
        @event        
        @description 关闭页面事件
    */    
    /**
        @name Edo.controls.Lov#submit
        @event        
        @description 数据提交事件
        @property {Object} data 提交的数据
    */    
    this.data = {};
};
Edo.controls.Lov.extend(Edo.controls.Trigger,{  
    /**        
        @name Edo.controls.Control#data
        @property
        @type Number
        @description 数据对象
    */
    /**        
        @name Edo.controls.Control#valueField
        @property
        @type String
        @default value
        @description 值字段
    */
    valueField: 'value',
    /**        
        @name Edo.controls.Control#displayField
        @property
        @type String 
        @default text
        @description 文本字段
    */
    displayField: 'text',
    /**        
        @name Edo.controls.Control#popupWidth
        @property
        @type Number
        @description 浮动下拉框宽度
    */
    url: '',
    /**        
        @name Edo.controls.Control#params
        @property
        @type Object
        @description 页面参数对象
    */    
    params: null,
    /**        
        @name Edo.controls.Control#pageName
        @property
        @type String
        @description 页面名称
    */    
    pageName: '',
    /**        
        @name Edo.controls.Control#autoMask
        @property
        @type Boolean
        @default true
        @description 页面打开时自动遮罩
    */  
    autoMask: true,
    maskTarget: '#body',
    readOnly: true,
    elCls: 'e-text e-search',
    initEvents: function(){             
        Edo.controls.Lov.superclass.initEvents.call(this);            
        
        if(!this.design){
            this.on('trigger', this._onLovTrigger, this, 0);
        }
    },
    _onLovTrigger: function(e){
        this.open(this.pageConfig);
    },
    createPageConfigString: function(obj){
        //坐标尺寸计算
        var sb = [];
        
        var sw = window.screen.width, sh = window.screen.height - 100;
        var w = obj.width, h = obj.height;
        for(var p in obj){
            var v = obj[p];
            if(p == 'left' && v == 'center'){
                v = sw / 2 - w / 2;
            }
            if(p == 'top' && v == 'middle'){
                v = sh / 2 - h / 2;
            }
            sb.push(p+'='+v);
        }
        return sb.join(',');
    },    
    getValue: function(){
        if(this.data) return this.data[this.valueField];
        return null;
    },    
    setValue: function(v){
        this._setData(v);
    }, 
    _setData: function(v){
        if(!Edo.isValue(v)) return;
        if(v !== this.data){
            this.data = v;
            this.set('text', v[this.displayField]);
        }
    },
    /**
        @name Edo.controls.Lov#submit
        @function
        @config
        @param {Object} data 数据对象
        @description 提交页面数据(同时关闭弹出页面)
    */ 
    submit: function(data){        
        if(typeof data != 'string'){            
            var o = {data: data};
            data = Edo.util.Json.encode(o);    
            data = Edo.util.Json.decode(data).data;        
        }else{
            data = Edo.util.Json.decode(data);
        }
        
        this.setValue(data);
        
        var e = {
            type: 'submit',
            source: this,
            data: data
        };
        this.fireEvent('submit', e);
        
        this.data = data;
        
        this.close();
    },
    /**
        @name Edo.controls.Lov#open
        @function
        @config
        @param {Object} config 页面配置对象<br/>
<pre>        
{
    width: 500,
    height: 300,
    left: 'center',
    top: 'middle',
    toolbar: 'no',
    scrollbars: 'no',
    menubar: 'no',
    resizable: 'no',
    location: 'no',
    status: 'no'
}        
</pre>
        @description 提交页面数据(同时关闭弹出页面)
    */ 
    open: function(config){
    
        if(this.pager){
            this.close();
        }
        
        var e = {
            type: 'beforeopen',
            source: this
        };
        if(this.fireEvent('beforeopen', e) === false) return false;
        
        if(this.autoMask){
            var obj = (this.maskTarget == '#body' || !this.maskTarget) ? document.body : this.maskTarget;
            if(Edo.type(obj) == 'element'){
                Edo.util.Dom.mask(obj);
            }else{
                obj.mask();
            }
        }
        var config = Edo.applyIf(this.pageConfig, this.windowConfig);
        var cstr = this.createPageConfigString(config);
        
        var url = Edo.urlEncode(this.params, this.url.indexOf('?') == -1 ? this.url+'?' : this.url);        
        
        this.pager = window.open(url, this.pageName, cstr);
        this.pager.focus();
        var sf = this;
        
        window.submitPagerData = function(data){
            sf.submit(data);
        }
        
        setTimeout(function(){
            Edo.util.Dom.on(sf.pager, 'unload',sf.onPageUnload, sf);
        }, this.deferBindUnload);
        
        this.startFocus();
        
        e.type = 'open';
        e.pager = this.pager;
        this.fireEvent('open', e);
    },
    deferBindUnload: 800,
    /**
        @name Edo.controls.Lov#close
        @function        
        @description 关闭页面
    */     
    close: function(){
    
        if(this.pager){
            this.pager.close();
            var obj = this.maskTarget == '#body' ? document.body : this.maskTarget;
            if(Edo.type(obj) == 'element'){
                Edo.util.Dom.unmask(obj);
            }else{
                obj.unmask();
            }
        }
        
        Edo.util.Dom.un(this.pager, 'unload',this.onPageUnload, this);
        this.stopFocus();
        this.pager = null;
        
        this.fireEvent('close', {
            type: 'close',
            source: this
        });
    },
    onWindowFocus: function(e){
        try{
            Edo.util.Dom.focus(this.pager);        
        }catch(e){
            
        }
    },
    onPageUnload: function(e){        
        this.close();
    },
    startFocus: function(){
        this.stopFocus();        
        Edo.util.Dom.on(window, 'focus', this.onWindowFocus, this);
    },
    stopFocus: function(){            
        Edo.util.Dom.un(window, 'focus', this.onWindowFocus, this);
    },
    destroy : function(){        
        this.close();
        
        Edo.controls.Lov.superclass.destroy.call(this);       
    }    
});
 
Edo.controls.Lov.regType('lov');