<script setup lang="ts">
import { Events } from "~/dim/event";
import { useWarehouse } from "~/api/warehouse/warehouseService";
import type warehouseType from "~/domain/warehouse";
import { type shippingProductType } from "~/domain/warehouse";
import type warehouseQuery from "~/api/warehouse/warehouseQuery";
const props = defineProps<{
  warehouseCode: string | undefined;
  warehouseList: warehouseType[];
  isDisabled?: boolean;
}>();
const emit = defineEmits([Events.input, Events.change]);
const shippingProductList: Ref<shippingProductType[]> = ref([]);

function setShippingProductList() {
  if (props.warehouseList.length > 0) {
    let list = props.warehouseList.filter(
      (i: warehouseType) => i.warehouseCode == props.warehouseCode
    );
    shippingProductList.value = list[0].shippingProducts;
  }
}
function handleChange(val: any) {
  emit(Events.input, val);
  emit(Events.change, val);
}
watch(
  () => props.warehouseCode,
  async (first: any, second: any) => {
    setShippingProductList();
  }
);
onMounted(() => {
  setShippingProductList();
});
</script>

<template>
  <el-select filterable placeholder="请选择运输方式" @change="handleChange" :disabled="isDisabled">
    <el-option v-for="item in shippingProductList" :key="item.shippingProductCode" :label="item.shippingProductName" :value="item.shippingProductCode">
      {{ item.shippingProductName }}
    </el-option>
  </el-select>
</template>
