|
@@ -17,12 +17,12 @@
|
|
|
</template>
|
|
|
|
|
|
<script setup name="SelectFilterUser">
|
|
|
-import { ref, watch } from 'vue';
|
|
|
+import { ref, watch, computed } from 'vue';
|
|
|
import { getUserList } from '@/api/user';
|
|
|
|
|
|
const emit = defineEmits(['update:modelValue', 'change']);
|
|
|
const props = defineProps({
|
|
|
- modelValue: { type: [Number, String], default: '' },
|
|
|
+ modelValue: { type: [Number, String, Array], default: '' },
|
|
|
defaultList: {
|
|
|
type: Array,
|
|
|
default() {
|
|
@@ -30,6 +30,10 @@ const props = defineProps({
|
|
|
},
|
|
|
},
|
|
|
});
|
|
|
+const isMultiple = computed(() => {
|
|
|
+ const multiple = attrs.multiple;
|
|
|
+ return multiple === '' || multiple;
|
|
|
+});
|
|
|
|
|
|
let optionList = ref([]);
|
|
|
let selected = ref('');
|
|
@@ -37,7 +41,7 @@ let loading = ref(false);
|
|
|
|
|
|
async function search(userInfo) {
|
|
|
if (!userInfo) {
|
|
|
- optionList.value = defaultList;
|
|
|
+ optionList.value = props.defaultList;
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -58,9 +62,11 @@ async function search(userInfo) {
|
|
|
}
|
|
|
|
|
|
const onChange = () => {
|
|
|
- const selectedData = optionList.value.find(
|
|
|
- (item) => selected.value === item.id
|
|
|
- );
|
|
|
+ const selectedData = isMultiple.value
|
|
|
+ ? optionList.value.filter(
|
|
|
+ (item) => selected.value && selected.value.includes(item.id)
|
|
|
+ )
|
|
|
+ : optionList.value.filter((item) => selected.value === item.id);
|
|
|
emit('update:modelValue', selected.value);
|
|
|
emit('change', selectedData);
|
|
|
};
|