UNPKG

tfp

Version:

A Web UI framework for TaskBuilder

109 lines (98 loc) 3.32 kB
import {FormInput} from "../controller.js"; /** * 组织结构选择组件 * @param {[type]} dataModel [description] */ export default class OrgPicker extends FormInput { constructor(__tfp, dataModel, parent) { super(__tfp, "OrgPicker", dataModel, parent); } get value() { return this.dataModel.value } set value(value) { if(typeof(value)=="string") value = JSON.parse(value); if(this.dataModel.valueType=="obj") { this.dataModel.value = value; } else { if(this.dataModel.multiCheck) { let val = ""; for(var i=0;i<value.length;i++) { if(val!="") val += ","; val += value[i][this.dataModel.valueType]; } this.dataModel.value = val; } else { this.dataModel.value = value[this.dataModel.valueType]; } } if(this._jqObj) { if(this.dataModel.multiCheck) { let names = ""; for(var i=0;i<value.length;i++) { if(names!="") names += ","; names += value[i].name; } this._jqObj.find("input").val(names); } else { this._jqObj.find("input").val(value.name); } } if(!this._tfp.isDesigning) { this.valueOnChange(); this.exeEventHandler("onChange", this.dataModel.value); } } get iconUrl() { return this._tfp.rootPath+"/src/components/" +this.dataModel.type.toLowerCase()+"/images/icon-24-" +this._tfp.curPage.contentColorMode+".png"; } set iconUrl(value) {} //数据绑定格式 get dataBindingFormat() { return this.dataModel.dataBindingFormat } set dataBindingFormat(value) {this.dataModel.dataBindingFormat = value} get showIcon() { return this.dataModel.showIcon } set showIcon(value) { this.dataModel.showIcon = value ? true : false; if(this._jqObj) { if(this.dataModel.showIcon) { if(this._jqObj.find("img").length==0) { this._jqObj.append("<img src=\""+this.iconUrl+"\" />"); } } else { this._jqObj.find("img").remove(); } let iptWidth = "100%"; if(this.dataModel.showIcon) iptWidth = "calc(100% - 30px)"; this._jqObj.find("input").css("width", iptWidth+"px"); } } get valueType() { return this.dataModel.valueType } set valueType(value) { if(!this.checkAttrOption("valueType", value)) { this._tfp.showMsg("不支持类型:"+value+"!"); return; } this.dataModel.valueType = value; } get multiCheck() { return this.dataModel.multiCheck } set multiCheck(value) { this.dataModel.multiCheck = value ? true : false; } showPicker() { if(this.dataModel.multiCheck) { this._tfp.openDialog("组织结构选择", this._tfp.rootPath+"/src/components/orgpicker/orgsPicker.tfp?valueType=obj&cptId="+this.id, "445px", "405px"); } else { this._tfp.openDialog("组织结构选择", this._tfp.rootPath+"/src/components/orgpicker/orgPicker.tfp?valueType=obj&cptId="+this.id, "445px", "405px"); } } onSelected(ret) { this.value = ret; } initRuntime() { let that = this; this._jqObj.click(function(){ if(that.readonly || that.disabled) return; that.showPicker(); }); } }