<!--
 * @Author: YKH
 * @Date: 2021-12-08 10:29:23
 * @LastEditTime: 2022-10-03 19:48:17
 * @Description: file content
 * @FilePath: \cool-admin-3.x\cool-admin-vue-vue3-ts-vite\src\cool\modules\shuyou\components\shuyouGameDirector-select.vue
-->
<template>
	<el-select v-model="value" v-bind="props" @change="onChange">
		<el-option v-for="(item, index) in list" :key="index" :value="item.id" :label="item.name" />
	</el-select>
</template>

<script lang="ts">
import { defineComponent, inject, onMounted, ref, watch } from "vue";

export default defineComponent({
	name: "shuyouGameDirectorselect",

	props: {
		modelValue: [String, Number, Array],
		props: Object
	},

	emits: ["update:modelValue"],

	setup(props, { emit }) {
		// 请求服务
		const service = inject<any>("service");

		// 数据列表
		const list = ref<any[]>([]);

		// 绑定值
		const value = ref<any>();

		// 绑定值回调
		function onChange(val: any) {
			// alert(val)
			emit("update:modelValue", val);
		}

		// 解析值
		watch(
			() => props.modelValue,
			(val: any) => {
				value.value = val;
				//value.value =  (isArray(val) ? val : [val]).filter(Boolean);
			},
			{
				immediate: true
			}
		);

		onMounted(async () => {
			list.value = await service.shuyouGameDirector.list();
		});

		return {
			list,
			value,
			onChange
		};
	}
});
</script>
