import "../../../../../node_modules/element-plus/es/index.mjs";
/* empty css                                                             */
/* empty css                                                                 */
/* empty css                                                                     */
/* empty css                                                                  */
/* empty css                                                                  */
/* empty css                                                                */
import { ref, getCurrentInstance, computed, reactive, watch, onMounted, onUnmounted, createBlock, openBlock, normalizeClass, withCtx, createElementBlock, createCommentVNode, createElementVNode, Fragment, createVNode, unref, createSlots, renderList, renderSlot, normalizeProps, guardReactiveProps, nextTick } from "vue";
import { VxeTable } from "vxe-table";
import XEUtils from "xe-utils";
/* empty css                                                   */
import { createDataSource } from "../../utils/datasource.mjs";
import Pagination from "./Pagination.vue.mjs";
import CustomButtons from "./CustomButtons.vue.mjs";
import TableColumn from "./TableColumn.vue.mjs";
import TableFilter from "./TableFilter.vue.mjs";
import DynamicQuery from "./DynamicQuery.vue.mjs";
import { getCurrentVueInstance } from "../../utils/getInstance.mjs";
import { parseSingleParamValue } from "../../utils/parseRouteParams.mjs";
import { isEqual } from "../../utils/common.mjs";
/* empty css                                                                   */
/* empty css                                                                  */
/* empty css                                                                  */
import "../../utils/formulajs/functionCore.mjs";
import { useEventFlow } from "../../utils/eventFlow/eventFlowHandler.mjs";
/* empty css                                                                 */
/* empty css                                                                   */
/* empty css                            */
import _export_sfc from "../../../../../_virtual/_plugin-vue_export-helper.mjs";
/* empty css                                                  */
/* empty css                                                        */
/* empty css                                                   */
/* empty css                                                  */
/* empty css                                                     */
/* empty css                                                    */
/* empty css                                                               */
/* empty css                                                     */
/* empty css                                                   */
/* empty css                                                    */
/* empty css                                                                 */
/* empty css                                                                       */
import getJsonAsyncUtil from "../../utils/getJsonAsyncUtil.mjs";
import emitter from "../../utils/eventBus.mjs";
/* empty css            */
import { ElContainer } from "../../../../../node_modules/element-plus/es/components/container/index.mjs";
import { ElMessage } from "../../../../../node_modules/element-plus/es/components/message/index.mjs";
const _hoisted_1 = { class: "fec-vxe-table" };
const _sfc_main = /* @__PURE__ */ Object.assign({
  inheritAttrs: false
}, {
  __name: "Table",
  props: {
    templateKey: {
      type: String,
      default: ""
    },
    //模式
    mode: {
      type: String,
      default: ""
    },
    titleMode: {
      type: String,
      default: ""
    },
    // 表格数据
    tableData: {
      type: Array,
      default: () => []
    },
    initSearchData: {
      type: Object,
      default: {}
    },
    canLoadBySearchData: {
      type: Boolean,
      default: false
    },
    initOption: {
      type: Object,
      default: () => {
      }
    },
    isSubTable: {
      type: Boolean,
      default: false
    },
    isDialog: {
      type: Boolean,
      default: false
    },
    hasPagination: {
      type: Boolean,
      default: false
    },
    heightMode: {
      type: String,
      default: ""
    },
    height: {
      type: Number,
      default: null
    },
    maxHeight: {
      type: Number,
      default: null
    },
    readonly: {
      type: Boolean,
      default: false
    },
    selectMode: {
      type: String,
      default: "",
      validator: (value) => ["", "none", "single", "multiple"].includes(value)
    },
    initHiddenData: {
      type: Object,
      default: {}
    },
    btnRollbackEvent: {
      type: Object,
      default: {}
    },
    subTableConfig: {
      type: Object,
      default: {}
    }
  },
  emits: [
    "data-loaded",
    "data-error",
    "opt-click",
    "selection-change",
    "sort-change",
    "page-change",
    "loaded",
    "height-loaded"
  ],
  setup(__props, { expose: __expose, emit: __emit }) {
    const props = __props;
    const emit = __emit;
    const fecTableContainerRef = ref(null);
    const tableRef = ref(null);
    const tableContainer = ref(null);
    const currentMode = ref("");
    const instance = getCurrentInstance();
    const dataSourceManager = ref(null);
    const summaryAllDataManager = ref(null);
    const ctx = getCurrentVueInstance();
    const configLoading = ref(true);
    const localConfig = ref({});
    const fieldsData = ref({});
    const hiddenFormData = computed(() => ({
      ...props.initHiddenData,
      ...props.initSearchData
    }));
    const dataSourceOptions = ref({});
    const dictionaryOptions = ref({});
    const staticSortData = ref({});
    const displayData = computed(() => {
      var _a;
      if (props.tableData && props.tableData.length > 0) {
        return sortDataWithStaticRules(props.tableData);
      }
      const data = ((_a = dataSourceManager.value) == null ? void 0 : _a.getData().list) || [];
      return sortDataWithStaticRules(data);
    });
    const sortDataWithStaticRules = (data) => {
      if (!data || data.length === 0) return data;
      const sortFields = Object.keys(staticSortData.value);
      if (sortFields.length === 0) return data;
      const mockList = data.map((item) => ({ ...item }));
      const fields = sortFields.map((field) => ({
        field,
        order: staticSortData.value[field]
      }));
      return XEUtils.orderBy(mockList, fields);
    };
    const isPagination = computed(() => {
      var _a;
      if (props.isSubTable || props.isDialog) {
        return props.hasPagination;
      } else {
        return (_a = localConfig.value.paginationConfig) == null ? void 0 : _a.enabled;
      }
    });
    const displayPagination = computed(() => {
      var _a, _b, _c;
      if (props.tableData && props.tableData.length > 0) {
        return {
          show: false
        };
      }
      const data = (_a = dataSourceManager.value) == null ? void 0 : _a.getData();
      const pagination = (_b = dataSourceManager.value) == null ? void 0 : _b.getPagination();
      return {
        show: true,
        pageNo: (pagination == null ? void 0 : pagination.pageNo) || 1,
        pageSize: (pagination == null ? void 0 : pagination.pageSize) || ((_c = localConfig.value.paginationConfig) == null ? void 0 : _c.pageSize) || 15,
        pageTotal: (data == null ? void 0 : data.total) || 0
      };
    });
    const autoResize = computed(() => {
      if (props.isSubTable) {
        if (props.heightMode) {
          return props.heightMode == "auto";
        } else {
          return false;
        }
      } else {
        return localConfig.value.heightMode == "auto";
      }
    });
    const tableHeight = computed(() => {
      if (props.isSubTable) {
        if (props.heightMode == "fixed" && props.height) {
          return props.height;
        } else {
          return "";
        }
      } else {
        if (localConfig.value.heightMode === "auto") {
          return "100%";
        }
        return localConfig.value.height || 500;
      }
    });
    const tableMaxHeight = computed(() => {
      if (props.isSubTable) {
        if (props.heightMode == "max" && props.maxHeight) {
          return props.maxHeight;
        } else {
          return "";
        }
      } else {
        if (localConfig.value.heightMode === "max") {
          return localConfig.value.maxHeight || 500;
        }
        return "";
      }
    });
    const summaryConfig = computed(() => {
      return localConfig.value.summaryConfig || {
        enabled: false,
        mode: "current",
        summaryFields: []
      };
    });
    const allSummaryData = ref({});
    const footerData = computed(() => {
      const config = summaryConfig.value;
      const { enabled, mode, summaryFields = [] } = config;
      if (!enabled) return [];
      const firstItem = fieldsData.value.find((item) => item.isShow);
      if (!firstItem) {
        return [];
      }
      const firstSummaryField = firstItem.fieldName;
      const footerRow = { _isFooter: true };
      if (mode === "current") {
        fieldsData.value.forEach((item) => {
          const fieldName = item.fieldName;
          if (summaryFields.includes(fieldName)) {
            const sum = displayData.value.reduce((total, item2) => {
              const value = parseFloat(item2[fieldName]);
              return total + (isNaN(value) ? 0 : value);
            }, 0);
            if (isNaN(sum)) {
              footerRow[fieldName] = " ";
            } else {
              const field = fieldsData.value.find((f) => f.fieldName == fieldName);
              footerRow[fieldName] = formatSummaryValue(sum, field) || " ";
            }
          } else {
            footerRow[fieldName] = " ";
          }
        });
      } else if (mode === "all") {
        fieldsData.value.forEach((item) => {
          const fieldName = item.fieldName;
          if (summaryFields.includes(fieldName)) {
            const sum = allSummaryData.value[fieldName];
            if (sum != void 0 && sum != null) {
              const field = fieldsData.value.find((f) => f.fieldName == fieldName);
              footerRow[fieldName] = formatSummaryValue(sum, field) || " ";
            } else {
              footerRow[fieldName] = " ";
            }
          } else {
            footerRow[fieldName] = " ";
          }
        });
      }
      if (firstSummaryField) {
        footerRow[firstSummaryField] = "合计";
      }
      return [footerRow];
    });
    function formatSummaryValue(value, field) {
      if (!field) {
        return value;
      }
      const format = field.format;
      field.hasDecimalPlaces;
      field.decimalPlaces ?? 2;
      let result = value;
      switch (format) {
        case "yuan":
          result = value;
          break;
        case "wan":
          result = value / 1e4;
          break;
        case "million":
          result = value / 1e6;
          break;
        case "percentage":
          result = value * 100;
          break;
        case "permillage":
          result = value * 1e3;
          break;
        case "permillion":
          result = value * 1e4;
          break;
        default:
          result = value;
      }
      if (field.format == "yuan" || field.format == "wan" || field.format == "million") {
        const formatted = result.toLocaleString("en-US", {
          minimumFractionDigits: field.hasDecimalPlaces && field.decimalPlaces !== void 0 ? field.decimalPlaces : 0,
          maximumFractionDigits: field.hasDecimalPlaces && field.decimalPlaces !== void 0 ? field.decimalPlaces : 20
        });
        return formatted;
      }
      return result;
    }
    const routeParams = ref({});
    const initDataSourceManager = async () => {
      var _a, _b, _c, _d, _e, _f, _g, _h;
      if (!((_a = localConfig.value.dataSources) == null ? void 0 : _a.length)) return;
      let pageNo = 1;
      let pageSize = isPagination.value ? (_b = localConfig.value.paginationConfig) == null ? void 0 : _b.pageSize : 0;
      if (!props.isSubTable && !props.isDialog) {
        const route = (_c = ctx.$route) == null ? void 0 : _c.path;
        if (route) {
          routeParams.value = JSON.parse(sessionStorage.getItem(route));
          pageNo = ((_d = routeParams.value) == null ? void 0 : _d.pageNo) || 1;
          pageSize = ((_e = routeParams.value) == null ? void 0 : _e.pageSize) || ((_f = localConfig.value.paginationConfig) == null ? void 0 : _f.pageSize) || 15;
        }
      }
      dataSourceManager.value = createDataSource({
        http: ctx.$http,
        initSearchData: searchData.value,
        dataSources: localConfig.value.dataSources,
        currentDataSourceId: localConfig.value.dataSourceId,
        pagination: {
          pageNo,
          pageSize
        },
        data: hiddenFormData.value,
        fields: fieldsData.value,
        sortRules: localConfig.value.sortRules,
        templateId: localConfig.value.templateKey
      });
      dataSourceManager.value.on("loaded", (data) => {
        emit("data-loaded", data);
      });
      dataSourceManager.value.on("error", (err) => {
        emit("data-error", err);
      });
      if (!props.tableData || props.tableData.length === 0) {
        tableDataFetch(routeParams.value);
        if (((_g = localConfig.value.summaryConfig) == null ? void 0 : _g.enabled) && ((_h = localConfig.value.summaryConfig) == null ? void 0 : _h.mode) == "all") {
          summaryAllDataManager.value = createDataSource({
            http: ctx.$http,
            initSearchData: searchData.value,
            dataSources: localConfig.value.dataSources,
            currentDataSourceId: localConfig.value.dataSourceId,
            pagination: {
              pageNo: 1,
              pageSize: 0
              // 获取全部数据
            },
            data: hiddenFormData.value,
            fields: fieldsData.value,
            sortRules: localConfig.value.sortRules,
            templateId: localConfig.value.templateKey
          });
          await summaryAllDataFetch(routeParams.value);
        }
      }
      loadFieldDataSources();
    };
    const loadFieldDataSources = async () => {
      var _a, _b;
      const fields = fieldsData.value || [];
      const fieldDataSources = /* @__PURE__ */ new Set();
      const dictionaryKeys = /* @__PURE__ */ new Set();
      for (const field of fields) {
        if ((field.fieldType === "select" || field.fieldType === "multipleSelection") && field.optionConfig) {
          const { optionSource, dataSourceValue, dictionaryValue } = field.optionConfig;
          if (optionSource === "dataSource" && dataSourceValue) {
            fieldDataSources.add(dataSourceValue);
          } else if (optionSource === "dictionary" && dictionaryValue) {
            dictionaryKeys.add(dictionaryValue);
          }
        }
      }
      for (const dataSourceId of fieldDataSources) {
        if (dataSourceOptions.value[dataSourceId]) continue;
        try {
          const dsManager = createDataSource({
            http: ctx.$http,
            dataSources: localConfig.value.dataSources,
            currentDataSourceId: dataSourceId,
            pagination: false
          });
          const data = await dsManager.fetch();
          let options = [];
          if (Array.isArray(data)) {
            options = data;
          } else if (typeof data === "object") {
            options = Array.isArray(data.data) ? data.data : ((_a = data.data) == null ? void 0 : _a.records) || ((_b = data.data) == null ? void 0 : _b.list) || [];
          }
          dataSourceOptions.value[dataSourceId] = options;
          dsManager.destroy();
        } catch (error) {
          console.error(`Failed to load data source ${dataSourceId}:`, error);
        }
      }
      if (dictionaryKeys.size > 0) {
        try {
          const keyName = Array.from(dictionaryKeys).join(",");
          const response = await ctx.$http.postForm(
            "/base-server/parm/sysParmDic/getDicListByKey",
            {
              keyName
            }
          );
          const dictionaryData = response;
          if (typeof dictionaryData === "object") {
            Object.keys(dictionaryData).forEach((dictKey) => {
              if (dictionaryKeys.has(dictKey)) {
                const dictItems = dictionaryData[dictKey];
                if (Array.isArray(dictItems)) {
                  dictionaryOptions.value[dictKey] = dictItems;
                }
              }
            });
          }
        } catch (error) {
          console.error("Failed to load dictionary data:", error);
        }
      }
      mergeOptionsToFields();
    };
    const mergeOptionsToFields = () => {
      if (fieldsData.value) {
        fieldsData.value.forEach((field) => {
          if (!field.optionConfig) return;
          const {
            optionSource,
            dataSourceValue,
            dictionaryValue,
            displayField,
            valueField
          } = field.optionConfig;
          if (optionSource === "dataSource" && dataSourceOptions.value[dataSourceValue]) {
            const rawOptions = dataSourceOptions.value[dataSourceValue];
            const labelField = displayField || "label";
            const keyField = valueField || "value";
            field.optionConfig.options = rawOptions.map((item) => ({
              label: item[labelField],
              value: item[keyField],
              disabled: item.disabled || false
            }));
          } else if (optionSource === "dictionary" && dictionaryOptions.value[dictionaryValue]) {
            const rawOptions = dictionaryOptions.value[dictionaryValue];
            const labelField = "optName";
            const keyField = "optCode";
            field.optionConfig.options = rawOptions.map((item) => ({
              label: item[labelField],
              value: item[keyField],
              disabled: item.disabled || false
            }));
          } else if (optionSource === "custom") {
            field.optionConfig.options = field.optionConfig.options || [];
          }
        });
      }
    };
    const handleFlowEvent = ref(null);
    const handleCustomBtnClick = async ({ btn, event, type }) => {
      var _a, _b;
      switch (btn.btnType) {
        case "refresh":
          reset();
          break;
        case "export":
          handleExport();
          break;
        case "personalize":
          handlePersonalize();
          break;
        default:
          await ((_b = handleFlowEvent.value) == null ? void 0 : _b.call(
            handleFlowEvent,
            hiddenFormData.value,
            btn,
            (_a = btn.eventConfig) == null ? void 0 : _a.find((item) => item.name == "Click")
          ));
          const handleFunc = props.btnRollbackEvent[btn.id];
          if (handleFunc && typeof handleFunc == "function") {
            handleFunc();
          }
      }
    };
    const handleSortChange = ({ property, order }) => {
      const orderValue = order ? order.replace("ending", "") : "";
      const field = fieldsData.value.find((item) => item.fieldName == property);
      if ((field == null ? void 0 : field.sortRule) == "server") {
        dataSourceManager.value.updateSort(property, orderValue);
        tableDataFetch(routeParams.value);
      } else if ((field == null ? void 0 : field.sortRule) == "static") {
        if (orderValue) {
          staticSortData.value[property] = orderValue;
        } else {
          delete staticSortData.value[property];
        }
      }
      emit("sort-change", { field: property, order: orderValue });
    };
    const handlePageChange = ({ pageNo, pageSize }) => {
      if (dataSourceManager.value) {
        dataSourceManager.value.updatePagination(pageNo, pageSize);
        const params = { ...routeParams.value };
        delete params.pageNo;
        delete params.pageSize;
        tableDataFetch(params);
      }
      emit("page-change", { pageNo, pageSize });
    };
    const handleCheckboxChange = (checked) => {
      emit("selection-change", checked.records);
    };
    const handleCheckboxAll = (checked) => {
      emit("selection-change", checked.records);
    };
    const handleRadioChange = (checked) => {
      emit("selection-change", [checked.row]);
    };
    const handleInitRendered = ({ visibleColumn, visibleData, $event }) => {
      const offsetHeight = fecTableContainerRef.value.$el.offsetHeight;
      emit("height-loaded", localConfig.value, offsetHeight);
      if ((visibleData == null ? void 0 : visibleData.length) > 0) {
        emitter.emit("onSubTableDataLoaded", {
          subTableConfig: props.subTableConfig,
          visibleData
        });
      }
    };
    const handleDataRendered = ({
      isReload,
      visibleColumn,
      visibleData,
      $event
    }) => {
      const offsetHeight = fecTableContainerRef.value.$el.offsetHeight;
      emit("height-loaded", localConfig.value, offsetHeight);
      if ((visibleData == null ? void 0 : visibleData.length) > 0) {
        emitter.emit("onSubTableDataLoaded", {
          subTableConfig: props.subTableConfig,
          visibleData
        });
      }
    };
    const handleFilterSearch = (filters) => {
      var _a, _b;
      if (dataSourceManager.value) {
        dataSourceManager.value.updateParams(filters);
        dataSourceManager.value.updatePagination(
          1,
          ((_a = localConfig.value.paginationConfig) == null ? void 0 : _a.pageSize) || 10
        );
        const $table = tableRef.value;
        if ($table) {
          $table.clearSort();
        }
        dataSourceManager.value.clearSort();
        (_b = summaryAllDataManager.value) == null ? void 0 : _b.updateParams(filters);
        tableDataFetch();
        clearSelection();
      } else {
        searchData.value = filters;
      }
    };
    const handleFilterReset = () => {
      var _a, _b;
      if (dataSourceManager.value) {
        dataSourceManager.value.clearParams();
        dataSourceManager.value.updatePagination(
          1,
          ((_a = localConfig.value.paginationConfig) == null ? void 0 : _a.pageSize) || 10
        );
        const $table = tableRef.value;
        if ($table) {
          $table.clearSort();
        }
        dataSourceManager.value.clearSort();
        (_b = summaryAllDataManager.value) == null ? void 0 : _b.clearParams();
        tableDataFetch();
        clearSelection();
      }
    };
    const refresh = (options = {}) => {
      var _a;
      const {
        resetSort = false,
        resetFilter = false,
        resetPagination = false
      } = options;
      if (dataSourceManager.value) {
        if (resetPagination) {
          dataSourceManager.value.updatePagination(
            1,
            ((_a = localConfig.value.paginationConfig) == null ? void 0 : _a.pageSize) || 10
          );
        }
        if (resetSort) {
          const $table = tableRef.value;
          if ($table) {
            $table.clearSort();
          }
          dataSourceManager.value.clearSort();
        }
        if (resetFilter) {
          const $table = tableRef.value;
          if ($table) {
            $table.clearFilter();
          }
        }
        tableDataFetch();
      }
    };
    const reset = () => {
      var _a;
      if (dataSourceManager.value) {
        dataSourceManager.value.updatePagination(
          1,
          ((_a = localConfig.value.paginationConfig) == null ? void 0 : _a.pageSize) || 10
        );
        const $table = tableRef.value;
        if ($table) {
          $table.clearSort();
        }
        dataSourceManager.value.clearSort();
        tableDataFetch();
      }
    };
    async function tableDataFetch(extraParams = {}) {
      var _a;
      if (!props.isSubTable && !props.isDialog) {
        const params = dataSourceManager.value.buildRequestParams(extraParams);
        const route = (_a = ctx.$route) == null ? void 0 : _a.path;
        if (route) {
          sessionStorage.setItem(route, JSON.stringify(params));
        }
      }
      await dataSourceManager.value.fetch(extraParams);
      await summaryAllDataFetch(extraParams);
    }
    async function summaryAllDataFetch(extraParams = {}) {
      var _a, _b;
      if (((_a = localConfig.value.summaryConfig) == null ? void 0 : _a.enabled) && ((_b = localConfig.value.summaryConfig) == null ? void 0 : _b.mode) == "all") {
        const data = await summaryAllDataManager.value.fetch(extraParams);
        const summaryFields = localConfig.value.summaryConfig.summaryFields || [];
        const allList = (data == null ? void 0 : data.list) || [];
        const summaryResult = {};
        summaryFields.forEach((fieldName) => {
          const sum = allList.reduce((total, item) => {
            const value = parseFloat(item[fieldName]);
            return total + (isNaN(value) ? 0 : value);
          }, 0);
          summaryResult[fieldName] = sum;
        });
        fieldsData.value.forEach((item) => {
          if (!summaryResult[item.fieldName]) {
            summaryResult[item.fieldName] = "";
          }
        });
        allSummaryData.value = summaryResult;
      }
    }
    const exportConfig = reactive({
      modes: ["current", "selected", "all", "empty"],
      original: false
    });
    const handleExport = () => {
      const $table = tableRef.value;
      if ($table) {
        $table.openExport();
      }
    };
    const rowConfig = computed(() => {
      return {
        keyField: localConfig.value.pkFieldName || "",
        isHover: true
      };
    });
    const radioConfig = ref({
      trigger: "row",
      highlight: true
    });
    const checkboxConfig = ref({
      showHeader: true,
      trigger: "row",
      highlight: true,
      showReserveStatus: true,
      isShiftKey: true,
      range: true,
      reserve: true
    });
    const sortConfig = reactive({
      multiple: true,
      chronological: true,
      remote: true
    });
    const handlePersonalize = () => {
      if (tableRef.value) {
        tableRef.value.openCustom();
      }
    };
    const switchMode = (modeKey) => {
      currentMode.value = modeKey;
    };
    const getSelection = () => {
      if (!tableRef.value) return [];
      return tableRef.value.getCheckboxRecords() || tableRef.value.getRadioRecord() || [];
    };
    const clearSelection = () => {
      if (tableRef.value) {
        tableRef.value.clearCheckboxRow();
        tableRef.value.clearRadioRow();
      }
    };
    watch(
      () => props.mode,
      (mode) => {
        currentMode.value = mode;
      },
      { immediate: true }
    );
    const loadConfig = async () => {
      var _a, _b;
      if (!props.templateKey) {
        if (props.initOption) {
          localConfig.value = Object.assign({}, props.initOption);
        }
        fieldsData.value = [
          ...localConfig.value.fieldsData || [],
          ...(localConfig.value.hiddenFields || []).map((item) => ({
            ...item,
            isShow: false
          }))
        ];
        (_a = localConfig.value.hiddenFields) == null ? void 0 : _a.forEach((item) => {
          if (!hiddenFormData.value[item.fieldName]) {
            if (typeof item.value == "object") {
              const value = parseSingleParamValue(item.value, {}, fieldsData.value);
              hiddenFormData.value[item.fieldName] = value !== void 0 ? value : null;
            } else {
              hiddenFormData.value[item.fieldName] = item.value !== void 0 ? item.value : null;
            }
          }
        });
        initHandleEvent();
        configLoading.value = false;
        nextTick(() => {
          var _a2;
          const offsetHeight = ((_a2 = fecTableContainerRef.value) == null ? void 0 : _a2.$el.offsetHeight) || 300;
          emit("height-loaded", localConfig.value, offsetHeight);
        });
        return;
      }
      configLoading.value = true;
      try {
        let option = await getJsonAsyncUtil(
          ctx.$http,
          props.templateKey,
          "table",
          props.initOption
        );
        localConfig.value = option;
        fieldsData.value = [
          ...localConfig.value.fieldsData || [],
          ...(localConfig.value.hiddenFields || []).map((item) => ({
            ...item,
            isShow: false
          }))
        ];
        (_b = localConfig.value.hiddenFields) == null ? void 0 : _b.forEach((item) => {
          if (!hiddenFormData.value[item.fieldName]) {
            if (typeof item.value == "object") {
              const value = parseSingleParamValue(item.value, {}, fieldsData.value);
              hiddenFormData.value[item.fieldName] = value !== void 0 ? value : null;
            } else {
              hiddenFormData.value[item.fieldName] = item.value !== void 0 ? item.value : null;
            }
          }
        });
        initHandleEvent();
        emit("loaded", option);
      } catch (error) {
        console.error("加载配置失败:", error);
        ElMessage.error("加载配置失败");
      } finally {
        configLoading.value = false;
      }
    };
    function initHandleEvent() {
      const { handleEvent } = useEventFlow({
        fields: fieldsData.value,
        instance,
        localConfig: localConfig.value,
        components: {
          table: instance == null ? void 0 : instance.proxy
        }
      });
      handleFlowEvent.value = handleEvent;
    }
    onMounted(() => {
      loadConfig().then(() => {
        initDataSourceManager();
      });
    });
    const searchData = ref({});
    watch(
      () => props.initSearchData,
      (newVal, oldVal) => {
        if (props.canLoadBySearchData && dataSourceManager.value && !isEqual(newVal, oldVal)) {
          dataSourceManager.value.updateInitSearchData(newVal);
          refresh();
        }
      },
      { deep: true }
    );
    watch(
      () => props.initHiddenData,
      (newVal, oldVal) => {
        if (props.canLoadBySearchData && dataSourceManager.value && !isEqual(newVal, oldVal)) {
          dataSourceManager.value.updateInitSearchData(newVal);
          refresh();
        }
      },
      { deep: true }
    );
    onUnmounted(() => {
      if (dataSourceManager.value) {
        dataSourceManager.value.destroy();
      }
    });
    const setFormData = (data) => {
      Object.assign(hiddenFormData.value, data);
    };
    __expose({
      tableRef,
      refresh,
      reset,
      switchMode,
      getSelection,
      clearSelection,
      exportData: handleExport,
      localConfig,
      setFormData,
      handleCustomBtnClick
    });
    return (_ctx, _cache) => {
      const _component_el_container = ElContainer;
      return openBlock(), createBlock(_component_el_container, {
        direction: "vertical",
        class: normalizeClass(`fec-table ${__props.isSubTable ? "fec-table-sub" : ""}`),
        "data-id": localConfig.value.templateKey,
        "data-name": localConfig.value.templateName,
        "data-pkId": localConfig.value.pkId,
        "data-version": "v5",
        ref_key: "fecTableContainerRef",
        ref: fecTableContainerRef
      }, {
        default: withCtx(() => {
          var _a, _b, _c, _d;
          return [
            !configLoading.value ? (openBlock(), createElementBlock("div", {
              key: 0,
              ref_key: "tableContainer",
              ref: tableContainer,
              class: "fec-table-container"
            }, [
              ((_b = (_a = localConfig.value) == null ? void 0 : _a.queryConfig) == null ? void 0 : _b.mode) == "fixed" ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
                createVNode(TableFilter, {
                  "query-config": localConfig.value.queryConfig,
                  "fields-data": fieldsData.value,
                  isCache: !__props.isSubTable && !__props.isDialog,
                  onSearch: handleFilterSearch,
                  onReset: handleFilterReset
                }, null, 8, ["query-config", "fields-data", "isCache"]),
                createVNode(CustomButtons, {
                  "custom-btns": localConfig.value.customBtns,
                  localConfig: localConfig.value,
                  readonly: __props.readonly,
                  isSubTable: __props.titleMode == "label",
                  onClick: handleCustomBtnClick,
                  hiddenFormData: hiddenFormData.value
                }, null, 8, ["custom-btns", "localConfig", "readonly", "isSubTable", "hiddenFormData"])
              ], 64)) : createCommentVNode("", true),
              ((_d = (_c = localConfig.value) == null ? void 0 : _c.queryConfig) == null ? void 0 : _d.mode) == "dynamic" ? (openBlock(), createBlock(DynamicQuery, {
                key: 1,
                readonly: __props.readonly,
                isSubTable: __props.titleMode == "label",
                localConfig: localConfig.value,
                "fields-data": fieldsData.value,
                isCache: !__props.isSubTable && !__props.isDialog,
                onSearch: handleFilterSearch,
                onClick: handleCustomBtnClick,
                hiddenFormData: hiddenFormData.value
              }, null, 8, ["readonly", "isSubTable", "localConfig", "fields-data", "isCache", "hiddenFormData"])) : createCommentVNode("", true),
              createElementVNode("div", _hoisted_1, [
                createVNode(unref(VxeTable), {
                  ref_key: "tableRef",
                  ref: tableRef,
                  "show-header": "",
                  data: displayData.value,
                  "auto-resize": autoResize.value,
                  height: tableHeight.value,
                  maxHeight: tableMaxHeight.value,
                  "empty-text": "暂无数据",
                  "export-config": unref(exportConfig),
                  "row-config": rowConfig.value,
                  "radio-config": radioConfig.value,
                  "checkbox-config": checkboxConfig.value,
                  "sort-config": unref(sortConfig),
                  "show-footer": summaryConfig.value.enabled,
                  "footer-data": footerData.value,
                  onSortChange: handleSortChange,
                  onCheckboxChange: handleCheckboxChange,
                  onCheckboxAll: handleCheckboxAll,
                  onRadioChange: handleRadioChange,
                  onInitRendered: handleInitRendered,
                  onDataRendered: handleDataRendered
                }, {
                  default: withCtx(() => {
                    var _a2;
                    return [
                      createVNode(TableColumn, {
                        "fields-data": fieldsData.value,
                        "show-index": localConfig.value.showIndex,
                        "select-mode": __props.selectMode || localConfig.value.selectMode,
                        "is-opt-btns": localConfig.value.isOptBtns,
                        "opt-btns": localConfig.value.optBtns,
                        "mode-key": currentMode.value,
                        modes: localConfig.value.mode,
                        "data-source-options": dataSourceOptions.value,
                        "dictionary-options": dictionaryOptions.value,
                        localConfig: localConfig.value,
                        "table-ref": (_a2 = unref(instance)) == null ? void 0 : _a2.proxy,
                        "table-data": displayData.value,
                        readonly: __props.readonly,
                        isDialog: __props.isDialog,
                        hiddenFormData: hiddenFormData.value,
                        btnRollbackEvent: __props.btnRollbackEvent
                      }, createSlots({ _: 2 }, [
                        renderList(fieldsData.value, (field) => {
                          return {
                            name: `cell-${field.fieldName}`,
                            fn: withCtx((scope) => [
                              renderSlot(_ctx.$slots, `cell-${field.fieldName}`, normalizeProps(guardReactiveProps(scope)), void 0, true)
                            ])
                          };
                        })
                      ]), 1032, ["fields-data", "show-index", "select-mode", "is-opt-btns", "opt-btns", "mode-key", "modes", "data-source-options", "dictionary-options", "localConfig", "table-ref", "table-data", "readonly", "isDialog", "hiddenFormData", "btnRollbackEvent"])
                    ];
                  }),
                  _: 3
                }, 8, ["data", "auto-resize", "height", "maxHeight", "export-config", "row-config", "radio-config", "checkbox-config", "sort-config", "show-footer", "footer-data"])
              ]),
              isPagination.value && displayData.value.length > 0 ? (openBlock(), createBlock(Pagination, {
                key: 2,
                config: localConfig.value.paginationConfig,
                pagination: displayPagination.value,
                onChange: handlePageChange
              }, null, 8, ["config", "pagination"])) : createCommentVNode("", true)
            ], 512)) : createCommentVNode("", true)
          ];
        }),
        _: 3
      }, 8, ["class", "data-id", "data-name", "data-pkId"]);
    };
  }
});
const _Table = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-cf0b025d"]]);
export {
  _Table as default
};
