<script setup lang="ts">
import { watch } from "vue";
import { useVModel } from "@vueuse/core";
import { httpWarelist } from "/@/api/other";
import { useAsync } from "/@/hooks/useAsync";

const props = defineProps<{
  modelValue: string;
  supplierNo: string;
  companyNo: string;
}>();

defineEmits(["update:modelValue"]);

const { data, loading, run } = useAsync<Record<string, string>[]>({
  initalData: [],
  isList: true
});

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

watch(
  () => props,
  () => {
    run(
      httpWarelist({
        companyNo: props.companyNo,
        supplierNo: props.supplierNo
      })
    );
  },
  {
    deep: true
  }
);
</script>

<template>
  <ElSelect
    class="w-full"
    placeholder="出库仓库"
    :loading="loading"
    v-model="value"
  >
    <ElOption
      v-for="item in data"
      :key="item.id"
      :value="item.wsm_code"
      :label="item.name"
    />
  </ElSelect>
</template>
