<script setup>
import {ref} from "vue";
import ComboBox from "@/components/common/ComboBox.vue"

const props = defineProps(["v-domain-group-id"])
const emits = defineEmits(["change"])
const comboBox =ref()

const {userId, groupId} = ( function () {
	let groupId = props.vDomainGroupId
	if (groupId == null) {
		groupId = 0
	}
	return {
		userId: ref(0),
		groupId: ref(groupId)
	}
})()

const change= function (group) {
	if (group != null) {
		emits("change", group.id)
	} else {
		emits("change", 0)
	}
}

const reload = function (newUserId) {
	userId.value = newUserId
	comboBox.value.clear()
	comboBox.value.setDataURL("/ns/domains/groups/options?userId=" + newUserId)
	comboBox.value.reloadData()
}

defineExpose({
	reload
})

</script>

<template>
	<div>
		<ComboBox
			data-url="/ns/domains/groups/options"
			placeholder="选择分组"
			data-key="groups"
			name="groupId"
			:v-value="groupId"
			@change="change"
			ref="comboBox">
		</ComboBox>
	</div>
</template>

<style scoped lang="postcss">

</style>