import { Button, Checkbox, CheckboxGroup, Icon, Image, Loading, Radio, RadioGroup, Sticky, Toast } from 'vant' import { defineComponent, PropType } from 'vue' import styles from './index.module.less' import checkBoxActive from '@/teacher/teacher-cert/images/checkbox_active.png' import checkBoxDefault from '@/teacher/teacher-cert/images/checkbox_default.png' import ColResult from '@/components/col-result' export default defineComponent({ name: 'SubjectList', props: { onChoice: { type: Function, default: (item: any) => {} }, choiceSubjectIds: { type: Array, default: [] }, subjectList: { type: Array, default: [] }, max: { // 最多可选数量 type: Number, default: 5 }, selectType: { // 选择类型,Radio:单选,Checkbox:多选 type: String as PropType<'Checkbox' | 'Radio'>, default: 'Checkbox' }, single: { // 单选模式 type: Boolean, default: false } }, data() { return { checkBox: [], checkboxRefs: [] as any, radio: null as any // 单选 } }, async mounted() { if (this.selectType === 'Radio') { this.radio = this.choiceSubjectIds[0] } else { this.checkBox = this.choiceSubjectIds as never[] } }, watch: { choiceSubjectIds(val: any, oldVal) { // 同步更新显示数据 this.checkBox = [...val] as never[] } }, methods: { onSelect(id: number) { if (this.selectType === 'Checkbox') { if ( this.max === this.checkBox.length && !this.checkBox.includes(id as never) ) { Toast(`乐器最多选择${this.max}个`) } this.checkboxRefs[id].toggle() } else if (this.selectType === 'Radio') { this.radio = id } } }, render() { return (
{sub.name}
{item.name}
{sub.name}
{item.name}