<template>
  <div class="gl-page-content-full">
    <div class="table">
      <BaseTable
        ref="baseTableRef"
        tableName="SYSTEM_DICTIONARY"
        :api="getDictionaryClassApi"
        :actionList="actionList"
        fullHeight
      >
        <template #leftOptions>
          <el-button type="primary" :icon="Plus" @click="openDetailFun({})">新增字典类型</el-button>
        </template>
      </BaseTable>
    </div>
    <ClassDetailDrawer
      v-model="detailVisible"
      :data="detailData"
      tableName="SYSTEM_DICTIONARY"
      @submit="submitFun"
    />
    <DictListDrawer v-model="listVisible" :data="detailData" />
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { Plus } from '@element-plus/icons-vue';
import { ElMessage } from 'element-plus';
import BaseTable from '@/components/common/table/baseTable.vue';
import ClassDetailDrawer from './components/classDetail.vue';
import DictListDrawer from './components/dictList.vue';
import { getDictionaryClassApi, deleteDictionaryClassApi } from '@/api/system/systemData';
import { getAllDictDataFun } from '@/utils/common';

const detailVisible = ref(false);
const listVisible = ref(false);
const detailData = ref<any>({});
const baseTableRef = ref<any>();

const actionList = ref([
  {
    title: '编辑',
    type: 'primary',
    click: (row: any) => {
      openDetailFun(row);
    },
  },
  {
    title: '字典列表',
    type: 'primary',
    click: (row: any) => {
      openListFun(row);
    },
  },
  {
    title: '删除',
    type: 'danger',
    needConfirm: true,
    confirmTip: '确定删除字典类型吗？',
    click: (row: any) => {
      delFun(row);
    },
  },
]);

const openDetailFun = (data: any) => {
  detailData.value = data;
  detailVisible.value = true;
};

const openListFun = (data: any) => {
  detailData.value = data;
  listVisible.value = true;
};

const submitFun = () => {
  baseTableRef.value.resetFun();
};

const delFun = (data: any) => {
  const params = {
    uuid: data.uuid,
  };
  deleteDictionaryClassApi(params).then((res: any) => {
    if (res.code === 200) {
      baseTableRef.value.resetFun();
      ElMessage.success('操作成功');
      getAllDictDataFun(true);
    }
  });
};
</script>

<style lang="scss" scoped>
.gl-page-content-full {
  .table {
    height: 100%;
  }
}
</style>
