<script setup lang="ts">
import { PageContainer } from 'antdv-pro-layout';
import { ProModal } from 'antdv-pro-modal';
import { message, Modal, Form } from 'ant-design-vue/es';
import { SizeType } from 'ant-design-vue/es/config-provider';
import { MenuInfo } from 'ant-design-vue/es/menu/src/interface';
import { ColumnsType } from 'ant-design-vue/es/table';
import IconFont from '@/components/IconFont/index.vue';
import { iconFonts } from '@/assets/js/icon_font_8d5l8fzk5b87iudi';
import { reactive, onMounted, toRaw } from 'vue';
import {
  addMenu,
  delMenu,
  getMenu,
  listMenu,
  updateMenu,
} from '@/api/system/menu';
import {
  parseDataToTree,
  parseDataToTreeExclude,
} from '@/utils/parse-tree-utils';
import { parseDateToStr } from '@/utils/date-utils';
import {
  MENU_PATH_INLINE,
  MENU_TYPE_DIR,
  MENU_TYPE_MENU,
  MENU_TYPE_BUTTON,
} from '@/constants/menu-constants';
import useDictStore from '@/store/modules/dict';
import { RESULT_CODE_SUCCESS } from '@/constants/result-constants';
import useI18n from '@/hooks/useI18n';
const { t } = useI18n();
const { getDict } = useDictStore();

/**字体图标可选择数据 */
let icons = reactive(
  iconFonts.map((item, i) => {
    if (i === 0) {
      return {
        value: item,
        label: item,
      };
    }
    return {
      value: item,
      label: 'icon-' + `${i}`.padStart(3, '0'),
    };
  })
);

/**字典数据 */
let dict: {
  /**菜单状态 */
  sysNormalDisable: DictType[];
} = reactive({
  sysNormalDisable: [],
});

/**查询参数 */
let queryParams = reactive({
  /**菜单名称 */
  menuName: undefined,
  /**状态 */
  status: undefined,
});

/**查询参数重置 */
function fnQueryReset() {
  queryParams = Object.assign(queryParams, {
    menuName: '',
    status: undefined,
  });
  fnGetList();
}

/**表格全展开行key */
let expandedRowKeys: string[] = [];

/**表格状态类型 */
type TabeStateType = {
  /**加载等待 */
  loading: boolean;
  /**紧凑型 */
  size: SizeType;
  /**搜索栏 */
  seached: boolean;
  /**记录数据 */
  data: object[];
  /**全展开 */
  expandedRowAll: boolean;
  /**展开行key */
  expandedRowKeys: (string | number)[];
};

/**表格状态 */
let tableState: TabeStateType = reactive({
  loading: false,
  size: 'middle',
  seached: false,
  data: [],
  expandedRowAll: false,
  expandedRowKeys: [],
});

/**表格字段列 */
let tableColumns: ColumnsType = [
  {
    title: t('views.system.menu.menuName'),
    dataIndex: 'menuName',
    align: 'left',
    width: 200,
  },
  {
    title: t('views.system.menu.menuId'),
    dataIndex: 'menuId',
    align: 'left',
    width: 120,
  },
  {
    title: t('views.system.menu.menuSort'),
    dataIndex: 'menuSort',
    align: 'left',
    width: 100,
  },
  {
    title: t('views.system.menu.menuTitle'),
    dataIndex: 'icon',
    key: 'icon',
    align: 'center',
    width: 100,
  },
  {
    title: t('views.system.menu.perId'),
    dataIndex: 'perms',
    align: 'left',
    width: 200,
  },
  {
    title: t('views.system.menu.formLoc'),
    dataIndex: 'component',
    align: 'left',
    width: 200,
  },
  {
    title: t('views.system.menu.status'),
    dataIndex: 'visible',
    key: 'visible',
    align: 'center',
    width: 120,
  },
  {
    title: t('views.system.menu.menuStatus'),
    dataIndex: 'status',
    key: 'status',
    align: 'center',
    width: 120,
  },
  {
    title: t('views.system.menu.createTime'),
    dataIndex: 'createTime',
    align: 'center',
    width: 150,
    customRender(opt) {
      if (+opt.value <= 0) return '';
      return parseDateToStr(+opt.value);
    },
  },
  {
    title: t('common.operate'),
    key: 'menuId',
    align: 'left',
  },
];

