<script lang="ts" setup name="BizRuleSelector">
import { getBizRuleByList } from '@/api/biz/bizRuleApi'
const props = withDefaults(defineProps<{
  modelValue: number
}>(), {
  modelValue: 0,
})

const emit = defineEmits(['update:modelValue'])
interface BizRule {
  ruleId: number
  ruleTitle: string
}

const ruleId = computed({
  get: () => {
    return props.modelValue
  },
  set: (val) => {
    emit('update:modelValue', val)
  },
})

const state = reactive({
  loading: false,
  dataList: [] as BizRule[],
})

const getData = async () => {
  state.loading = true
  const { data } = await getBizRuleByList({})
  state.loading = false
  state.dataList = data
}
onMounted(() => {
  getData ()
})
</script>

<template>
  <el-select v-model="ruleId" v-loading="state.loading" style="width: 100%" filterable placeholder="请选择业务规则" value-key="ruleId">
    <el-option key="0" label="请选择" :value="0" disabled />
    <el-option
      v-for="item in state.dataList"
      :key="item.ruleId"
      :label="item.ruleTitle"
      :value="item.ruleId"
    />
  </el-select>
</template>
