MemberLevelSelect.vue 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <template>
  2. <el-select v-model="levelId" placeholder="请选择用户等级" clearable class="!w-240px">
  3. <el-option v-for="level in levelOptions" :key="level.id" :label="level.name" :value="level.id">
  4. <span class="flex items-center gap-x-8px">
  5. <el-avatar :src="level.icon" size="small" />
  6. {{ level.name }}
  7. </span>
  8. </el-option>
  9. </el-select>
  10. </template>
  11. <script lang="ts" setup>
  12. import * as LevelApi from '@/api/member/level'
  13. /** 会员等级选择框 **/
  14. defineOptions({ name: 'MemberLevelSelect' })
  15. const props = defineProps({
  16. /** 下拉框选中值 **/
  17. modelValue: {
  18. type: Number,
  19. default: undefined
  20. }
  21. })
  22. const emit = defineEmits(['update:modelValue'])
  23. const levelId = computed({
  24. get() {
  25. return props.modelValue
  26. },
  27. set(value: any) {
  28. emit('update:modelValue', value)
  29. }
  30. })
  31. const levelOptions = ref<LevelApi.LevelVO[]>([])
  32. const getList = async () => {
  33. levelOptions.value = await LevelApi.getSimpleLevelList()
  34. }
  35. /** 初始化 */
  36. onMounted(() => {
  37. getList()
  38. })
  39. </script>