o2.xdesktop.requireapp("process.xform", "$elinput", null, false);
mwf.xdesktop.requireapp("process.xform", "$selector", null, false);
if( !o2.app$elselector ){
o2.xapplication.process.xform.$elselector = o2.app$elselector = new class({
implements: [events],
extends: mwf.app$elinput
});
object.assign(o2.app$elselector.prototype, o2.app$selector.prototype);
}
/** @class elselect 基于element ui的选择框组de件。
* @o2cn 选择框
* @example
* //可以在脚本中获取该组件
* //方法1:
* var input = this.form.get("name"); //获取组件
* //方法2
* var input = this.target; //在组件事件脚本中获取
* @extends mwf.xapplication.process.xform.$module
* @o2category formcomponents
* @o2range {process|cms|portal}
* @hideconstructor
* @see {@link https://element.eleme.cn/#/zh-cn/component/select|element ui select 选择器}
*/
mwf.xapplication.process.xform.elselect = mwf.appelselect = new class(
/** @lends o2.xapplication.process.xform.elselect# */
{
implements: [events],
extends: mwf.app$elselector,
options: {
/**
* 组件加载后触发。如果选项加载为异步,则异步处理完成后触发此事件
* @event mwf.xapplication.process.xform.elselect#load
*/
"moduleevents": ["load", "queryload", "postload"],
/**
* 当 input 获得焦点时触发。this.event[0]指向event
* @event mwf.xapplication.process.xform.elselect#focus
* @see {@link https://element.eleme.cn/#/zh-cn/component/select|选择器的select events章节}
*/
/**
* 当 input 失去焦点时触发。this.event[0]指向event
* @event mwf.xapplication.process.xform.elselect#blur
* @see {@link https://element.eleme.cn/#/zh-cn/component/select|选择器的select events章节}
*/
/**
* 选中值发生变化时触发。this.event[0]为组件目前的选中值
* @event mwf.xapplication.process.xform.elselect#change
* @see {@link https://element.eleme.cn/#/zh-cn/component/select|选择器的select events章节}
*/
/**
* 下拉框出现/隐藏时触发。this.event[0]的值出现则为 true,隐藏则为 false
* @event mwf.xapplication.process.xform.elselect#visible-change
* @see {@link https://element.eleme.cn/#/zh-cn/component/select|选择器的select events章节}
*/
/**
* 多选模式下移除tag时触发。this.event[0]为移除的tag值
* @event mwf.xapplication.process.xform.elselect#remove-tag
* @see {@link https://element.eleme.cn/#/zh-cn/component/select|选择器的select events章节}
*/
/**
* 可清空的单选模式下用户点击清空按钮时触发。
* @event mwf.xapplication.process.xform.elselect#clear
* @see {@link https://element.eleme.cn/#/zh-cn/component/select|选择器的select events章节}
*/
"elevents": ["focus", "blur", "change", "visible-change", "remove-tag", "clear"]
},
// _loadnode: function(){
// if (this.isreadonly()) this.json.disabled = true;
// this._loadnodeedit();
// },
_loadmergereadcontentnode: function( contentnode, data ){
this._loadoptions();
promise.resolve( this.json.options || this.moduleselectag ).then(function(options){
var values = (o2.typeof(data.data) !== "array") ? [data.data] : data.data;
var text = this.__getoptionstext(options, values);
contentnode.set("text", text.join(","));
}.bind(this));
},
_appendvuedata: function(){
// this.form.macro.environment.data.check(this.json.id);
// this.json[this.json.id] = this._getbusinessdata();
if (!this.json.clearable) this.json.clearable = false;
if (!this.json.size) this.json.size = "";
if (!this.json.multiple) this.json.multiple = false;
if (!this.json.collapsetags) this.json.collapsetags = false;
if (!this.json.filterable) this.json.filterable = false;
if (!this.json.allowcreate) this.json.allowcreate = false;
if (!this.json.remote) this.json.remote = false;
if (!this.json.popperclass) this.json.popperclass = "";
if (!this.json.multiplelimit || !this.json.multiplelimit.toint()) this.json.multiplelimit = 0;
if (!this.json.nomatchtext) this.json.nomatchtext = "";
if (!this.json.nodatatext) this.json.nodatatext = "";
if (!this.json.loadingtext) this.json.loadingtext = "";
if (!this.json.description) this.json.description = "";
if (!this.json.disabled) this.json.disabled = false;
if (!this.json.loading) this.json.loading = false;
if (!this.json.options) this.json.options = [];
this._loadoptions();
if (this.json.multiple===true) if (!this.json[this.json.$id] || !this.json[this.json.$id].length) this.json[this.json.$id] = [];
},
appendvuemethods: function(methods){
if (this.json.filtermethod && this.json.filtermethod.code){
var fn = this.form.macro.exec(this.json.filtermethod.code, this);
methods.$filtermethod = function(){
fn.apply(this, arguments);
}.bind(this)
}
if (this.json.remotemethod && this.json.remotemethod.code){
var fn = this.form.macro.exec(this.json.remotemethod.code, this);
methods.$remotemethod = function(){
fn.apply(this, arguments);
}.bind(this)
}
},
_setoptionswithcode: function(code){
var v = this.form.macro.exec(code, this);
if (v.then){
this.moduleselectag = v.then(function(o){
if (o2.typeof(o)==="array"){
this.json.options = o.map(function(item){
if (o2.typeof(item)!=="object"){
var value = item.tostring();
return {"value": value, "label": value};
}
return item;
});
this.json.$options = array.clone(this.json.options);
return this.json.options;
}
}.bind(this));
}else if (o2.typeof(v)==="array"){
this.json.options = v.map(function(item){
if (o2.typeof(item)!=="object"){
var value = item.tostring();
return {"value": value, "label": value};
}
return item;
});
this.json.$options = array.clone(this.json.options);
}
},
_setoptionswitharray: function( optionitems ){
if (o2.typeof(optionitems)==="array"){
this.json.options = optionitems.map(function(item){
if (item && o2.typeof(item)!=="object"){
var value = item.tostring();
var arr = value.split("|");
if (arr.length>1){
return {"label": arr[0], "value": arr[1]};
}else{
return {"label": arr[0], "value": arr[0]};
}
}
return item;
});
this.json.$options = array.clone(this.json.options);
}
},
_loadoptions: function(){
if (this.json.itemsgroup===true){
if (this.json.itemgroupscript && this.json.itemgroupscript.code) this._setoptionswithcode(this.json.itemgroupscript.code);
}else{
// if (this.json.itemtype=="script"){
// if (this.json.itemscript && this.json.itemscript.code) this._setoptionswithcode(this.json.itemscript.code);
// }else{
// if (this.json.itemvalues && (o2.typeof(this.json.itemvalues)==="array")){
// this.json.options = this.json.itemvalues.map(function(item){
// if (item){
// var arr = item.split("|");
// if (arr.length>1){
// return {"label": arr[0], "value": arr[1]};
// }else{
// return {"label": arr[0], "value": arr[0]};
// }
// }
// });
// }
// }
var optionitems = this.getoptions();
if( optionitems && typeof(optionitems.then) === "function" ){
this.moduleselectag = promise.resolve(optionitems).then(function (optitems) {
this._setoptionswitharray( optitems );
this.moduleselectag = false;
return this.json.options;
}.bind(this));
}else{
this._setoptionswitharray( optionitems );
}
}
},
_createelementhtml: function(){
var html = "