import "../../../../../../node_modules/element-plus/es/index.mjs";
/* empty css                                                                */
/* empty css                                                                    */
/* empty css                                                                     */
import { getCurrentInstance, inject, computed, createElementBlock, openBlock, createVNode, mergeProps, toHandlers, createSlots, withCtx, createTextVNode } from "vue";
import { openDialog } from "../../dialog/index.mjs";
/* empty css                 */
import _export_sfc from "../../../../../../_virtual/_plugin-vue_export-helper.mjs";
import { ElInput } from "../../../../../../node_modules/element-plus/es/components/input/index.mjs";
import { ElButton } from "../../../../../../node_modules/element-plus/es/components/button/index.mjs";
const _hoisted_1 = { class: "text-field-wrapper" };
const _sfc_main = /* @__PURE__ */ Object.assign({
  inheritAttrs: false
}, {
  __name: "UserSelect",
  props: {
    config: {
      type: Object,
      required: true
    },
    modelValue: {
      type: [String, Number],
      default: ""
    },
    placeholder: {
      type: String,
      default: ""
    },
    disabled: {
      type: Boolean,
      default: false
    },
    formMode: {
      type: String,
      default: ""
    },
    dialogConfig: {
      type: Object,
      default: {}
    }
  },
  emits: ["update:modelValue", "change"],
  setup(__props, { emit: __emit }) {
    const props = __props;
    const emit = __emit;
    function handleChange(val) {
      emit("change", val);
    }
    const instance = getCurrentInstance();
    const formData = inject("formData", null);
    inject("localConfig", null);
    const fieldsData = inject("fieldsData", null);
    const hiddenFields = inject("hiddenFields", null);
    const formCtx = inject("formCtx", null);
    const inputValue = computed(
      () => formData.value[props.config.displayFieldName]
    );
    function handleClear() {
      formData.value[props.config.displayFieldName] = "";
      formData.value[props.config.fieldName] = "";
    }
    const fieldsList = [
      ...(fieldsData == null ? void 0 : fieldsData.value) || [],
      ...(hiddenFields == null ? void 0 : hiddenFields.value) || []
    ];
    const dialog = props.dialogConfig;
    const customTableConfig = dialog.customTableConfig;
    customTableConfig.dataSources.push({
      id: "userSelectDataSourceId",
      name: "用户选择数据源",
      serverName: "base-server",
      url: "/user/sysUser/findByPageV5",
      method: "post",
      contentType: "json",
      params: dialog.dialogParams || []
    });
    function openSuffixDialog() {
      openDialog(
        props.config.displayFieldName,
        dialog,
        instance,
        formCtx,
        fieldsList,
        formData.value
      ).then((result) => {
        const values = result.map((row) => row.opNo);
        formData.value[props.config.fieldName] = values.join("|");
        console.log("确定", result);
      }).catch(() => {
        console.log("取消");
      });
    }
    return (_ctx, _cache) => {
      const _component_el_button = ElButton;
      const _component_el_input = ElInput;
      return openBlock(), createElementBlock("div", _hoisted_1, [
        createVNode(_component_el_input, mergeProps({
          modelValue: inputValue.value,
          "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => inputValue.value = $event)
        }, toHandlers(__props.config.eventHandlers), {
          placeholder: __props.placeholder,
          disabled: __props.disabled,
          onChange: handleChange,
          clearable: "",
          onClear: handleClear
        }), createSlots({ _: 2 }, [
          __props.formMode != "query" ? {
            name: "append",
            fn: withCtx(() => [
              createVNode(_component_el_button, {
                class: "suffixButton",
                onClick: openSuffixDialog
              }, {
                default: withCtx(() => _cache[1] || (_cache[1] = [
                  createTextVNode("选择")
                ])),
                _: 1
              })
            ]),
            key: "0"
          } : void 0
        ]), 1040, ["modelValue", "placeholder", "disabled"])
      ]);
    };
  }
});
const _UserSelect = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-0cc70898"]]);
export {
  _UserSelect as default
};
