import {Component, Prop, Vue, Emit, Watch} from 'vue-property-decorator'; @Component export default class EflySelectBox extends Vue { @Prop({default: () => ''}) private type!: any; @Prop({default: () => ''}) private multi!: any; @Prop({default: () => ''}) private search!: any; @Prop({default: () => ''}) private searchType!: any; @Prop({default: () => ''}) private data!: any; @Prop({default: () => ''}) private main!: any; @Prop({default: () => ''}) private minor!: any; @Prop({default: () => ''}) private children!: any; @Prop({default: () => ''}) private tier!: any; @Prop({default: () => ''}) private downIcon!: any; @Prop({default: () => ''}) private rightIcon!: any; private list: any = { data: [], } private mostParent: any; private created() { this.findMostParent(this); } @Watch('data', {immediate: true}) private watchData(value: any) { this.list.data = []; for (let i in this.data) { this.list.data.push(this.data[i]) } } @Watch('search', {immediate: true}) private watchSearch(value: any) { } private init(index: any = '') { for (let i in this.list.data) { if (index === this.list.data[i].selectID) { this.list.data[i].selected = false; } else if (this.multi) { } else { this.list.data[i].selected = false; } } this.$forceUpdate(); } /** * 找寻组件最父级 * @param that 当前作用域 */ private findMostParent(that: any) { if (that.$options._componentTag === 'efly-select') { this.mostParent = that; return } else { this.findMostParent(that.$parent) } } /** * 选择选项 * @param item * @param index */ private selectItem(item: any, index: any) { if(!item['efly-select-forbidden']){ this.mostParent.initItemSelected(); this.list.data[index].selected = this.multi ? !this.list.data[index].selected : true; this.$forceUpdate(); this.mostParent.selectItem(item); } } private showGroup(item: any) { item.groupShow = !item.groupShow; this.$forceUpdate(); } }