<script setup lang="ts">
import { Events } from "~/dim/event";
const props = defineProps<{ skuCode: string; isDisabled?: boolean;warehouseList:any }>();
const emit = defineEmits([Events.input, Events.change, Events.reset]);
import { DefaultQuery, pageSizes } from "~/domain/query";
import { useWarehouse } from "~/api/warehouse/warehouseService";
const { getWarehouseList } = useWarehouse();
import type warehouseType from "~/domain/warehouse";
import type warehouseQuery from "~/api/warehouse/warehouseQuery";
const defaultQuery = () => {
  const q = {} as warehouseQuery;
  q.skuCode = props.skuCode || "";
  return q;
};
const query: Ref<warehouseQuery> = ref(defaultQuery());
const warehouseList: Ref<warehouseType[]> = ref([]);
function handleChange(val: any) {
  emit(Events.input, val);
  emit(Events.change, val);
}
watch(
  () => props.warehouseList,
  async (first: any, second: any) => {
    warehouseList.value = props.warehouseList;
  }
);
// async function getWarehouseListFun() {
//   let res: any = await getWarehouseList(query.value);
//   if (res.code == 200) {
//     let rows = res.data;
//     // if (rows.length > 0) {
//     //   rows = rows.filter((i: warehouseType) => i.shippingProducts.length > 0);
//     // }
//     rows.forEach((item: any, index: number) => {
//       if (item.shippingProducts && item.shippingProducts.length > 1) {
//         item.shippingProducts.sort((a: any, b: any) => {
//           if (a.shippingType === "vendor" && b.shippingType !== "vendor") {
//             return -1; // a 在 b 前
//           } else if (
//             a.shippingType !== "vendor" &&
//             b.shippingType === "vendor"
//           ) {
//             return 1; // b 在 a 前
//           } else {
//             return 0; // 保持原顺序
//           }
//         });
//       }
//     });
//     warehouseList.value = rows;
//     emit(Events.reset, warehouseList.value);
//   }
// }

onMounted(() => {
});
</script>

<template>
  <!-- <el-radio-group @change="handleChange">
    <el-radio v-for="item in warehouseList" :key="item.warehouseCode" :value="item.warehouseCode">{{ item.warehouseName }}</el-radio>
  </el-radio-group> -->
  <el-select filterable placeholder="请选择仓库" @change="handleChange" :disabled="isDisabled">
    <el-option v-for="item in warehouseList" :key="item.warehouseCode" :label="item.warehouseName" :value="item.warehouseCode">
      {{ item.warehouseName }}
    </el-option>
  </el-select>
</template>
