2026-10-05 17:49:17 +03:30
|
|
|
<script setup lang="ts">
|
2026-10-18 19:39:59 +03:30
|
|
|
import { computed } from 'vue';
|
|
|
|
|
import { Select as ASelect } from 'ant-design-vue';
|
2026-10-05 17:49:17 +03:30
|
|
|
|
|
|
|
|
type PickUser = { id: string; fullName: string };
|
|
|
|
|
|
|
|
|
|
const props = withDefaults(
|
|
|
|
|
defineProps<{
|
|
|
|
|
modelValue: string[];
|
|
|
|
|
users: PickUser[];
|
|
|
|
|
disabled?: boolean;
|
|
|
|
|
/** حداقل تعداد انتخاب (حذف آخرین نفر غیرفعال میشود) */
|
|
|
|
|
min?: number;
|
|
|
|
|
addLabel?: string;
|
|
|
|
|
emptyLabel?: string;
|
|
|
|
|
}>(),
|
|
|
|
|
{ disabled: false, min: 0, addLabel: 'افزودن', emptyLabel: 'کسی انتخاب نشده' },
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const emit = defineEmits<{
|
|
|
|
|
'update:modelValue': [ids: string[]];
|
|
|
|
|
change: [ids: string[]];
|
|
|
|
|
}>();
|
|
|
|
|
|
2026-10-18 19:39:59 +03:30
|
|
|
const options = computed(() =>
|
|
|
|
|
props.users.map((u) => ({ value: u.id, label: u.fullName })),
|
2026-10-05 17:49:17 +03:30
|
|
|
);
|
|
|
|
|
|
2026-10-18 19:39:59 +03:30
|
|
|
function onUpdate(value: unknown) {
|
|
|
|
|
const ids = Array.isArray(value) ? value.map(String) : [];
|
|
|
|
|
if (ids.length < props.min && props.modelValue.length >= props.min) {
|
|
|
|
|
emit('update:modelValue', [...props.modelValue]);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
emit('update:modelValue', ids);
|
|
|
|
|
emit('change', ids);
|
2026-10-05 17:49:17 +03:30
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<template>
|
2026-10-18 19:39:59 +03:30
|
|
|
<a-select
|
|
|
|
|
mode="multiple"
|
|
|
|
|
allow-clear
|
|
|
|
|
show-search
|
|
|
|
|
option-filter-prop="label"
|
|
|
|
|
:value="modelValue"
|
|
|
|
|
:options="options"
|
|
|
|
|
:disabled="disabled"
|
|
|
|
|
:placeholder="emptyLabel"
|
|
|
|
|
style="width: 100%"
|
|
|
|
|
@update:value="onUpdate"
|
|
|
|
|
/>
|
2026-10-05 17:49:17 +03:30
|
|
|
</template>
|