/**表格紧凑型变更操作 */
function fnTableSize({ key }: MenuInfo) {
  tableState.size = key as SizeType;
}

/**表格展开行key */
function fnTableExpandedRowsAll(checked: boolean | string | number) {
  tableState.expandedRowKeys = checked ? expandedRowKeys : [];
}

/**表格展开行key */
function fnTableExpandedRowsChange(expandedRows: (string | number)[]) {
  tableState.expandedRowKeys = expandedRows;
}

/**初始菜单原始数据 */
let menuListData: Record<string, any>[] = [];

/**初始上级菜单选择树 */
let treeDataAll: Record<string, any>[] = [];

/**
 * 获取选择上级菜单值
 * @param value 菜单选中值
 */
function fnTreeDataChange(value: any) {
  if (!value) return;
  const menu = menuListData.find(m => m.menuId === value);
  if (!menu) return;
  // 限制可选类型
  if (menu.menuType === MENU_TYPE_DIR) {
    modalState.from.menuType = MENU_TYPE_MENU;
  }
  if (menu.menuType === MENU_TYPE_MENU) {
    modalState.from.menuType = MENU_TYPE_BUTTON;
  }
  modalState.from.parentType = menu.menuType;
}

/**对话框对象信息状态类型 */
type ModalStateType = {
  /**详情框是否显示 */
  openByView: boolean;
  /**新增框或修改框是否显示 */
  openByEdit: boolean;
  /**标题 */
  title: string;
  /**表单数据 */
  from: Record<string, any>;
  /**确定按钮 loading */
  confirmLoading: boolean;
  /**上级菜单选择树 */
  treeData: Record<string, any>[];
};

/**对话框对象信息状态 */
let modalState: ModalStateType = reactive({
  openByView: false,
  openByEdit: false,
  title: '菜单',
  from: {
    menuId: undefined,
    parentId: '0',
    menuName: '',
    menuSort: 0,
    menuType: MENU_TYPE_BUTTON,
    component: '',
    path: '',
    icon: '#',
    perms: '',
    isFrame: '1',
    isCache: '0',
    visible: '0',
    status: '0',
    createTime: 0,
    remark: '',
    parentType: '', // 标记禁止菜单类型添加目录和菜单
  },
  confirmLoading: false,
  treeData: [],
});

/**对话框内表单属性和校验规则 */
const modalStateFrom = Form.useForm(
  modalState.from,
  reactive({
    parentId: [
      {
        required: true,
        message: t('views.system.menu.highMenu') + t('common.unableNull'),
      },
    ],
    menuName: [
      {
        required: true,
        min: 1,
        max: 50,
        message: t('views.system.menu.menuName') + t('common.unableNull'),
      },
    ],
    component: [
      {
        required: true,
        min: 1,
        max: 200,
        message: t('views.system.menu.formLoc') + t('common.unableNull'),
      },
    ],
    path: [
      {
        required: true,
        min: 1,
        max: 200,
        message: t('views.system.menu.routerAdrr') + t('common.unableNull'),
      },
    ],
    perms: [
      {
        required: true,
        min: 1,
        max: 100,
        message: t('views.system.menu.perId') + t('common.unableNull'),
      },
    ],
  })
);

/**
 * 对话框弹出显示为 查看
 * @param menuId 菜单编号id
 */
function fnModalVisibleByVive(menuId: string | number) {
  if (!menuId) {
    message.error(t('common.getInfoFail'), 2);
    return;
  }
  if (modalState.confirmLoading) return;
  const hide = message.loading(t('common.loading'), 0);
  modalState.confirmLoading = true;
  modalState.treeData = treeDataAll;
  getMenu(menuId).then(res => {
    modalState.confirmLoading = false;
    hide();
    if (res.code === RESULT_CODE_SUCCESS && res.data) {
      modalState.from = Object.assign(modalState.from, res.data);
      modalState.title = t('views.system.menu.menuInfo');
      modalState.openByView = true;
    } else {
      message.error(t('common.getInfoFail'), 2);
    }
  });
}

