<template>
  <BasicModal
    v-bind="$attrs"
    :title="title"
    @register="registerInnerModal"
    @ok="handleSubmit"
    :width="800"
  >
    <template #footer>
      <div v-if="isUpdate !== 3">
        <a-button type="default" @click="handleCancle">取消</a-button>
        <a-button type="primary" @click="handleSubmit">确认</a-button>
      </div>
    </template>

    <BasicTable @register="registerTable"> </BasicTable>
  </BasicModal>
</template>

<script setup lang="ts">
import { BasicModal, useModalInner } from "@/components/Modal";
import { BasicTable, useTable, TableAction } from "@/components/Table";
import { computed, ref, unref } from "vue";
import { infoList } from "@/api/basicInfo/elevator";
import { modalSchemas, formDeviceSchemas, deviceColumns } from "./info.data";

defineOptions({ name: "InfoModal" });

const emit = defineEmits(["register", "reload"]);

const isUpdate = ref<number>(1);
const title = computed<string>(() => {
  return "未分配的终端";
});
const [registerTable, { reload, multipleRemove, selected, getForm }] = useTable({
  rowSelection: {
    type: "checkbox",
  },
  title: "设备列表",
  api: infoList,
  showIndexColumn: false,
  rowKey: "id",
  useSearchForm: true,
  formConfig: {
    schemas: formDeviceSchemas,
    baseColProps: {
      xs: 24,
      sm: 24,
      md: 24,
      lg: 12,
    },
  },
  columns: deviceColumns,
  // 需要添加上部门参数
});
const [registerInnerModal, { modalLoading, closeModal }] = useModalInner(
  async (data: { record?: Recordable; update: number }) => {
    modalLoading(true);
    const { record, update } = data;
    isUpdate.value = update;

    modalLoading(false);
  }
);

async function handleSubmit() {
  try {
    modalLoading(true);
  } catch (e) {
    console.warn(e);
  } finally {
    modalLoading(false);
  }
}
function handleCancle() {
  closeModal();
}
</script>

<style scoped></style>
