|
@@ -22,14 +22,12 @@
|
|
defineOptions({
|
|
defineOptions({
|
|
name: 'SelectCourse',
|
|
name: 'SelectCourse',
|
|
});
|
|
});
|
|
- type ValueType = string | Array<string>;
|
|
|
|
|
|
|
|
const props = defineProps<{
|
|
const props = defineProps<{
|
|
- modelValue: ValueType;
|
|
|
|
|
|
+ modelValue: string;
|
|
clearable?: boolean;
|
|
clearable?: boolean;
|
|
disabled?: boolean;
|
|
disabled?: boolean;
|
|
placeholder?: string;
|
|
placeholder?: string;
|
|
- multiple?: boolean;
|
|
|
|
prefix?: boolean;
|
|
prefix?: boolean;
|
|
semesterId: string;
|
|
semesterId: string;
|
|
examId: string;
|
|
examId: string;
|
|
@@ -37,7 +35,7 @@
|
|
const emit = defineEmits(['update:modelValue', 'change']);
|
|
const emit = defineEmits(['update:modelValue', 'change']);
|
|
const attrs = useAttrs();
|
|
const attrs = useAttrs();
|
|
|
|
|
|
- const selected = ref<string | Array<string> | undefined>();
|
|
|
|
|
|
+ const selected = ref<string | undefined>();
|
|
const optionList = ref<OptionListItem[]>([]);
|
|
const optionList = ref<OptionListItem[]>([]);
|
|
const search = async () => {
|
|
const search = async () => {
|
|
optionList.value = [];
|
|
optionList.value = [];
|
|
@@ -48,19 +46,16 @@
|
|
});
|
|
});
|
|
|
|
|
|
optionList.value = (resData || []).map((item) => {
|
|
optionList.value = (resData || []).map((item) => {
|
|
- return { ...item, value: item.code, label: `${item.name}(${item.code})` };
|
|
|
|
|
|
+ return { ...item, value: item.id, label: `${item.name}(${item.code})` };
|
|
});
|
|
});
|
|
};
|
|
};
|
|
|
|
|
|
const onChange = () => {
|
|
const onChange = () => {
|
|
- const selectedData = props.multiple
|
|
|
|
- ? optionList.value.filter(
|
|
|
|
- (item) =>
|
|
|
|
- selected.value && (selected.value as string[]).includes(item.value)
|
|
|
|
- )
|
|
|
|
- : optionList.value.filter((item) => selected.value === item.value);
|
|
|
|
- emit('update:modelValue', selected.value || null);
|
|
|
|
- emit('change', props.multiple ? selectedData : selectedData[0]);
|
|
|
|
|
|
+ const selectedData = optionList.value.filter(
|
|
|
|
+ (item) => selected.value === item.value
|
|
|
|
+ );
|
|
|
|
+ emit('update:modelValue', selected.value || '');
|
|
|
|
+ emit('change', selectedData[0]);
|
|
};
|
|
};
|
|
|
|
|
|
watch(
|
|
watch(
|
|
@@ -75,7 +70,11 @@
|
|
watch(
|
|
watch(
|
|
() => props.examId,
|
|
() => props.examId,
|
|
(val, oldval) => {
|
|
(val, oldval) => {
|
|
- if (val !== oldval) search();
|
|
|
|
|
|
+ if (val !== oldval) {
|
|
|
|
+ emit('update:modelValue', '');
|
|
|
|
+ emit('change', null);
|
|
|
|
+ search();
|
|
|
|
+ }
|
|
},
|
|
},
|
|
{
|
|
{
|
|
immediate: true,
|
|
immediate: true,
|