/**
 * 对话框弹出显示为 新增或者修改
 * @param menuId 菜单编号id, 不传为新增
 * @param parentId 上级菜单id
 */
function fnModalVisibleByEdit(
  menuId?: string | number,
  parentId?: string | number,
  parentType?: string | number
) {
  modalState.treeData = treeDataAll;
  if (!menuId) {
    modalStateFrom.resetFields();
    if (parentId) {
      modalState.from.parentId = parentId;
      modalState.from.parentType = parentType;
    }
    modalState.title = t('common.addText') + t('views.system.menu.menuInfo');
    modalState.openByEdit = true;
  } else {
    if (modalState.confirmLoading) return;
    const hide = message.loading(t('common.loading'), 0);
    modalState.confirmLoading = true;
    getMenu(menuId).then(res => {
      modalState.confirmLoading = false;
      hide();
      if (res.code === RESULT_CODE_SUCCESS && res.data) {
        modalState.from = Object.assign(modalState.from, res.data);
        modalState.title =
          t('common.editText') + t('views.system.menu.menuInfo');
        modalState.openByEdit = true;
      } else {
        message.error(t('common.getInfoFail'), 2);
      }
    });
  }
}

/**
 * 对话框弹出确认执行函数
 * 进行表达规则校验
 */
function fnModalOk() {
  let validateNames = ['parentId', 'menuName'];
  if (modalState.from.menuType === MENU_TYPE_DIR) {
    validateNames.push('path');
  }
  if (modalState.from.menuType === MENU_TYPE_MENU) {
    validateNames.push('component');
    validateNames.push('path');
    validateNames.push('perms');
  }
  if (modalState.from.menuType === MENU_TYPE_BUTTON) {
    validateNames.push('perms');
  }
  modalStateFrom
    .validate(validateNames)
    .then(() => {
      modalState.confirmLoading = true;
      const from = toRaw(modalState.from);
      const menu = from.menuId ? updateMenu(from) : addMenu(from);
      const key = 'menu';
      message.loading({ content: t('common.loading'), key });
      menu
        .then(res => {
          if (res.code === RESULT_CODE_SUCCESS) {
            message.success({
              content: t('common.msgSuccess', { msg: modalState.title }),
              key,
              duration: 2,
            });
            modalState.openByEdit = false;
            modalStateFrom.resetFields();
            treeDataAll = [];
            fnGetList();
          } else {
            message.error({
              content: `${res.msg}`,
              key,
              duration: 2,
            });
          }
        })
        .finally(() => {
          modalState.confirmLoading = false;
        });
    })
    .catch(e => {
      message.error(t('common.errorFields', { num: e.errorFields.length }), 2);
    });
}

/**
 * 对话框弹出关闭执行函数
 * 进行表达规则校验
 */
function fnModalCancel() {
  modalState.openByEdit = false;
  modalState.openByView = false;
  modalStateFrom.resetFields();
}

/**
 * 菜单删除
 * @param menuId 菜单编号id
 */
function fnRecordDelete(menuId: string | number) {
  Modal.confirm({
    title: t('common.tipTitle'),
    content: t('views.system.menu.delSure', { menuId }),
    onOk() {
      const key = 'delMenu';
      message.loading({ content: t('common.loading'), key });
      delMenu(menuId).then(res => {
        if (res.code === RESULT_CODE_SUCCESS) {
          message.success({
            content: t('common.msgSuccess', { msg: t('common.deleteText') }),
            key,
            duration: 2,
          });
          fnGetList();
        } else {
          message.error({
            content: `${res.msg}`,
            key: key,
            duration: 2,
          });
        }
      });
    },
  });
}

