<template>
  <PageWrapper dense>
    <BasicTable @register="registerTable">
      <template #bodyCell="{ column, record }">
        <template v-if="column && record && column.key === 'action'">
          <a-button type="link" @click="showDrawer(record.id)">详情</a-button>
          <a-popconfirm
            title="确定接单吗?"
            ok-text="是"
            cancel-text="否"
            @confirm="receive(record.id)"
          >
            <a-button type="link">接单</a-button>
          </a-popconfirm>
          <a-button type="link" @click="handle(record.id)">处理</a-button>
          <a-button type="link" @click="back(record.id)">回退</a-button>
          <a-button type="link" @click="delay(record.id)">延期</a-button>
        </template>
      </template>
    </BasicTable>
    <detailDrawer ref="detailDrawerRef" />
    <backModal ref="backModalRef" @success="reload()"/>
    <delayModal ref="delayModalRef"  @success="reload()" />
    <handleModal ref="handleModalRef"  @success="reload()" />
  </PageWrapper>
</template>

<script setup lang="ts">
  import { PageWrapper } from '@/components/Page';
  import { BasicTable, useTable } from '@/components/Table';
  import { list, getProjectInfo } from './api';
  import { formSchemas, columns } from './data';
  import detailDrawer from './detailDrawer.vue';
  import backModal from './backModal.vue';
  import handleModal from './handleModal.vue';
  import delayModal from './delayModal.vue';
  import { ref } from 'vue';

  const [registerTable,{reload}] = useTable({
    title: '工单处理',
    api: list,
    showIndexColumn: true,
    rowKey: 'id',
    useSearchForm: true,
    formConfig: {
      schemas: formSchemas,
      name: 'orderHandle',
      baseColProps: {
        xs: 24,
        sm: 24,
        md: 24,
        lg: 6,
      },
    },
    columns: columns,
    actionColumn: {
      width: 320,
      title: '操作',
      key: 'action',
      fixed: 'right',
    },
  });

  //详情抽屉
  const detailDrawerRef = ref();
  const showDrawer = (id: any) => {
    detailDrawerRef.value.showDrawer(id);
  };
  const receive = async (id: any) => {
    reload();
  };
  const backModalRef = ref()
  const back = (id:any) =>{
    backModalRef.value.showModal(id)
  }
  const delayModalRef = ref()
  const delay = (id:any) =>{
    delayModalRef.value.showModal(id)
  }
  const handleModalRef = ref()
  const handle = (id:any) =>{
    handleModalRef.value.showModal(id)
  }
  const projectOptions = ref([]);
  const getProjectOptions = async () => {
    const res = await getProjectInfo();
    res.forEach((i: any) => {
      i.value = i.projectName;
      i.label = i.projectName;
    });
    projectOptions.value = res;
    formSchemas[0].componentProps.options = projectOptions.value;
  };
  const getOptions = () => {
    getProjectOptions();
  };
  getOptions();
  // 前往审批记录页面
</script>

<style scoped></style>
