<template>
  <BasicModal
    v-bind="$attrs"
    :title="title"
    @register="registerInnerModal"
    @ok="handleSubmit"
    @cancel="handleCancle"
    :width="800"
    :footer="null"
  >
    <BasicTable @register="registerTable">
      <template #toolbar> </template>
      <template #bodyCell="{ column, record }">
        <template v-if="column.key === 'action'"> </template>
        <template v-if="column.dataIndex === 'state'"
          >{{ statusMap[record.state] }}
        </template>
      </template>
    </BasicTable>
    <createPlanModal @register="registerPlanModal" @reload="reload" />
  </BasicModal>
</template>

<script setup lang="ts">
import { BasicModal, useModalInner } from "@/components/Modal";
import { computed, reactive, ref, unref } from "vue";
import { BasicTable, useTable, TableAction } from "@/components/Table";

import { formSchemas, columns, yearColmus } from "./maintenanceRecord.data";
import createPlanModal from "./createPlanModal.vue";
import { useModal } from "@/components/Modal";
import { annualPlanList } from "@/api/basicInfo/maintenanceRecord";
defineOptions({ name: "MaintenanceRecordModal" });

const emit = defineEmits(["register", "reload"]);
const elevatorInfo = ref<any>({});
const isUpdate = ref<number>(1);
const title = computed<string>(() => {
  return "年检计划";
});
const statusMap = reactive({
  0: "未提醒",
  1: "已提醒",
});
const [registerTable, { reload, selected }] = useTable({
  rowSelection: {
    type: "checkbox",
  },
  title: "",
  api: annualPlanList,
  showIndexColumn: false,
  rowKey: "id",
  useSearchForm: false,
  formConfig: {
    schemas: formSchemas,
    baseColProps: {
      xs: 24,
      sm: 24,
      md: 24,
      lg: 6,
    },
  },
  // 需要添加上部门参数
  beforeFetch(params: Recordable) {
    params.elevatorNum = elevatorInfo.value.elevatorNum;
    return params;
  },
  columns: yearColmus,
});
const [registerInnerModal, { closeModal }] = useModalInner(
  async (data: { record?: Recordable; update: number }) => {
    const { record, update } = data;
    elevatorInfo.value = record;
    reload();
  }
);
const [registerPlanModal, { openModal: openPlanModal }] = useModal();
function handleClick() {
  openPlanModal(true);
}
function handleCancle() {
  closeModal();
}
async function handleSubmit() {}
</script>

<style scoped></style>
