<template>
    <uni-data-select
        v-model="modelValue"
        :localdata="options"
        placeholder="请选择商业公司"
        v-bind="omit($attrs,['change'])"
    />
</template>

<script setup>
import {defineModel, defineOptions, defineProps, getCurrentInstance, nextTick, onMounted, ref, withDefaults} from 'vue'
import {omit} from "radash";
import {getBusinessCompanyList} from "../api/orderManager";

defineOptions({
    name: "BusinessCompany",
    inheritAttrs: false
})

const modelValue = defineModel()
// default: type = all_name
/**
 * type:
 *  all_name = 显示所有名称
 *  id = value 值是 ID
 */
const props = defineProps({
    type: {
        type: String,
        default: 'all_name'
    }
})
const {proxy} = getCurrentInstance()

const options = ref([])

onMounted(async () => {
    await nextTick()
    const {data} = await getBusinessCompanyList({
        isUnit: 0,
        queryParam: {
            areaId: 0
        }
    })
    options.value = data.map(item => {
        return {
            value: props.type === 'id' ? item.userid : item.businessname,
            text: item.businessname
        }
    })
})
</script>
