<script setup lang="ts">
import { ref, onMounted } from "vue";
import { useVModel } from "@vueuse/core";
import RemoteSelect from "/@/components/RemoteSelect";
import { httpCustomerlist } from "/@/api/netOrderEnter/netOrderEntry";

const props = defineProps<{
  modelValue?: string;
  disabled?: boolean;
  prop
}>();

const emits = defineEmits(['change']);

const value = useVModel(props, "modelValue");

const RemoteSelectRef = ref<InstanceType<typeof RemoteSelect> | null>(null);

onMounted(() => {
  value.value && (RemoteSelectRef.value as any).initalData(value.value);
});

defineExpose({
  initalData: data => (RemoteSelectRef.value as any).initalData(data),
  getRecurrentValue: data => (RemoteSelectRef.value as any).getRecurrentValue(data),
});
</script>

<template>
  <RemoteSelect
    ref="RemoteSelectRef"
    :disabled="disabled"
    v-model="value"
    style="width: 100%"
    :api="httpCustomerlist"
    customProp="item"
    request-prop="companyName"
    response-label-prop="companyName"
    :response-val-prop="prop || 'companyNo'"
    @item-change="val => emits('change', val)"
    @clear="emits('change')"
  />
</template>