/**查询菜单列表 */
function fnGetList() {
  if (tableState.loading) return;
  tableState.loading = true;
  listMenu(toRaw(queryParams)).then(res => {
    if (res.code === RESULT_CODE_SUCCESS && Array.isArray(res.data)) {
      // 过滤旧前端菜单
      res.data = res.data.filter(i => i.perms !== 'page');
      menuListData = JSON.parse(JSON.stringify(res.data));
      // 初始上级菜单和展开编号key
      if (treeDataAll.length <= 0) {
        // 解除可变副作用
        const data: Record<string, any>[] = JSON.parse(
          JSON.stringify(res.data)
        );
        // 转换树状数据
        treeDataAll = [
          {
            menuId: '0',
            menuName: t('views.system.dept.node'),
            children: parseDataToTreeExclude(
              data,
              'menuType',
              MENU_TYPE_BUTTON,
              'menuId'
            ),
          },
        ];
        // 展开编号key
        expandedRowKeys = [...new Set(data.map(item => item.parentId))];
        fnTableExpandedRowsAll(tableState.expandedRowAll);
      }
      // 解析生成菜单树结构
      tableState.data = parseDataToTree(res.data, 'menuId');
    }
    tableState.loading = false;
  });
}

onMounted(() => {
  // 初始字典数据
  Promise.allSettled([getDict('sys_normal_disable')]).then(resArr => {
    if (resArr[0].status === 'fulfilled') {
      dict.sysNormalDisable = resArr[0].value;
    }
  });
  // 获取列表数据
  fnGetList();
});
</script>

