<template>
  <LjSelectorSelect
    ref="selectStationRef"
    v-model:value="props.value"
    :value-key="props.valueKey"
    :loading="loading"
    v-bind="$attrs"
    :remote-method="remoteMethod"
    popper-class="lj-select-codemx__popper"
    @select="handleSelect"
    @open-modal="openModal"
  >
    <template #label v-if="$slots?.label">
      <slot name="label"></slot>
    </template>
    <el-option v-for="item in options" :key="item.pzid" :label="item.namemx" :value="item" class="w-full"> </el-option>
  </LjSelectorSelect>
</template>

<script lang="ts" setup name="SelectorMtrldefSelect">
import { ref, computed, nextTick } from "vue";
// import { CommonDynamicSelect } from "@/api/modules/common";
import { DwnameEnum } from "@/enums/dwnameEnum";
import LjSelectorSelect from "@/components/LjSelector/select.vue";
import { useUserStore } from "@/stores/modules/user";
import { isFilterPrice } from "@/utils/index";
import { getConfigureCodeMxList } from "@/api/modules/basicinfo";

interface ProTableProps {
  value: any;
  pzid?: any;
  valueKey?: string;
  // typeid?: any;
  [key: string]: any;
}

// 默认值
const props = withDefaults(defineProps<ProTableProps>(), {
  valueKey: "pid"
});
const { userInfo } = useUserStore();
const emit = defineEmits(["select", "update:value", "openModal", "update:pricelistid"]);
const loading = ref(false);

const options = ref<any[]>([]);
// const isuse = ref("有效");
const selectStationRef = ref();

// const pricePower = computed(() => {
//   return userInfo.rsltFunids.includes(96);
// });

const remoteMethod = async (query: string) => {
  loading.value = true;
  let _params = {
    pzid: props.pzid,
    // typeid: props.typeid,
    keyword: query
  };
  let result = await getConfigureCodeMxList(_params);

  if (result?.datatable) {
    options.value = result.datatable;
  } else {
    options.value = [];
  }
  loading.value = false;
};

const handleSelect = (item: any) => {
  console.log("handleSelect 手动选择 :>> ", item);
  emit("select", item);
  // emit("select", item, () => {
  //   console.log("handleSelect 手动选择 :>>endsss :>> ", selectStationRef.value);
  //   // nextTick(() => {
  //   selectStationRef.value.element.blur();
  //   // });
  // });
};

const openModal = (e: any) => {
  emit("openModal", e);
};
</script>

<style lang="scss">
.lj-select-codemx__popper {
  max-width: 300px !important;
  min-width: 300px !important;
}
</style>
