1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- import { VantComponent } from '../common/component';
- VantComponent({
- classes: [
- 'main-item-class',
- 'content-item-class',
- 'main-active-class',
- 'content-active-class',
- 'main-disabled-class',
- 'content-disabled-class',
- ],
- props: {
- items: {
- type: Array,
- observer: 'updateSubItems',
- },
- activeId: null,
- mainActiveIndex: {
- type: Number,
- value: 0,
- observer: 'updateSubItems',
- },
- height: {
- type: null,
- value: 300,
- },
- max: {
- type: Number,
- value: Infinity,
- },
- selectedIcon: {
- type: String,
- value: 'success',
- },
- },
- data: {
- subItems: [],
- },
- methods: {
-
- onSelectItem(event) {
- const { item } = event.currentTarget.dataset;
- const isArray = Array.isArray(this.data.activeId);
-
- const isOverMax = isArray && this.data.activeId.length >= this.data.max;
-
- const isSelected = isArray
- ? this.data.activeId.indexOf(item.id) > -1
- : this.data.activeId === item.id;
- if (!item.disabled && (!isOverMax || isSelected)) {
- this.$emit('click-item', item);
- }
- },
-
- onClickNav(event) {
- const index = event.detail;
- const item = this.data.items[index];
- if (!item.disabled) {
- this.$emit('click-nav', { index });
- }
- },
-
- updateSubItems() {
- const { items, mainActiveIndex } = this.data;
- const { children = [] } = items[mainActiveIndex] || {};
- this.setData({ subItems: children });
- },
- },
- });
|