<template>
  <PageContainer>
    <a-card
      v-show="tableState.seached"
      :bordered="false"
      :body-style="{ marginBottom: '24px', paddingBottom: 0 }"
    >
      <!-- 表格搜索栏 -->
      <a-form :model="queryParams" name="queryParams" layout="horizontal">
        <a-row :gutter="16">
          <a-col :lg="6" :md="12" :xs="24">
            <a-form-item
              :label="t('views.system.menu.menuName')"
              name="menuName"
            >
              <a-input
                v-model:value="queryParams.menuName"
                allow-clear
              ></a-input>
            </a-form-item>
          </a-col>
          <a-col :lg="6" :md="12" :xs="24">
            <a-form-item
              :label="t('views.system.menu.menuStatus')"
              name="status"
            >
              <a-select
                v-model:value="queryParams.status"
                allow-clear
                :options="dict.sysNormalDisable"
              >
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :lg="6" :md="12" :xs="24">
            <a-form-item>
              <a-space :size="8">
                <a-button type="primary" @click.prevent="fnGetList">
                  <template #icon><SearchOutlined /></template>
                  {{ t('common.search') }}
                </a-button>
                <a-button type="default" @click.prevent="fnQueryReset">
                  <template #icon><ClearOutlined /></template>
                  {{ t('common.reset') }}</a-button
                >
              </a-space>
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </a-card>

    <a-card :bordered="false" :body-style="{ padding: '0px' }">
      <!-- 插槽-卡片左侧侧 -->
      <template #title>
        <a-space :size="8" align="center">
          <a-button
            type="primary"
            @click.prevent="fnModalVisibleByEdit()"
            v-perms:has="['system:menu:add']"
          >
            <template #icon><PlusOutlined /></template>
            {{ t('common.addText') }}
          </a-button>
        </a-space>
      </template>

      <!-- 插槽-卡片右侧 -->
      <template #extra>
        <a-space :size="8" align="center">
          <a-tooltip>
            <template #title>{{ t('views.system.role.openSwitch') }}</template>
            <a-switch
              v-model:checked="tableState.expandedRowAll"
              :checked-children="t('views.system.dept.open')"
              :un-checked-children="t('views.system.dept.open')"
              size="small"
              @change="fnTableExpandedRowsAll"
            />
          </a-tooltip>
          <a-tooltip>
            <template #title>{{ t('common.searchBarText') }}</template>
            <a-switch
              v-model:checked="tableState.seached"
              :checked-children="t('common.switch.show')"
              :un-checked-children="t('common.switch.hide')"
              size="small"
            />
          </a-tooltip>
          <a-tooltip>
            <template #title>{{ t('common.reloadText') }}</template>
            <a-button type="text" @click.prevent="fnGetList">
              <template #icon><ReloadOutlined /></template>
            </a-button>
          </a-tooltip>
          <a-tooltip placement="topRight">
            <template #title>{{ t('common.sizeText') }}</template>
            <a-dropdown placement="bottomRight" trigger="click">
              <a-button type="text">
                <template #icon><ColumnHeightOutlined /></template>
              </a-button>
              <template #overlay>
                <a-menu
                  :selected-keys="[tableState.size as string]"
                  @click="fnTableSize"
                >
                  <a-menu-item key="default"
                    >{{ t('common.size.default') }}
                  </a-menu-item>
                  <a-menu-item key="middle"
                    >{{ t('common.size.middle') }}
                  </a-menu-item>
                  <a-menu-item key="small"
                    >{{ t('common.size.small') }}
                  </a-menu-item>
                </a-menu>
              </template>
            </a-dropdown>
          </a-tooltip>
        </a-space>
      </template>
      <!-- 表格列表 -->
      <a-table
        class="table"
        row-key="menuId"
        :columns="tableColumns"
        :loading="tableState.loading"
        :data-source="tableState.data"
        :size="tableState.size"
        :pagination="false"
        :scroll="{ x: tableColumns.length * 150 }"
        children-column-name="children"
        :expanded-row-keys="tableState.expandedRowKeys"
        @expandedRowsChange="fnTableExpandedRowsChange"
      >
        <template #bodyCell="{ column, record }">
          <template v-if="column.key === 'icon'">
            <IconFont :type="record.icon" style="font-size: 18px"></IconFont>
          </template>
          <template v-if="column.key === 'visible'">
            <a-tag :color="+record.visible ? 'processing' : 'warning'">
              {{
                [t('views.system.menu.hidden'), t('views.system.menu.show')][
                  +record.visible
                ]
              }}
            </a-tag>
          </template>
          <template v-if="column.key === 'status'">
            <DictTag :options="dict.sysNormalDisable" :value="record.status" />
          </template>
          <template v-if="column.key === 'menuId'">
            <a-space :size="8" align="center">
              <a-tooltip>
                <template #title>{{ t('common.viewText') }}</template>
                <a-button
                  type="link"
                  @click.prevent="fnModalVisibleByVive(record.menuId)"
                  v-perms:has="['system:menu:query']"
                >
                  <template #icon><ProfileOutlined /></template>
                </a-button>
              </a-tooltip>
              <a-tooltip>
                <template #title>{{ t('common.editText') }}</template>
                <a-button
                  type="link"
                  @click.prevent="fnModalVisibleByEdit(record.menuId)"
                  v-perms:has="['system:menu:edit']"
                >
                  <template #icon><FormOutlined /></template>
                </a-button>
              </a-tooltip>
              <a-tooltip>
                <template #title>{{ t('common.deleteText') }}</template>
                <a-button
                  type="link"
                  @click.prevent="fnRecordDelete(record.menuId)"
                  v-perms:has="['system:menu:remove']"
                >
                  <template #icon><DeleteOutlined /></template>
                </a-button>
              </a-tooltip>
              <a-tooltip
                placement="topLeft"
                v-if="record.menuType !== MENU_TYPE_BUTTON"
              >
                <template #title>{{ t('views.system.menu.addSon') }}</template>
                <a-button
                  type="link"
                  @click.prevent="
                    fnModalVisibleByEdit(
                      undefined,
                      record.menuId,
                      record.menuType
                    )
                  "
                  v-perms:has="['system:menu:add']"
                >
                  <template #icon><PlusOutlined /></template>
                </a-button>
              </a-tooltip>
            </a-space>
          </template>
        </template>
      </a-table>
    </a-card>

    <!-- 详情框 -->
    <ProModal
      :drag="true"
      :width="800"
      :open="modalState.openByView"
      :title="modalState.title"
      @cancel="fnModalCancel"
    >
      <a-form layout="horizontal" :label-col="{ span: 6 }" :label-wrap="true">
        <a-form-item
          :label="t('views.system.menu.highMenu')"
          name="parentId"
          :label-col="{ span: 3 }"
          :label-wrap="true"
        >
          <a-tree-select
            :value="modalState.from.parentId"
            disabled
            :tree-data="modalState.treeData"
            :field-names="{
              children: 'children',
              label: 'menuName',
              value: 'menuId',
            }"
            tree-node-label-prop="menuName"
          >
            <template #suffixIcon></template>
          </a-tree-select>
        </a-form-item>
        <a-form-item
          :label="t('views.system.menu.menuName')"
          name="menuName"
          :label-col="{ span: 3 }"
          :label-wrap="true"
        >
          {{ modalState.from.menuName }}
        </a-form-item>
        <a-row>
          <a-col :lg="12" :md="12" :xs="24">
            <a-form-item :label="t('views.system.menu.menuId')" name="menuId">
              {{ modalState.from.menuId }}
            </a-form-item>
          </a-col>
          <a-col :lg="12" :md="12" :xs="24">
            <a-form-item
              :label="t('views.system.menu.menuSort')"
              name="menuSort"
            >
              {{ modalState.from.menuSort }}
            </a-form-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col :lg="12" :md="12" :xs="24">
            <a-form-item
              :label="t('views.system.menu.menuType')"
              name="menuType"
            >
              <a-tag
                v-if="modalState.from.menuType === MENU_TYPE_DIR"
                color="purple"
              >
                {{ t('views.system.menu.root') }}
              </a-tag>
              <a-tag
                v-if="modalState.from.menuType === MENU_TYPE_MENU"
                color="cyan"
              >
                {{ t('views.system.menu.menu') }}
              </a-tag>
              <a-tag
                v-if="modalState.from.menuType === MENU_TYPE_BUTTON"
                color="orange"
              >
                {{ t('views.system.menu.button') }}
              </a-tag>
            </a-form-item>
          </a-col>
          <a-col :lg="12" :md="12" :xs="24">
            <a-form-item :label="t('views.system.menu.menuTitle')" name="icon">
              <IconFont
                :type="modalState.from.icon || '#'"
                style="font-size: 18px"
              ></IconFont>
            </a-form-item>
          </a-col>
        </a-row>

        <a-row>
          <a-col
            :lg="12"
            :md="12"
            :xs="24"
            v-if="modalState.from.menuType !== MENU_TYPE_BUTTON"
          >
            <a-form-item :label="t('views.system.menu.routerAdrr')" name="path">
              {{ modalState.from.path }}
            </a-form-item>
          </a-col>
          <a-col
            :lg="12"
            :md="12"
            :xs="24"
            v-if="modalState.from.menuType === MENU_TYPE_MENU"
          >
            <a-form-item
              :label="t('views.system.menu.formLoc')"
              name="component"
            >
              {{ modalState.from.component }}
            </a-form-item>
          </a-col>
        </a-row>

        <a-row v-if="modalState.from.menuType !== MENU_TYPE_BUTTON">
          <a-col :lg="12" :md="12" :xs="24">
            <a-form-item :label="t('views.system.menu.local')" name="isFrame">
              <a-tag color="default">
                {{
                  [t('views.system.menu.no'), t('views.system.menu.yes')][
                    +modalState.from.isFrame
                  ]
                }}
              </a-tag>
            </a-form-item>
          </a-col>
          <a-col :lg="12" :md="12" :xs="24">
            <a-form-item
              :label="t('views.system.menu.pageCache')"
              name="isCache"
            >
              <a-tag color="default">
                {{
                  [
                    t('views.system.menu.noCache'),
                    t('views.system.menu.cache'),
                  ][+modalState.from.isCache]
                }}
              </a-tag>
            </a-form-item>
          </a-col>
          <a-col :lg="12" :md="12" :xs="24">
            <a-form-item :label="t('views.system.menu.status')" name="visible">
              <a-tag color="default">
                {{
                  [t('views.system.menu.hidden'), t('views.system.menu.show')][
                    +modalState.from.visible
                  ]
                }}
              </a-tag>
            </a-form-item>
          </a-col>
          <a-col :lg="12" :md="12" :xs="24">
            <a-form-item
              :label="t('views.system.menu.menuStatus')"
              name="status"
            >
              <DictTag
                :options="dict.sysNormalDisable"
                :value="modalState.from.status"
              />
            </a-form-item>
          </a-col>
        </a-row>

        <a-form-item
          :label="t('views.system.menu.perId')"
          name="perms"
          :label-col="{ span: 3 }"
          :label-wrap="true"
          v-if="modalState.from.menuType !== MENU_TYPE_DIR"
        >
          {{ modalState.from.perms }}
        </a-form-item>

        <a-form-item
          :label="t('views.system.menu.mark')"
          name="remark"
          :label-col="{ span: 3 }"
          :label-wrap="true"
        >
          {{ modalState.from.remark }}
        </a-form-item>
      </a-form>
      <template #footer>
        <a-button key="cancel" @click="fnModalCancel">{{
          t('common.cancel')
        }}</a-button>
      </template>
    </ProModal>

    <!-- 新增框或修改框 -->
    <ProModal
      :drag="true"
      :width="800"
      :destroyOnClose="true"
      :keyboard="false"
      :mask-closable="false"
      :open="modalState.openByEdit"
      :title="modalState.title"
      :confirm-loading="modalState.confirmLoading"
      @ok="fnModalOk"
      @cancel="fnModalCancel"
    >
      <a-form
        name="modalStateFrom"
        layout="horizontal"
        :label-col="{ span: 6 }"
        :label-wrap="true"
      >
        <a-form-item
          :label="t('views.system.menu.highMenu')"
          name="parentId"
          v-bind="modalStateFrom.validateInfos.parentId"
          :label-col="{ span: 3 }"
          :label-wrap="true"
        >
          <a-tree-select
            v-model:value="modalState.from.parentId"
            show-search
            tree-default-expand-all
            :tree-data="modalState.treeData"
            :field-names="{
              children: 'children',
              label: 'menuName',
              value: 'menuId',
            }"
            tree-node-label-prop="menuName"
            tree-node-filter-prop="menuName"
            style="width: 100%"
            :dropdown-style="{ maxHeight: '400px', overflow: 'auto' }"
            @change="fnTreeDataChange"
          >
          </a-tree-select>
        </a-form-item>

        <a-row>
          <a-col :lg="12" :md="12" :xs="24">
            <a-form-item
              :label="t('views.system.menu.menuName')"
              name="menuName"
              v-bind="modalStateFrom.validateInfos.menuName"
            >
              <a-input
                v-model:value="modalState.from.menuName"
                allow-clear
              ></a-input>
            </a-form-item>
          </a-col>
          <a-col :lg="12" :md="12" :xs="24">
            <a-form-item
              :label="t('views.system.menu.menuSort')"
              name="menuSort"
            >
              <a-input-number
                v-model:value="modalState.from.menuSort"
                :min="0"
                :max="9999"
                :step="1"
              ></a-input-number>
            </a-form-item>
          </a-col>
        </a-row>

        <a-form-item
          :label="t('views.system.menu.menuType')"
          name="menuType"
          :label-col="{ span: 3 }"
          :label-wrap="true"
        >
          <a-radio-group v-model:value="modalState.from.menuType">
            <a-radio
              :key="MENU_TYPE_DIR"
              :value="MENU_TYPE_DIR"
              :disabled="modalState.from.parentType === MENU_TYPE_MENU"
            >
              {{ t('views.system.menu.root') }}
            </a-radio>
            <a-radio
              :key="MENU_TYPE_MENU"
              :value="MENU_TYPE_MENU"
              :disabled="modalState.from.parentType === MENU_TYPE_MENU"
            >
              {{ t('views.system.menu.menu') }}
            </a-radio>
            <a-radio :key="MENU_TYPE_BUTTON" :value="MENU_TYPE_BUTTON">
              {{ t('views.system.menu.button') }}
            </a-radio>
          </a-radio-group>
        </a-form-item>

        <a-row v-if="modalState.from.menuType !== MENU_TYPE_BUTTON">
          <a-col :lg="12" :md="12" :xs="24">
            <a-form-item :label="t('views.system.menu.menuTitle')" name="icon">
              <a-select
                v-model:value="modalState.from.icon"
                show-search
                option-filter-prop="label"
                option-label-prop="label"
                :options="icons"
              >
                <template #suffixIcon>
                  <IconFont :type="modalState.from.icon"></IconFont>
                </template>
                <template #option="{ value, label }">
                  <div style="font-size: 18px">
                    <IconFont :type="value"></IconFont>
                    &nbsp;&nbsp;{{ label }}
                  </div>
                </template>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :lg="12" :md="12" :xs="24">
            <a-form-item
              :label="t('views.system.menu.routerAdrr')"
              name="path"
              v-bind="modalStateFrom.validateInfos.path"
            >
              <a-input v-model:value="modalState.from.path" allow-clear>
                <template #prefix>
                  <a-tooltip placement="topLeft">
                    <template #title>
                      <div>
                        {{ t('views.system.menu.pathTip') }}
                        {{ MENU_PATH_INLINE }}/{{
                          t('views.system.menu.sonPage')
                        }}
                      </div>
                    </template>
                    <InfoCircleOutlined style="opacity: 0.45; color: inherit" />
                  </a-tooltip>
                </template>
              </a-input>
            </a-form-item>
          </a-col>
        </a-row>

        <a-row v-if="modalState.from.menuType !== MENU_TYPE_BUTTON">
          <a-col :lg="12" :md="12" :xs="24">
            <a-form-item :label="t('views.system.menu.local')" name="isFrame">
              <a-select
                v-model:value="modalState.from.isFrame"
                default-value="0"
              >
                <a-select-option key="0" value="0">{{
                  t('views.system.menu.no')
                }}</a-select-option>
                <a-select-option key="1" value="1">{{
                  t('views.system.menu.yes')
                }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :lg="12" :md="12" :xs="24">
            <a-form-item
              :label="t('views.system.menu.pageCache')"
              name="isCache"
            >
              <a-select
                v-model:value="modalState.from.isCache"
                default-value="0"
              >
                <a-select-option key="0" value="0">{{
                  t('views.system.menu.noCache')
                }}</a-select-option>
                <a-select-option key="1" value="1">{{
                  t('views.system.menu.cache')
                }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :lg="12" :md="12" :xs="24">
            <a-form-item :label="t('views.system.menu.status')" name="visible">
              <a-select
                v-model:value="modalState.from.visible"
                default-value="0"
              >
                <a-select-option key="0" value="0">{{
                  t('views.system.menu.hidden')
                }}</a-select-option>
                <a-select-option key="1" value="1">{{
                  t('views.system.menu.show')
                }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :lg="12" :md="12" :xs="24">
            <a-form-item
              :label="t('views.system.menu.menuStatus')"
              name="status"
            >
              <a-select
                v-model:value="modalState.from.status"
                default-value="0"
                :options="dict.sysNormalDisable"
              >
              </a-select>
            </a-form-item>
          </a-col>
        </a-row>

        <a-form-item
          :label="t('views.system.menu.formLoc')"
          name="component"
          v-bind="modalStateFrom.validateInfos.component"
          :label-col="{ span: 3 }"
          :label-wrap="true"
          v-if="modalState.from.menuType === MENU_TYPE_MENU"
        >
          <a-input v-model:value="modalState.from.component" allow-clear>
            <template #prefix>
              <a-tooltip placement="topLeft">
                <template #title>
                  <div>
                    {{ t('views.system.menu.componentTip') }}
                  </div>
                </template>
                <InfoCircleOutlined style="opacity: 0.45; color: inherit" />
              </a-tooltip>
            </template>
          </a-input>
        </a-form-item>

        <a-form-item
          :label="t('views.system.menu.perId')"
          name="perms"
          v-if="modalState.from.menuType !== MENU_TYPE_DIR"
          v-bind="modalStateFrom.validateInfos.perms"
          :label-col="{ span: 3 }"
          :label-wrap="true"
        >
          <a-input v-model:value="modalState.from.perms" allow-clear>
            <template #prefix>
              <a-tooltip placement="topLeft">
                <template #title>
                  <div>
                    {{ t('views.system.menu.perms') }}
                  </div>
                </template>
                <InfoCircleOutlined style="opacity: 0.45; color: inherit" />
              </a-tooltip>
            </template>
          </a-input>
        </a-form-item>

        <a-form-item
          :label="t('views.system.menu.mark')"
          name="remark"
          :label-col="{ span: 3 }"
          :label-wrap="true"
        >
          <a-textarea
            v-model:value="modalState.from.remark"
            :auto-size="{ minRows: 4, maxRows: 6 }"
            :maxlength="450"
            :show-count="true"
          />
        </a-form-item>
      </a-form>
    </ProModal>
  </PageContainer>
</template>

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