<!-- 变量信息 -->
<template>
  <div class="app-container">
    <!-- 搜索区域 -->
    <div v-show="visible" class="search-container">
      <el-form
        ref="queryFormRef"
        :model="queryFormData"
        label-suffix=":"
        :inline="true"
        @submit.prevent="handleQuery"
      >
        <el-form-item label="行车" prop="crane_no">
          <CraneTableSelect
            v-model="queryFormData.crane_no"
            @confirm-click="handleConfirm"
            @clear-click="handleQuery"
          />
        </el-form-item>
        <el-form-item label="变量code" prop="var_code">
          <el-input v-model="queryFormData.var_code" placeholder="请输入变量code" clearable />
        </el-form-item>
        <el-form-item label="变量名称" prop="var_name">
          <el-input v-model="queryFormData.var_name" placeholder="请输入变量名称" clearable />
        </el-form-item>
        <el-form-item label="所属机构" prop="mec_type">
          <el-select v-model="queryFormData.mec_type" placeholder="请选择所属机构" style="width: 180px" clearable>
            <el-option v-for="dict in dictStore.getDictArray('mec_type')" :key="dict.dict_value" :label="dict.dict_label" :value="dict.dict_value" />
          </el-select>
        </el-form-item>
        <el-form-item label="变量类型" prop="switch_type">
          <el-select v-model="queryFormData.switch_type" placeholder="请选择变量类型" style="width: 180px" clearable>
            <el-option v-for="dict in dictStore.getDictArray('switch_type')" :key="dict.dict_value" :label="dict.dict_label" :value="dict.dict_value" />
          </el-select>
        </el-form-item>
        <el-form-item label="网关" prop="gateway_id">
          <GatewayTableSelect
            v-model="queryFormData.gateway_id"
            @confirm-click="handleConfirm"
            @clear-click="handleQuery"
          />
        </el-form-item>
        <el-form-item label="变量分组" prop="var_group">
          <el-select v-model="queryFormData.var_group" placeholder="请选择变量分组" style="width: 180px" clearable>
            <el-option v-for="dict in dictStore.getDictArray('var_group')" :key="dict.dict_value" :label="dict.dict_label" :value="dict.dict_value" />
          </el-select>
        </el-form-item>
        <el-form-item label="变量分类" prop="var_category">
          <el-select v-model="queryFormData.var_category" placeholder="请选择变量分类" style="width: 180px" clearable>
            <el-option v-for="dict in dictStore.getDictArray('var_category')" :key="dict.dict_value" :label="dict.dict_label" :value="dict.dict_value" />
          </el-select>
        </el-form-item>
        <el-form-item label="是否重点显示" prop="is_top_show">
          <el-select v-model="queryFormData.is_top_show" placeholder="请选择是否重点显示" style="width: 180px" clearable>
            <el-option v-for="dict in dictStore.getDictArray('sys_yes_no')" :key="dict.dict_value" :label="dict.dict_label" :value="dict.dict_value" />
          </el-select>
        </el-form-item>
        <el-form-item label="是否生成" prop="is_save">
          <el-select v-model="queryFormData.is_save" placeholder="请选择是否生成" style="width: 180px" clearable>
            <el-option v-for="dict in dictStore.getDictArray('sys_yes_no')" :key="dict.dict_value" :label="dict.dict_label" :value="dict.dict_value" />
          </el-select>
        </el-form-item>
        <el-form-item label="是否首页重点显示" prop="is_overview_top_show">
          <el-select v-model="queryFormData.is_overview_top_show" placeholder="请选择是否首页重点显示" style="width: 180px" clearable>
            <el-option v-for="dict in dictStore.getDictArray('sys_yes_no')" :key="dict.dict_value" :label="dict.dict_label" :value="dict.dict_value" />
          </el-select>
        </el-form-item>
        <el-form-item label="是否首页显示" prop="is_home_page_show">
          <el-select v-model="queryFormData.is_home_page_show" placeholder="请选择是否首页显示" style="width: 180px" clearable>
            <el-option v-for="dict in dictStore.getDictArray('sys_yes_no')" :key="dict.dict_value" :label="dict.dict_label" :value="dict.dict_value" />
          </el-select>
        </el-form-item>
        <el-form-item prop="status" label="状态">
          <el-select
            v-model="queryFormData.status"
            placeholder="请选择状态"
            style="width: 170px"
            clearable
          >
            <el-option value="1" label="启用" />
            <el-option value="0" label="停用" />
          </el-select>
        </el-form-item>
        <el-form-item v-if="isExpand" prop="created_time" label="创建时间">
          <DatePicker v-model="createdDateRange" @update:model-value="handleCreatedDateRangeChange" />
        </el-form-item>
        <el-form-item v-if="isExpand" prop="updated_time" label="更新时间">
          <DatePicker v-model="updatedDateRange" @update:model-value="handleUpdatedDateRangeChange" />
        </el-form-item>
        <el-form-item v-if="isExpand" prop="created_id" label="创建人">
          <UserTableSelect
            v-model="queryFormData.created_id"
            @confirm-click="handleConfirm"
            @clear-click="handleQuery"
          />
        </el-form-item>
        <el-form-item v-if="isExpand" prop="updated_id" label="更新人">
          <UserTableSelect
            v-model="queryFormData.updated_id"
            @confirm-click="handleConfirm"
            @clear-click="handleQuery"
          />
        </el-form-item>
        <!-- 查询、重置、展开/收起按钮 -->
        <el-form-item>
          <el-button
            v-hasPerm="['module_business:vardict:query']"
            type="primary"
            icon="search"
            @click="handleQuery"
          >
            查询
          </el-button>
          <el-button
            v-hasPerm="['module_business:vardict:query']"
            icon="refresh"
            @click="handleResetQuery"
          >
            重置
          </el-button>
          <!-- 展开/收起 -->
          <template v-if="isExpandable">
            <el-link class="ml-3" type="primary" underline="never" @click="isExpand = !isExpand">
              {{ isExpand ? "收起" : "展开" }}
              <el-icon>
                <template v-if="isExpand">
                  <ArrowUp />
                </template>
                <template v-else>
                  <ArrowDown />
                </template>
              </el-icon>
            </el-link>
          </template>
        </el-form-item>
      </el-form>
    </div>

    <!-- 内容区域 -->
    <el-card class="data-table">
      <template #header>
        <div class="card-header">
          <span>
            变量信息列表
            <el-tooltip content="变量信息列表">
              <QuestionFilled class="w-4 h-4 mx-1" />
            </el-tooltip>
          </span>
        </div>
      </template>

      <!-- 功能区域 -->
      <div class="data-table__toolbar">
        <div class="data-table__toolbar--left">
          <el-row :gutter="10">
            <el-col :span="1.5">
              <el-button
                v-hasPerm="['module_business:vardict:create']"
                type="success"
                icon="plus"
                @click="handleOpenDialog('create')"
              >
                新增
              </el-button>
            </el-col>
            <el-col :span="1.5">
              <el-button
                v-hasPerm="['module_business:vardict:delete']"
                type="danger"
                icon="delete"
                :disabled="selectIds.length === 0"
                @click="handleDelete(selectIds)"
              >
                批量删除
              </el-button>
            </el-col>
            <el-col :span="1.5">
              <el-dropdown v-hasPerm="['module_business:vardict:batch']" trigger="click">
                <el-button type="default" :disabled="selectIds.length === 0" icon="ArrowDown">
                  更多
                </el-button>
                <template #dropdown>
                  <el-dropdown-menu>
                    <el-dropdown-item :icon="Check" @click="handleMoreClick('1')">
                      批量启用
                    </el-dropdown-item>
                    <el-dropdown-item :icon="CircleClose" @click="handleMoreClick('0')">
                      批量停用
                    </el-dropdown-item>
                  </el-dropdown-menu>
                </template>
              </el-dropdown>
            </el-col>
          </el-row>
        </div>
        <div class="data-table__toolbar--right">
          <el-row :gutter="10">
            <!-- <el-col :span="1.5">
              <el-tooltip content="导入">
                <el-button
                  v-hasPerm="['module_business:vardict:import']"
                  type="success"
                  icon="upload"
                  circle
                  @click="handleOpenImportDialog"
                />
              </el-tooltip>
            </el-col> -->
            <el-col :span="1.5">
              <el-tooltip content="导出">
                <el-button
                  v-hasPerm="['module_business:vardict:export']"
                  type="warning"
                  icon="download"
                  circle
                  @click="handleOpenExportsModal"
                />
              </el-tooltip>
            </el-col>
            <el-col :span="1.5">
              <el-tooltip content="搜索显示/隐藏">
                <el-button
                  v-hasPerm="['*:*:*']"
                  type="info"
                  icon="search"
                  circle
                  @click="visible = !visible"
                />
              </el-tooltip>
            </el-col>
            <el-col :span="1.5">
              <el-tooltip content="刷新">
                <el-button
                  v-hasPerm="['module_business:vardict:query']"
                  type="primary"
                  icon="refresh"
                  circle
                  @click="handleRefresh"
                />
              </el-tooltip>
            </el-col>
            <el-col :span="1.5">
              <el-popover placement="bottom" trigger="click">
                <template #reference>
                  <el-button type="danger" icon="operation" circle></el-button>
                </template>
                <el-scrollbar max-height="350px">
                  <template v-for="column in tableColumns" :key="column.prop">
                    <el-checkbox v-if="column.prop" v-model="column.show" :label="column.label" />
                  </template>
                </el-scrollbar>
              </el-popover>
            </el-col>
          </el-row>
        </div>
      </div>

      <!-- 表格区域：系统配置列表 -->
      <el-table
        ref="tableRef"
        v-loading="loading"
        :data="pageTableData"
        highlight-current-row
        class="data-table__content"
        :height="450"
        border
        stripe
        @selection-change="handleSelectionChange"
      >
        <template #empty>
          <el-empty :image-size="80" description="暂无数据" />
        </template>
        <el-table-column
          v-if="tableColumns.find((col) => col.prop === 'selection')?.show"
          type="selection"
          min-width="55"
          align="center"
        />
        <el-table-column
          v-if="tableColumns.find((col) => col.prop === 'index')?.show"
          fixed
          label="序号"
          min-width="60"
        >
          <template #default="scope">
            {{ (queryFormData.page_no - 1) * queryFormData.page_size + scope.$index + 1 }}
          </template>
        </el-table-column>
        <el-table-column v-if="tableColumns.find((col) => col.prop === 'crane_name')?.show" label="行车" prop="crane_name" min-width="140">
        </el-table-column>
        <el-table-column v-if="tableColumns.find((col) => col.prop === 'var_code')?.show" label="变量code" prop="var_code" min-width="120">
        </el-table-column>
        <el-table-column v-if="tableColumns.find((col) => col.prop === 'var_name')?.show" label="变量名称" prop="var_name" min-width="120">
        </el-table-column>
        <el-table-column v-if="tableColumns.find((col) => col.prop === 'mec_type')?.show" 
          label="所属机构" 
          prop="mec_type" 
          min-width="100">
          <template #default="scope">
            {{
                (scope.row.mec_type
                  ? (dictStore.getDictLabel("mec_type", scope.row.mec_type) as any)
                  : undefined
                )?.dict_label || scope.row.mec_type
            }}
          </template>
        </el-table-column>
        <el-table-column v-if="tableColumns.find((col) => col.prop === 'data_type')?.show" 
          label="数据类型" 
          prop="data_type" 
          min-width="100">
          <template #default="scope">
            {{
                (scope.row.data_type
                  ? (dictStore.getDictLabel("data_type", scope.row.data_type) as any)
                  : undefined
                )?.dict_label || scope.row.data_type
            }}
          </template>
        </el-table-column>
        <el-table-column v-if="tableColumns.find((col) => col.prop === 'addr')?.show" label="数据地址" prop="addr" min-width="140">
        </el-table-column>
        <el-table-column v-if="tableColumns.find((col) => col.prop === 'switch_type')?.show" 
          label="变量类型" 
          prop="switch_type" 
          min-width="100">
          <template #default="scope">
            {{
                (scope.row.switch_type || scope.row.switch_type === 0
                  ? (dictStore.getDictLabel("switch_type", scope.row.switch_type) as any)
                  : undefined
                )?.dict_label || scope.row.switch_type
            }}
          </template>
        </el-table-column>
        <el-table-column v-if="tableColumns.find((col) => col.prop === 'gateway_name')?.show" label="网关" prop="gateway_name" min-width="100">
        </el-table-column>
        <el-table-column v-if="tableColumns.find((col) => col.prop === 'var_group')?.show" label="变量分组" prop="var_group" min-width="140">
          <template #default="scope">
            {{
                (scope.row.var_group
                  ? (dictStore.getDictLabel("var_group", scope.row.var_group) as any)
                  : undefined
                )?.dict_label || scope.row.var_group
            }}
          </template>
        </el-table-column>
        <el-table-column v-if="tableColumns.find((col) => col.prop === 'var_category')?.show" label="变量分类" prop="var_category" min-width="140">
          <template #default="scope">
            {{
                (scope.row.var_category
                  ? (dictStore.getDictLabel("var_category", scope.row.var_category) as any)
                  : undefined
                )?.dict_label || scope.row.var_category
            }}
          </template>
        </el-table-column>
        <el-table-column v-if="tableColumns.find((col) => col.prop === 'var_sort')?.show" label="排序" prop="var_sort" min-width="80">
        </el-table-column>
        <el-table-column v-if="tableColumns.find((col) => col.prop === 'translate')?.show" label="绑定公式" prop="translate" min-width="140">
          <template #default="scope">
            {{
                (scope.row.translate
                  ? (dictStore.getDictLabel("translate", scope.row.translate) as any)
                  : undefined
                )?.dict_label || scope.row.translate
            }}
          </template>
        </el-table-column>
        <el-table-column v-if="tableColumns.find((col) => col.prop === 'device_no')?.show" label="关联设备编号 " prop="device_no" min-width="140">
        </el-table-column>
        <el-table-column v-if="tableColumns.find((col) => col.prop === 'is_reverse')?.show" label="是否取反" prop="is_reverse" min-width="140">
          <template #default="scope">
            <el-tag :type="scope.row.is_reverse == '1' ? 'success' : 'info'">
              {{ scope.row.is_reverse === 1 ? "是" : "否" }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column v-if="tableColumns.find((col) => col.prop === 'is_top_show')?.show" label="是否重点显示" prop="is_top_show" min-width="140">
          <template #default="scope">
            <el-tag :type="scope.row.is_top_show == '1' ? 'success' : 'info'">
              {{ scope.row.is_top_show === 1 ? "是" : "否" }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column v-if="tableColumns.find((col) => col.prop === 'is_save')?.show" label="是否生成" prop="is_save" min-width="140">
          <template #default="scope">
            <el-tag :type="scope.row.is_save == '1' ? 'success' : 'info'">
              {{ scope.row.is_save === 1 ? "是" : "否" }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column v-if="tableColumns.find((col) => col.prop === 'is_calibration')?.show" label="是否标定" prop="is_calibration" min-width="140">
          <template #default="scope">
            <el-tag :type="scope.row.is_calibration == '1' ? 'success' : 'info'">
              {{ scope.row.is_calibration === 1 ? "是" : "否" }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column v-if="tableColumns.find((col) => col.prop === 'is_overview_top_show')?.show" label="是否首页重点显示" prop="is_overview_top_show" min-width="140">
          <template #default="scope">
            <el-tag :type="scope.row.is_overview_top_show == '1' ? 'success' : 'info'">
              {{ scope.row.is_overview_top_show === 1 ? "是" : "否" }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column v-if="tableColumns.find((col) => col.prop === 'is_home_page_show')?.show" label="是否首页显示" prop="is_home_page_show" min-width="140">
          <template #default="scope">
            <el-tag :type="scope.row.is_home_page_show == '1' ? 'success' : 'info'">
              {{ scope.row.is_home_page_show === 1 ? "是" : "否" }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column v-if="tableColumns.find((col) => col.prop === 'is_diagnose')?.show" label="是否启用诊断专家" prop="is_diagnose" min-width="140">
          <template #default="scope">
            <el-tag :type="scope.row.is_diagnose == '1' ? 'success' : 'info'">
              {{ scope.row.is_diagnose === 1 ? "是" : "否" }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column v-if="tableColumns.find((col) => col.prop === 'is_upload')?.show" label="是否上传云平台" prop="is_upload" min-width="140">
          <template #default="scope">
            <el-tag :type="scope.row.is_upload == '1' ? 'success' : 'info'">
              {{ scope.row.is_upload === 1 ? "是" : "否" }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column v-if="tableColumns.find((col) => col.prop === 'diagnosis_id')?.show" label="关联诊断专家" prop="diagnosis_id" min-width="140">
        </el-table-column>
        <el-table-column v-if="tableColumns.find((col) => col.prop === 'status')?.show" label="是否启用" prop="status" min-width="140">
          <template #default="scope">
            <el-tag :type="scope.row.status == '1' ? 'success' : 'info'">
              {{ scope.row.status == '1' ? '启用' : '停用' }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column v-if="tableColumns.find((col) => col.prop === 'description')?.show" label="备注/描述" prop="description" min-width="140">
        </el-table-column>
        <el-table-column v-if="tableColumns.find((col) => col.prop === 'created_time')?.show" label="创建时间 " prop="created_time" min-width="200">
        </el-table-column>
        <el-table-column v-if="tableColumns.find((col) => col.prop === 'updated_time')?.show" label="更新时间" prop="updated_time" min-width="200">
        </el-table-column>
        <el-table-column v-if="tableColumns.find((col) => col.prop === 'created_id')?.show" label="创建人ID" prop="created_id" min-width="140">
          <template #default="scope">
            <el-tag>{{ scope.row.created_by?.name }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column v-if="tableColumns.find((col) => col.prop === 'updated_id')?.show" label="更新人ID" prop="updated_id" min-width="140">
          <template #default="scope">
            <el-tag>{{ scope.row.updated_by?.name }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column
          v-if="tableColumns.find((col) => col.prop === 'operation')?.show"
          fixed="right"
          label="操作"
          align="center"
          min-width="200"
        >
          <template #default="scope">
            <el-button
              v-hasPerm="['module_business:vardict:detail']"
              type="info"
              size="small"
              link
              icon="document"
              @click="handleOpenDialog('detail', scope.row.id)"
            >
              详情
            </el-button>
            <el-button
              v-hasPerm="['module_business:vardict:update']"
              type="primary"
              size="small"
              link
              icon="edit"
              @click="handleOpenDialog('update', scope.row.id)"
            >
              编辑
            </el-button>
            <el-button
              v-hasPerm="['module_business:vardict:delete']"
              type="danger"
              size="small"
              link
              icon="delete"
              @click="handleDelete([scope.row.id])"
            >
              删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页区域 -->
      <template #footer>
        <pagination
          v-model:total="total"
          v-model:page="queryFormData.page_no"
          v-model:limit="queryFormData.page_size"
          @pagination="loadingData"
        />
      </template>
    </el-card>

    <!-- 弹窗区域 -->
    <el-dialog
      v-model="dialogVisible.visible"
      :title="dialogVisible.title"
      @close="handleCloseDialog"
    >
      <!-- 详情 -->
      <template v-if="dialogVisible.type === 'detail'">
        <el-descriptions :column="4" border>
            <el-descriptions-item label="行车" :span="2">
              {{ detailFormData.crane_name }}
            </el-descriptions-item>
            <el-descriptions-item label="变量code" :span="2">
              {{ detailFormData.var_code }}
            </el-descriptions-item>
            <el-descriptions-item label="变量名称" :span="2">
              {{ detailFormData.var_name }}
            </el-descriptions-item>
            <el-descriptions-item label="所属机构" :span="2">
              {{ (detailFormData.mec_type 
                  ? (dictStore.getDictLabel("mec_type", detailFormData.mec_type) as any)
                  : undefined
                )?.dict_label || detailFormData.mec_type }}
            </el-descriptions-item>
            <el-descriptions-item label="数据类型" :span="2">
              {{ (detailFormData.data_type 
                  ? (dictStore.getDictLabel("data_type", detailFormData.data_type) as any)
                  : undefined
                )?.dict_label || detailFormData.data_type }}
            </el-descriptions-item>
            <el-descriptions-item label="数据地址" :span="2">
              {{ detailFormData.addr }}
            </el-descriptions-item>
            <el-descriptions-item label="变量类型" :span="2">
              {{ (detailFormData.switch_type 
                  ? (dictStore.getDictLabel("switch_type", detailFormData.switch_type) as any)
                  : undefined
                )?.dict_label || detailFormData.switch_type }}
            </el-descriptions-item>
            
            <el-descriptions-item label="网关" :span="2"> 
              {{ detailFormData.gateway_name }}
            </el-descriptions-item>
            <el-descriptions-item label="排序" :span="2">
              {{ detailFormData.var_sort }}
            </el-descriptions-item>
            <el-descriptions-item label="变量分组" :span="2">
              {{ (detailFormData.var_group 
                  ? (dictStore.getDictLabel("var_group", detailFormData.var_group) as any)
                  : undefined
                )?.dict_label || detailFormData.var_group }}
            </el-descriptions-item>
            <el-descriptions-item label="变量分类" :span="2">
              {{ (detailFormData.var_category 
                  ? (dictStore.getDictLabel("var_category", detailFormData.var_category) as any)
                  : undefined
                )?.dict_label || detailFormData.var_category }}
            </el-descriptions-item>
            <el-descriptions-item label="绑定公式" :span="2">
              {{ (detailFormData.translate 
                  ? (dictStore.getDictLabel("translate", detailFormData.translate) as any)
                  : undefined
                )?.dict_label || detailFormData.translate }}
            </el-descriptions-item>
            <el-descriptions-item label="关联设备编号 " :span="2">
              {{ detailFormData.device_no }}
            </el-descriptions-item>
            <el-descriptions-item label="是否取反" :span="2">
              <el-tag :type="detailFormData.is_reverse == '1' ? 'success' : 'danger'">
                {{ detailFormData.is_reverse == '1' ? "是" : "否" }}
              </el-tag>
            </el-descriptions-item>
            <el-descriptions-item label="是否重点显示" :span="2">
              <el-tag :type="detailFormData.is_top_show == '1' ? 'success' : 'danger'">
                {{ detailFormData.is_top_show == '1' ? "是" : "否" }}
              </el-tag>
            </el-descriptions-item>
            <el-descriptions-item label="是否生成" :span="2">
              <el-tag :type="detailFormData.is_save == '1' ? 'success' : 'danger'">
                {{ detailFormData.is_save == '1' ? "是" : "否" }}
              </el-tag>
            </el-descriptions-item>
            <el-descriptions-item label="是否标定" :span="2">
              <el-tag :type="detailFormData.is_calibration == '1' ? 'success' : 'danger'">
                {{ detailFormData.is_calibration == '1' ? "是" : "否" }}
              </el-tag>
            </el-descriptions-item>
            <el-descriptions-item label="是否首页重点显示" :span="2">
              <el-tag :type="detailFormData.is_overview_top_show == '1' ? 'success' : 'danger'">
                {{ detailFormData.is_overview_top_show == '1' ? "是" : "否" }}
              </el-tag>
            </el-descriptions-item>
            <el-descriptions-item label="是否首页显示" :span="2">
              <el-tag :type="detailFormData.is_home_page_show == '1' ? 'success' : 'danger'">
                {{ detailFormData.is_home_page_show == '1' ? "是" : "否" }}
              </el-tag>
            </el-descriptions-item>
            <el-descriptions-item label="是否启用诊断专家" :span="2">
              <el-tag :type="detailFormData.is_diagnose == '1' ? 'success' : 'danger'">
                {{ detailFormData.is_diagnose == '1' ? "是" : "否" }}
              </el-tag>
            </el-descriptions-item>
            <el-descriptions-item label="是否上传云平台" :span="2">
              <el-tag :type="detailFormData.is_upload == '1' ? 'success' : 'danger'">
                {{ detailFormData.is_upload == '1' ? "是" : "否" }}
              </el-tag>
            </el-descriptions-item>
            <el-descriptions-item label="关联诊断专家" :span="2">
              {{ detailFormData.diagnosis_id }}
            </el-descriptions-item>
            <el-descriptions-item label="状态" :span="2">
              <el-tag :type="detailFormData.status == '1' ? 'success' : 'danger'">
                {{ detailFormData.status == '1' ? "启用" : "停用" }}
              </el-tag>
            </el-descriptions-item>
            <el-descriptions-item label="备注/描述" :span="2">
              {{ detailFormData.description }}
            </el-descriptions-item>
            <el-descriptions-item label="创建时间 " :span="2">
              {{ detailFormData.created_time }}
            </el-descriptions-item>
            <el-descriptions-item label="更新时间" :span="2">
              {{ detailFormData.updated_time }}
            </el-descriptions-item>
            <el-descriptions-item label="创建人" :span="2">
              {{ detailFormData.created_by?.name }}
            </el-descriptions-item>
            <el-descriptions-item label="更新人" :span="2">
              {{ detailFormData.updated_by?.name }}
            </el-descriptions-item>
        </el-descriptions>
      </template>

      <!-- 新增、编辑表单 -->
      <template v-else>
        <el-form ref="dataFormRef" :model="formData" :rules="rules" label-suffix=":" label-width="auto" label-position="right">
          <el-form-item label="行车" prop="crane_no" :required="true">
            <CraneTableSelect
                v-model="formData.crane_no"
                @confirm-click="handleConfirm"
                @clear-click="handleQuery"
              />
          </el-form-item>
          <el-form-item label="网关" prop="gateway_id" :required="true">
            <GatewayTableSelect
                v-model="formData.gateway_id"
                @confirm-click="handleConfirm"
                @clear-click="handleQuery"
              />
          </el-form-item>
          <el-form-item label="变量code" prop="var_code" :required="true">
            <el-input v-model="formData.var_code" placeholder="请输入变量code" />
          </el-form-item>
          <el-form-item label="变量名称" prop="var_name" :required="true">
            <el-input v-model="formData.var_name" placeholder="请输入变量名称" />
          </el-form-item>
          <el-form-item label="所属机构" prop="mec_type" :required="true" class="w-100">
            <el-select v-model="formData.mec_type" placeholder="请选择所属机构">
              <el-option v-for="dict in dictStore.getDictArray('mec_type')" :key="dict.dict_value" :label="dict.dict_label" :value="dict.dict_value" />
            </el-select>
          </el-form-item>
          <el-form-item label="数据类型" prop="data_type" :required="true" class="w-100">
            <el-select v-model="formData.data_type" placeholder="请选择数据类型">
              <el-option v-for="dict in dictStore.getDictArray('data_type')" :key="dict.dict_value" :label="dict.dict_label" :value="dict.dict_value" />
            </el-select>
          </el-form-item>
          <el-form-item label="数据地址" prop="addr" :required="true">
            <el-input v-model="formData.addr" placeholder="请输入数据地址" />
          </el-form-item>
          <el-form-item label="变量类型" prop="switch_type" :required="true"  class="w-100">
            <el-select v-model="formData.switch_type" placeholder="请选择变量类型">
              <el-option v-for="dict in dictStore.getDictArray('switch_type')" :key="dict.dict_value" :label="dict.dict_label" :value="dict.dict_value" />
            </el-select>
          </el-form-item>
 

          <el-form-item label="变量分组" prop="var_group" :required="false" class="w-100">
            <el-select v-model="formData.var_group" placeholder="请选择变量分组">
              <el-option v-for="dict in dictStore.getDictArray('var_group')" :key="dict.dict_value" :label="dict.dict_label" :value="dict.dict_value" />
            </el-select>
          </el-form-item>
          <el-form-item label="变量分类" prop="var_category" :required="true" class="w-100">
            <el-select v-model="formData.var_category" placeholder="请选择变量分类">
              <el-option v-for="dict in dictStore.getDictArray('var_category')" :key="dict.dict_value" :label="dict.dict_label" :value="dict.dict_value" />
            </el-select>
          </el-form-item>
          <el-form-item label="是否取反" prop="is_reverse" :required="true">
            <el-radio-group v-model="formData.is_reverse">
              <el-radio :value="1">是</el-radio>
              <el-radio :value="0">否</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="是否生成" prop="is_save" :required="false">
            <el-radio-group v-model="formData.is_save">
              <el-radio :value="1">是</el-radio>
              <el-radio :value="0">否</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="是否重点显示" prop="is_top_show" :required="false">
            <el-radio-group v-model="formData.is_top_show">
              <el-radio :value="1">是</el-radio>
              <el-radio :value="0">否</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="是否首页重点显示" prop="is_overview_top_show" :required="false">
            <el-radio-group v-model="formData.is_overview_top_show">
              <el-radio :value="1">是</el-radio>
              <el-radio :value="0">否</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="是否首页显示" prop="is_home_page_show" :required="false">
            <el-radio-group v-model="formData.is_home_page_show">
              <el-radio :value="1">是</el-radio>
              <el-radio :value="0">否</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="是否标定" prop="is_calibration" :required="false">
            <el-radio-group v-model="formData.is_calibration">
              <el-radio :value="1">是</el-radio>
              <el-radio :value="0">否</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="排序" prop="var_sort" :required="true">
            <el-input v-model="formData.var_sort" placeholder="请输入排序" />
          </el-form-item>

          <el-form-item label="是否上传云平台" prop="is_upload" :required="true">
            <el-radio-group v-model="formData.is_upload">
              <el-radio :value="1">是</el-radio>
              <el-radio :value="0">否</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="绑定公式" prop="translate" :required="false" class="w-100">
            <el-select v-model="formData.translate" placeholder="请选择绑定公式">
              <el-option v-for="dict in dictStore.getDictArray('translate')" :key="dict.dict_value" :label="dict.dict_label" :value="dict.dict_value" />
            </el-select>
          </el-form-item>
          <el-form-item label="是否启用诊断专家" prop="is_diagnose" :required="false">
            <el-radio-group v-model="formData.is_diagnose">
              <el-radio :value="1">是</el-radio>
              <el-radio :value="0">否</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="关联设备编号 " prop="device_no" :required="false">
            <el-input v-model="formData.device_no" placeholder="请输入关联设备编号 " />
          </el-form-item>
          <el-form-item label="关联诊断专家" prop="diagnosis_id" :required="false">
            <el-input v-model="formData.diagnosis_id" placeholder="请输入关联诊断专家" />
          </el-form-item>
          <el-form-item label="状态" prop="status" :required="true">
            <el-radio-group v-model="formData.status">
              <el-radio value="1">启用</el-radio>
              <el-radio value="0">停用</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="描述" prop="description">
            <el-input
              v-model="formData.description"
              :rows="4"
              :maxlength="100"
              show-word-limit
              type="textarea"
              placeholder="请输入描述"
            />
          </el-form-item>
          <el-form-item label="创建时间 " prop="created_time" :required="false">
            <el-input v-model="formData.created_time" placeholder="请输入创建时间 " />
          </el-form-item>
        </el-form>
      </template>

      <template #footer>
        <div class="dialog-footer">
          <!-- 详情弹窗不需要确定按钮的提交逻辑 -->
          <el-button @click="handleCloseDialog">取消</el-button>
          <el-button v-if="dialogVisible.type !== 'detail'" type="primary" @click="handleSubmit">
            确定
          </el-button>
          <el-button v-else type="primary" @click="handleCloseDialog">确定</el-button>
        </div>
      </template>
    </el-dialog>

    <!-- 导入弹窗 -->
    <ImportModal
      v-model="importDialogVisible"
      :content-config="curdContentConfig"
      @upload="handleUpload"
    />

    <!-- 导出弹窗 -->
    <ExportModal
      v-model="exportsDialogVisible"
      :content-config="curdContentConfig"
      :query-params="queryFormData"
      :page-data="pageTableData"
      :selection-data="selectionRows"
    />
  </div>
</template>

<script setup lang="ts">
defineOptions({
  name: "BizVarDict",
  inheritAttrs: false,
});

import { ref, reactive, onMounted } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { QuestionFilled, ArrowUp, ArrowDown, Check, CircleClose } from '@element-plus/icons-vue'
import { formatToDateTime } from "@/utils/dateUtil";
import { useDictStore } from "@/store";
import { ResultEnum } from '@/enums/api/result.enum'
import DatePicker from "@/components/DatePicker/index.vue";
import type { IContentConfig } from "@/components/CURD/types";
import ImportModal from "@/components/CURD/ImportModal.vue";
import ExportModal from "@/components/CURD/ExportModal.vue";
import BizVarDictAPI, { BizVarDictPageQuery, BizVarDictTable, BizVarDictForm } from '@/api/module_business/vardict'

const visible = ref(true);
const isExpand = ref(false);
const isExpandable = ref(true);
const queryFormRef = ref();
const dataFormRef = ref();
const total = ref(0);
const selectIds = ref<number[]>([]);
const selectionRows = ref<BizVarDictTable[]>([]);
const loading = ref(false);

// 字典仓库与需要加载的字典类型
const dictStore = useDictStore()
const dictTypes: any = [
  'mec_type',
  'data_type',
  'switch_type',
  'var_category',
  'sys_yes_no',
  'var_group',
  'translate',
]

// 分页表单
const pageTableData = ref<BizVarDictTable[]>([]);

// 表格列配置
const tableColumns = ref([
  { prop: "selection", label: "选择框", show: true },
  { prop: "index", label: "序号", show: true },
  { prop: 'crane_no', label: '行车编号', show: true },
  { prop: 'crane_name', label: '行车名称', show: true },
  { prop: 'var_code', label: '变量code', show: true },
  { prop: 'var_name', label: '变量名称', show: true },
  { prop: 'mec_type', label: '所属机构', show: true },
  { prop: 'data_type', label: '数据类型', show: true },
  { prop: 'switch_type', label: '变量类型', show: true },
  { prop: 'addr', label: '数据地址', show: true },
  { prop: 'gateway_id', label: '网关', show: true },
  { prop: 'gateway_name', label: '网关名称', show: true },
  { prop: 'var_sort', label: '排序', show: true },
  { prop: 'var_group', label: '变量分组', show: true },
  { prop: 'var_category', label: '变量分类', show: true },
  { prop: 'translate', label: '绑定公式', show: true },
  { prop: 'device_no', label: '关联设备编号 ', show: true },
  { prop: 'is_reverse', label: '是否取反', show: true },
  { prop: 'is_top_show', label: '是否重点显示', show: true },
  { prop: 'is_save', label: '是否生成', show: true },
  { prop: 'is_calibration', label: '是否标定', show: true },
  { prop: 'is_overview_top_show', label: '是否首页重点显示', show: true },
  { prop: 'is_home_page_show', label: '是否首页显示', show: true },
  { prop: 'is_diagnose', label: '是否启用诊断专家', show: true },
  { prop: 'is_upload', label: '是否上传云平台', show: true },
  { prop: 'diagnosis_id', label: '关联诊断专家', show: true },
  { prop: 'status', label: '是否启用', show: true },
  { prop: 'description', label: '备注/描述', show: true },
  { prop: 'created_time', label: '创建时间 ', show: true },
  { prop: 'updated_time', label: '更新时间', show: true },
  { prop: 'created_id', label: '创建人ID', show: true },
  { prop: 'updated_id', label: '更新人ID', show: true },
  { prop: 'operation', label: '操作', show: true }
]);

// 导出列（不含选择/序号/操作）
const exportColumns = [
  { prop: 'crane_name', label: '行车' },
  { prop: 'var_code', label: '变量code' },
  { prop: 'var_name', label: '变量名称' },
  { prop: 'mec_type', label: '所属机构' },
  { prop: 'data_type', label: '数据类型' },
  { prop: 'switch_type', label: '变量类型' },
  { prop: 'addr', label: '数据地址' },
  { prop: 'gateway_id', label: '网关' },
  { prop: 'var_sort', label: '排序' },
  { prop: 'var_group', label: '变量分组' },
  { prop: 'var_category', label: '变量分类' },
  { prop: 'translate', label: '绑定公式' },
  { prop: 'device_no', label: '关联设备编号 ' },
  { prop: 'is_reverse', label: '是否取反' },
  { prop: 'is_top_show', label: '是否重点显示' },
  { prop: 'is_save', label: '是否生成' },
  { prop: 'is_calibration', label: '是否标定' },
  { prop: 'is_overview_top_show', label: '是否首页重点显示' },
  { prop: 'is_home_page_show', label: '是否首页显示' },
  { prop: 'is_diagnose', label: '是否启用诊断专家' },
  { prop: 'is_upload', label: '是否上传云平台' },
  { prop: 'diagnosis_id', label: '关联诊断专家' },
  { prop: 'status', label: '是否启用' },
  { prop: 'description', label: '备注/描述' },
  { prop: 'created_time', label: '创建时间 ' },
  { prop: 'updated_time', label: '更新时间' },
  { prop: 'created_id', label: '创建人ID' },
  { prop: 'updated_id', label: '更新人ID' },
]

// 导入/导出配置
const curdContentConfig = {
  permPrefix: "module_business:vardict",
  cols: exportColumns as any,
  importTemplate: () => BizVarDictAPI.downloadTemplateBizVarDict(),
  exportsAction: async (params: any) => {
    const query: any = { ...params };
    query.status = '0';
    query.page_no = 1;
    query.page_size = 9999;
    const all: any[] = [];
    while (true) {
      const res = await BizVarDictAPI.listBizVarDict(query);
      const items = res.data?.data?.items || [];
      const total = res.data?.data?.total || 0;
      all.push(...items);
      if (all.length >= total || items.length === 0) break;
      query.page_no += 1;
    }
    return all;
  },
} as unknown as IContentConfig;

// 详情表单
const detailFormData = ref<BizVarDictTable>({});
// 日期范围临时变量
const createdDateRange = ref<[Date, Date] | []>([]);
// 更新时间范围临时变量
const updatedDateRange = ref<[Date, Date] | []>([]);

// 处理创建时间范围变化
function handleCreatedDateRangeChange(range: [Date, Date]) {
  createdDateRange.value = range;
  if (range && range.length === 2) {
    queryFormData.created_time = [formatToDateTime(range[0]), formatToDateTime(range[1])];
  } else {
    queryFormData.created_time = undefined;
  }
}

// 处理更新时间范围变化
function handleUpdatedDateRangeChange(range: [Date, Date]) {
  updatedDateRange.value = range;
  if (range && range.length === 2) {
    queryFormData.updated_time = [formatToDateTime(range[0]), formatToDateTime(range[1])];
  } else {
    queryFormData.updated_time = undefined;
  }
}

// 分页查询参数
const queryFormData = reactive<BizVarDictPageQuery>({
  page_no: 1,
  page_size: 10,
  crane_no: undefined,
  var_code: undefined,
  var_name: undefined,
  mec_type: undefined,
  switch_type: undefined,
  gateway_id: undefined,
  var_group: undefined,
  var_category: undefined,
  is_top_show: undefined,
  is_save: undefined,
  is_overview_top_show: undefined,
  is_home_page_show: undefined,
  status: undefined,
  created_time: undefined,
  updated_time: undefined,
  created_id: undefined,
  updated_id: undefined,
});


// 编辑表单
const formData = reactive<BizVarDictForm>({
  id: undefined,
  crane_no: undefined,
  var_code: undefined,
  var_name: undefined,
  mec_type: undefined,
  data_type: undefined,
  switch_type: undefined,
  addr: undefined,
  gateway_id: undefined,
  var_sort: undefined,
  var_group: undefined,
  var_category: undefined,
  translate: undefined,
  device_no: undefined,
  is_reverse: '0',
  is_top_show: '0',
  is_save: "1",
  is_calibration: '0',
  is_overview_top_show: '0',
  is_home_page_show: '0',
  is_diagnose: '0',
  is_upload: '0',
  diagnosis_id: undefined,
  status: '1',
  description: undefined,
});

// 弹窗状态
const dialogVisible = reactive({
  title: "",
  visible: false,
  type: "create" as "create" | "update" | "detail",
});

// 表单验证规则
const rules = reactive({
  id: [
    { required: false, message: '请输入id ', trigger: 'blur' },
  ],
  crane_no: [
    { required: false, message: '请输入行车编号', trigger: 'blur' },
  ],
  var_code: [
    { required: false, message: '请输入变量code', trigger: 'blur' },
  ],
  var_name: [
    { required: false, message: '请输入变量名称', trigger: 'blur' },
  ],
  mec_type: [
    { required: false, message: '请输入所属机构', trigger: 'blur' },
  ],
  data_type: [
    { required: false, message: '请输入数据类型', trigger: 'blur' },
  ],
  switch_type: [
    { required: true, message: '请输入变量类型', trigger: 'blur' },
  ],
  addr: [
    { required: false, message: '请输入数据地址', trigger: 'blur' },
  ],
  gateway_id: [
    { required: false, message: '请输入网关', trigger: 'blur' },
  ],
  var_sort: [
    { required: false, message: '请输入排序', trigger: 'blur' },
  ],
  var_group: [
    { required: true, message: '请输入变量分组', trigger: 'blur' },
  ],
  var_category: [
    { required: true, message: '请输入变量分类', trigger: 'blur' },
  ],
  translate: [
    { required: true, message: '请输入绑定公式', trigger: 'blur' },
  ],
  device_no: [
    { required: true, message: '请输入关联设备编号 ', trigger: 'blur' },
  ],
  is_reverse: [
    { required: true, message: '请输入是否取反', trigger: 'blur' },
  ],
  is_top_show: [
    { required: true, message: '请输入是否重点显示', trigger: 'blur' },
  ],
  is_save: [
    { required: true, message: '请输入是否生成', trigger: 'blur' },
  ],
  is_calibration: [
    { required: true, message: '请输入是否标定', trigger: 'blur' },
  ],
  is_overview_top_show: [
    { required: true, message: '请输入是否首页重点显示', trigger: 'blur' },
  ],
  is_home_page_show: [
    { required: true, message: '请输入是否首页显示', trigger: 'blur' },
  ],
  is_diagnose: [
    { required: true, message: '请输入是否启用诊断专家', trigger: 'blur' },
  ],
  is_upload: [
    { required: true, message: '请输入是否上传云平台', trigger: 'blur' },
  ],
  diagnosis_id: [
    { required: true, message: '请输入关联诊断专家', trigger: 'blur' },
  ],
  status: [
    { required: true, message: '请输入是否启用', trigger: 'blur' },
  ],
  description: [
    { required: false, message: '请输入备注/描述', trigger: 'blur' },
  ],
  created_time: [
    { required: false, message: '请输入创建时间 ', trigger: 'blur' },
  ],
  updated_time: [
    { required: true, message: '请输入更新时间', trigger: 'blur' },
  ],
  created_id: [
    { required: false, message: '请输入创建人ID', trigger: 'blur' },
  ],
  updated_id: [
    { required: false, message: '请输入更新人ID', trigger: 'blur' },
  ],
});

// 导入弹窗显示状态
const importDialogVisible = ref(false);

// 导出弹窗显示状态
const exportsDialogVisible = ref(false);

// 打开导入弹窗
function handleOpenImportDialog() {
  importDialogVisible.value = true;
}

// 打开导出弹窗
function handleOpenExportsModal() {
  exportsDialogVisible.value = true;
}

// 列表刷新
async function handleRefresh() {
  await loadingData();
}

// 加载表格数据
async function loadingData() {
  loading.value = true;
  try {
    const response = await BizVarDictAPI.listBizVarDict(queryFormData);
    pageTableData.value = response.data.data.items;
    total.value = response.data.data.total;
  } catch (error: any) {
    console.error(error);
  } finally {
    loading.value = false;
  }
}

// 查询（重置页码后获取数据）
async function handleQuery() {
  queryFormData.page_no = 1;
  loadingData();
}

// 选择创建人后触发查询
function handleConfirm() {
  handleQuery();
}

// 重置查询
async function handleResetQuery() {
  queryFormRef.value.resetFields();
  queryFormData.page_no = 1;
  // 重置日期范围选择器
  createdDateRange.value = [];
  updatedDateRange.value = [];
  queryFormData.created_time = undefined;
  queryFormData.updated_time = undefined;
  loadingData();
}

// 定义初始表单数据常量
const initialFormData: BizVarDictForm = {
  id: undefined,
  crane_no: undefined,
  var_code: undefined,
  var_name: undefined,
  mec_type: undefined,
  data_type: undefined,
  switch_type: undefined,
  addr: undefined,
  gateway_id: undefined,
  var_sort: undefined,
  var_group: undefined,
  var_category: undefined,
  translate: undefined,
  device_no: undefined,
  is_reverse: '0',
  is_top_show: '0',
  is_save: '1',
  is_calibration: '0',
  is_overview_top_show: '0',
  is_home_page_show: '0',
  is_diagnose: '0',
  is_upload: '0',
  diagnosis_id: undefined,
  status: '1',
  description: undefined,
};

// 重置表单
async function resetForm() {
  if (dataFormRef.value) {
    dataFormRef.value.resetFields();
    dataFormRef.value.clearValidate();
  }
  // 完全重置 formData 为初始状态
  Object.assign(formData, initialFormData);
}

// 行复选框选中项变化
async function handleSelectionChange(selection: any) {
  selectIds.value = selection.map((item: any) => item.id);
  selectionRows.value = selection;
}

// 关闭弹窗
async function handleCloseDialog() {
  dialogVisible.visible = false;
  resetForm();
}

// 打开弹窗
async function handleOpenDialog(type: "create" | "update" | "detail", id?: number) {
  dialogVisible.type = type;
  if (id) {
    const response = await BizVarDictAPI.detailBizVarDict(id);
    if (type === "detail") {
      dialogVisible.title = "详情";
      Object.assign(detailFormData.value, response.data.data);
    } else if (type === "update") {
      dialogVisible.title = "修改";
      Object.assign(formData, response.data.data);
    }
  } else {
    dialogVisible.title = "新增";
    formData.id = undefined;
    formData.crane_no = undefined;
    formData.var_code = undefined;
    formData.var_name = undefined;
    formData.mec_type = undefined;
    formData.data_type = undefined;
    formData.switch_type = undefined;
    formData.addr = undefined;
    formData.gateway_id = undefined;
    formData.var_sort = undefined;
    formData.var_group = undefined;
    formData.var_category = undefined;
    formData.translate = undefined;
    formData.device_no = undefined;
    formData.is_reverse = '0';
    formData.is_top_show = '0';
    formData.is_save = '1';
    formData.is_calibration = '0';
    formData.is_overview_top_show = '0';
    formData.is_home_page_show = '0';
    formData.is_diagnose = '0';
    formData.is_upload = '0';
    formData.diagnosis_id = undefined;
    formData.status = '1';
    formData.description = undefined;
  }
  dialogVisible.visible = true;
}

// 提交表单（防抖）
async function handleSubmit() {
  // 表单校验
  dataFormRef.value.validate(async (valid: any) => {
    if (valid) {
      loading.value = true;
      // 根据弹窗传入的参数(deatil\create\update)判断走什么逻辑
      const id = formData.id;
      if (id) {
        try {
          await BizVarDictAPI.updateBizVarDict(id, { id, ...formData });
          dialogVisible.visible = false;
          resetForm();
          handleCloseDialog();
          handleResetQuery();
        } catch (error: any) {
          console.error(error);
        } finally {
          loading.value = false;
        }
      } else {
        try {
          await BizVarDictAPI.createBizVarDict(formData);
          dialogVisible.visible = false;
          resetForm();
          handleCloseDialog();
          handleResetQuery();
        } catch (error: any) {
          console.error(error);
        } finally {
          loading.value = false;
        }
      }
    }
  });
}

// 删除、批量删除
async function handleDelete(ids: number[]) {
  ElMessageBox.confirm("确认删除该项数据?", "警告", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    type: "warning",
  })
    .then(async () => {
      try {
        loading.value = true;
        await BizVarDictAPI.deleteBizVarDict(ids);
        handleResetQuery();
      } catch (error: any) {
        console.error(error);
      } finally {
        loading.value = false;
      }
    })
    .catch(() => {
      ElMessageBox.close();
    });
}

// 批量启用/停用
async function handleMoreClick(status: string) {
  if (selectIds.value.length) {
    ElMessageBox.confirm(`确认${status === "1" ? "启用" : "停用"}该项数据?`, "警告", {
      confirmButtonText: "确定",
      cancelButtonText: "取消",
      type: "warning",
    })
      .then(async () => {
        try {
          loading.value = true;
          await BizVarDictAPI.batchBizVarDict({ ids: selectIds.value, status });
          handleResetQuery();
        } catch (error: any) {
          console.error(error);
        } finally {
          loading.value = false;
        }
      })
      .catch(() => {
        ElMessageBox.close();
      });
  }
}

// 处理上传
const handleUpload = async (formData: FormData) => {
  try {
    const response = await BizVarDictAPI.importBizVarDict(formData);
    if (response.data.code === ResultEnum.SUCCESS) {
      ElMessage.success(`${response.data.msg}，${response.data.data}`);
      importDialogVisible.value = false;
      await handleQuery();
    }
  } catch (error: any) {
    console.error(error);
  }
};

onMounted(async () => {
  // 预加载字典数据
  if (dictTypes.length > 0) {
    await dictStore.getDict(dictTypes)
  }
  loadingData();
});
</script>

<style lang="scss" scoped>
</style>