import { defineComponent, ref, computed, watch, watchEffect, openBlock, createElementBlock, createVNode, unref, mergeProps, toHandlers, withCtx, createElementVNode, normalizeClass, Fragment, renderList, toDisplayString, nextTick } from "vue";
import { Field } from "vant";
import { G as GET, q as proxy_api, S as Store, n as _export_sfc, y as _sfc_main$1, k as _sfc_main$2 } from "./index2.js";
import "@wltech/svg";
import "dayjs";
import "qs";
import "vuedraggable";
import "vue-router";
const getSearchCompany = (params) => {
  return GET(
    `${proxy_api[Store.node_env]}/interact/material/company/fuzzy_search`,
    params
  );
};
var index_vue_vue_type_style_index_0_scoped_true_lang = "";
const _hoisted_1 = { class: "company-search-field" };
const _hoisted_2 = { class: "uno-max-h-150 scroll-y uno-pt-10" };
const _hoisted_3 = ["onClick"];
const _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "index",
  props: {
    value: { default: "" },
    item: { default: () => {
    } },
    hasBorder: { type: Boolean, default: false },
    placeholder: { default: "" },
    placement: { default: "bottom-start" }
  },
  emits: ["update:value"],
  setup(__props, { emit }) {
    const props = __props;
    const fieldValue = ref();
    const popoverVisible = ref(false);
    const inputClass = computed(() => {
      return props.hasBorder ? `border-1 border-solid border-border-color uno-radius-6` : "";
    });
    const inputPlacehoder = computed(() => {
      var _a;
      return props.placeholder ? props.placeholder : `\u8BF7\u8F93\u5165${(_a = props == null ? void 0 : props.item) == null ? void 0 : _a.label}`;
    });
    const companyList = ref([]);
    const onPopoverSelect = (item) => {
      fieldValue.value = item.companyName;
    };
    const onSearch = async (val) => {
      var _a, _b;
      const result = await getSearchCompany({
        corp_id: Store.corp_id,
        appid: Store.app_id,
        name: val,
        scene: 1
      });
      companyList.value = ((_b = (_a = result.data) == null ? void 0 : _a.list) != null ? _b : []).slice(0, 10).map((res) => {
        return {
          companyName: res.name,
          companyCreditCode: res.credit_code,
          companyPlatFormId: res.platform_id
        };
      });
      nextTick(() => {
        popoverVisible.value = true;
      });
    };
    watch(
      () => fieldValue.value,
      (val) => {
        emit("update:value", val);
      }
    );
    watchEffect(() => {
      fieldValue.value = props.value;
    });
    return (_ctx, _cache) => {
      return openBlock(), createElementBlock("div", _hoisted_1, [
        createVNode(unref(Field), mergeProps({
          modelValue: fieldValue.value,
          "onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => fieldValue.value = $event),
          label: __props.item.label
        }, __props.item, toHandlers(__props.item.on || {})), {
          input: withCtx(() => [
            createVNode(_sfc_main$1, {
              modelValue: popoverVisible.value,
              "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => popoverVisible.value = $event),
              placement: __props.placement
            }, {
              reference: withCtx(() => [
                createElementVNode("div", {
                  class: normalizeClass(`w-full box-border uno-px-10 ${unref(inputClass)}`)
                }, [
                  createVNode(_sfc_main$2, {
                    modelValue: fieldValue.value,
                    "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => fieldValue.value = $event),
                    placeholder: unref(inputPlacehoder),
                    "need-debounce": true,
                    onOnChange: onSearch
                  }, null, 8, ["modelValue", "placeholder"])
                ], 2)
              ]),
              default: withCtx(() => [
                createElementVNode("div", _hoisted_2, [
                  (openBlock(true), createElementBlock(Fragment, null, renderList(companyList.value, (item) => {
                    return openBlock(), createElementBlock("div", {
                      key: item.companyCreditCode,
                      class: "w-full uno-px-10 uno-pb-10",
                      onClick: ($event) => onPopoverSelect(item)
                    }, toDisplayString(item.companyName), 9, _hoisted_3);
                  }), 128))
                ])
              ]),
              _: 1
            }, 8, ["modelValue", "placement"])
          ]),
          _: 1
        }, 16, ["modelValue", "label"])
      ]);
    };
  }
});
var index = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-22e60dde"]]);
export { index as default };
