<template>
  <BasicModal
    v-bind="$attrs"
    :title="title"
    @register="registerInnerModal"
    @ok="handleSubmit"
    @cancel="handleCancle"
    :width="1200"
  >
    <BasicTable @register="registerTable">
      <!-- <template #toolbar>
        <a-button v-auth="'elevator:maintenancePlan:add'" @click="handleClick">生成</a-button>
        <a-button v-auth="'elevator:maintenancePlan:remove'" type="primary" @click="multipleRemove(infoPlanRemove)" :disabled="!selected"
          >删除</a-button
        >
      </template> -->
      <template #bodyCell="{ column, record }">
        <template v-if="column.key === 'action'"> </template>
        <!-- <template v-if="column.dataIndex === 'planType'">{{ typeMap[record.planType] }} </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, onMounted } from 'vue';
import { BasicTable, useTable, TableAction } from '@/components/Table';

import { formSchemas, columns, planColmus } from './maintenanceRecord.data';
import createPlanModal from './createPlanModal.vue';
import { useModal } from '@/components/Modal';
import { maintenancePlanList, infoPlanRemove } from '@/api/basicInfo/maintenanceRecord';
import { workDataList } from '@/api/workPlace/workInfo/index';
defineOptions({ name: 'MaintenanceRecordModal' });
const elevatorInfo = ref<any>({});
const emit = defineEmits(['register', 'reload']);
const typeMap = reactive({
  1: '半月',
  2: '季度',
  3: '半年',
  4: '年度',
  5: '按需',
});
const statusMap = reactive({
  0: '未提醒',
  1: '已提醒',
});
const isUpdate = ref<number>(1);
const title = computed<string>(() => {
  return '维保计划';
});
const [registerTable, { reload, selected, multipleRemove }] = useTable({
  rowSelection: {
    type: 'checkbox',
  },
  title: '',
  api: workDataList,
  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: planColmus,
});
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, { elevatorInfo: elevatorInfo.value });
}
async function handleSubmit() {}
function handleCancle() {
  closeModal();
}
</script>

<style scoped></style>
