import { Widget } from "./Widget";
import { Http } from "../Http";
import { Guid } from "@gvol-org/geovis-brain-core";
/**
* @class ui.Cascader
* @since ui
*/
export class Cascader extends Widget {
disabled: boolean = false;
content: object[];
placeholder: string;
value: object[];
id:string;
/**
* @hideconstructor
* @param {string} [placeholder] 默认显示的文本
* @param {object[]} [content] 级联菜单的内容
* @param {object[]} [value] 当前选择值
* @param {Function} [onChange] 选择不同值时触发的方法
* @param {Boolean} [disabled] 下拉列表是否可用
*@param {object} [style] 组件的样式
* @return ui.Cascader
*/
constructor(
placeholder?: string,
content?: object[],
value?: object[],
onChange?: Function,
disabled?: boolean,
style?: object
) {
let mapContainer = document.createElement("div");
mapContainer.style.flex='1 0 0%';
mapContainer.style.height='100%';
mapContainer.style.width='auto';
mapContainer.style.position='relative';
mapContainer.style.display='block';
let mapUI = document.createElement("div");
mapUI.classList.add("map-ui-div");
mapContainer.appendChild(mapUI);
super(mapContainer,style);
if (!(this instanceof Cascader)) {
return new Cascader(placeholder, content, value, onChange, disabled, style);
}
this.placeholder = placeholder;
this.content = content;
this.disabled = disabled;
this.value = value;
this.id=Guid.newGuid();
Http.generateComponentSubject$.next({
name: 'Map',
component: this,
data: {
placeholder: placeholder,
content: content,
value: value,
onChange: onChange,
disabled: disabled,
style: style,
id:this.id
}
});
}
/**
* 返回是否可用。
* @return {Boolean} Boolean
*/
getDisabled() {
return this.disabled;
}
/**
* 返回默认显示的文本
* @return {String} String
*/
getPlaceholder() {
return this.placeholder;
}
/**
* 返回级联菜单的内容
* @return {object[]} object[]
*/
getContent() {
return this.content;
}
/**
* 返回当前选择值
* @return {object[]} object[]
*/
getValue() {
return this.value;
}
/**
* 选择不同值时触发的方法
* @param {Function} callback 回调方法。
*/
onChange(callback: Function) {
}
/**
* 设置是否可用
* @param {Boolean} disabled 是否可用
* @return ui.Cascader
*/
setDisabled(disabled: boolean) {
this.disabled = disabled;
return this;
}
/**
* 设置默认显示的文本
* @param {String} placeholder 默认显示的文本
* @return ui.Cascader
*/
setPlaceholder(placeholder: string) {
this.placeholder = placeholder;
return this;
}
/**
* 设置级联菜单的内容
* @param {object[]} content 级联菜单的内容
* @return ui.Cascader
*/
setContent(content: object[]) {
this.content = content;
return this;
}
/**
* 设置当前选择值
* @param {object[]} value 当前选择值
* @return ui.Cascader
*/
setValue(value: object[]) {
this.value = value;
return this;
}
setStyle(style: object) {
return this;
}
}