纸通宝商家版本的小程序,原生微信开发。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

58 lines
1.8 KiB

import { VantComponent } from '../common/component';
import { pickerProps } from './shared';
VantComponent({
classes: ['active-class', 'toolbar-class', 'column-class'],
props: Object.assign(Object.assign({}, pickerProps), {
max: {
type: Number,
value: Infinity,
},
activeId: {
type: Array,
value: []
},
toolbarPosition: {
type: String,
value: 'top'
},
defaultIndex: {
type: Number,
value: 0
},
columns: {
type: Array,
value: []
},
selectedIcon: {
type: String,
value: 'success',
}
}),
methods: {
emit(event) {
const { type } = event.currentTarget.dataset;
if (this.data.columns.length) {
this.$emit(type, this.data.activeId );
} else {
this.$emit(type, { });
}
},
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 index = this.data.activeId.indexOf(item.id)
if (!item.disabled && !isOverMax) {
if(index > -1){
this.data.activeId.splice(index, 1)
} else {
this.data.activeId.push(item.id)
}
this.setData({ activeId: this.data.activeId });
}
},
}
});