<template>
  <PageWrapper dense>

 
     
        <BasicTable @register="registerTable">
          <template #toolbar>
            <a-button
              @click="
                downloadExcel(
                  maintenanceInfoExport,
                  '维保单位基础信息;数据',
                  getForm().getFieldsValue()
                )
              "
              v-auth="'elevator:maintenanceInfo:export'"
              >导出</a-button
            >
            <a-button
              type="primary"
              danger
              @click="multipleRemove(maintenanceInfoRemove)"
              :disabled="!selected"
              v-auth="'elevator:maintenanceInfo:remove'"
              >删除</a-button
            >
            <a-button
              type="primary"
              @click="handleAdd"
              v-auth="'elevator:maintenanceInfo:add'"
              >新增</a-button
            >
          </template>
          <template #bodyCell="{ column, record }">
            <template v-if="column.key === 'action'">
              <TableAction
                stopButtonPropagation
                :actions="[
                  {
                    label: '查看',

                    type: 'primary',
                    ghost: true,
                    auth: 'behavior:behaviorMessage:query',
                    onClick: handCheck.bind(null, record),
                  },
                  {
                    label: '修改',

                    type: 'primary',
                    ghost: true,
                    auth: 'elevator:maintenanceInfo:edit',
                    onClick: handleEdit.bind(null, record),
                  },
                  {
                    label: '删除',

                    type: 'primary',
                    danger: true,
                    ghost: true,
                    auth: 'elevator:maintenanceInfo:remove',
                    popConfirm: {
                      placement: 'left',
                      title: '是否删除维保单位基础信息;[' + record.id + ']?',
                      confirm: handleDelete.bind(null, record),
                    },
                  },
                  {
                    label: '用户管理',

                    type: 'primary',
                    ghost: true,
                    auth: 'elevator:tenementInfo:userManage',
                    onClick: handleOpenUserModal.bind(null, record),
                  },
                ]"
              />
            </template>
          </template> </BasicTable
      >

    <MaintenanceInfoModal @register="registerModal" @reload="reload" />
    <UserManageModal @register="registerUserModal"></UserManageModal>
  </PageWrapper>
</template>

<script setup lang="ts">
import { PageWrapper } from "@/components/Page";
import { BasicTable, useTable, TableAction } from "@/components/Table";
import {
  maintenanceInfoList,
  maintenanceInfoExport,
  maintenanceInfoRemove,
} from "@/api/basicInfo/maintenance";
import { downloadExcel } from "@/utils/file/download";
import { useModal } from "@/components/Modal";
import MaintenanceInfoModal from "./MaintenanceInfoModal.vue";
import { formSchemas, columns } from "./maintenanceInfo.data";
import { IconEnum } from "@/enums/appEnum";
import UserManageModal from "@/components/CommonUserManageModal/UserManageModal.vue";
import DeptTree from "@/components/commonDeptTree/DeptTree.vue";
import { ref, toValue } from "vue";
import { Row, Col } from "ant-design-vue";
defineOptions({ name: "MaintenanceInfo" });
const selectDeptId = ref<string[]>([]);
const searchValue = ref<string>("");
const [registerTable, { reload, multipleRemove, selected, getForm }] = useTable({
  rowSelection: {
    type: "checkbox",
  },
  title: "维保单位基础信息;列表",
  api: maintenanceInfoList,
  showIndexColumn: true,
  rowKey: "id",
  useSearchForm: true,
  formConfig: {
    schemas: formSchemas,
    baseColProps: {
      xs: 24,
      sm: 24,
      md: 24,
      lg: 6,
    },
    resetFunc: async () => {
      selectDeptId.value = [];
      searchValue.value = "";
      await reload();
    },
  },
  columns: columns,
  // 需要添加上部门参数
  beforeFetch(params: Recordable) {
    if (toValue(selectDeptId).length === 1) {
      params.deptId = toValue(selectDeptId)[0];
    }
    return params;
  },
  actionColumn: {
    width: 250,
    title: "操作",
    key: "action",
    fixed: "right",
  },
});

const [registerModal, { openModal }] = useModal();
const [registerUserModal, { openModal: openUserModal }] = useModal();
function handleEdit(record: Recordable) {
  openModal(true, { record, update: 1 });
}

function handleAdd() {
  openModal(true, { update: 2 });
}
function handCheck(record: Recordable) {
  openModal(true, { record, update: 3 });
}
function handleOpenUserModal(record: Recordable) {
  openUserModal(true, { record, update: 3 });
}
async function handleDelete(record: Recordable) {
  await maintenanceInfoRemove([record.id]);
  await reload();
}
</script>

<style scoped></style>
