<!--
 * @Author: Mm
 * @Date: 2025-04-07 10:13:17
 * @LastEditors: Mm
 * @LastEditTime: 2025-05-23 10:43:43
 * 不写bug的程序员不是一个好程序员!
-->
<script setup lang="ts">
import type { Recordable } from '@vben/types';

import { computed, getCurrentInstance, nextTick, onMounted, ref } from 'vue';

import { Page, useVbenModal, type VbenFormProps } from '@vben/common-ui';
import { getVxePopupContainer } from '@vben/utils';

import { Modal, Popconfirm, Space, Tag, message } from 'ant-design-vue';
import dayjs from 'dayjs';

import {
  useVbenVxeGrid,
  vxeCheckboxChecked,
  type VxeGridProps,
} from '#/adapter/vxe-table';

import { wcldTasksList } from '#/api/tasks/index';

import { dwspColumns, queryDwspSchema } from './data';
import { useRouter } from 'vue-router';

const router = useRouter();

const formOptions: VbenFormProps = {
  commonConfig: {
    labelWidth: 80,
    componentProps: {
      allowClear: true,
    },
  },
  schema: queryDwspSchema(),
  wrapperClass: 'grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4',
};

const gridOptions: VxeGridProps = {
  checkboxConfig: {
    // 高亮
    highlight: true,
    // 翻页时保留选中状态
    reserve: true,
    // 点击行选中
    // trigger: 'row',
  },
  // 需要使用i18n注意这里要改成getter形式 否则切换语言不会刷新
  // columns: columns(),
  columns: dwspColumns,
  height: 'auto',
  keepSource: true,
  pagerConfig: {},
  proxyConfig: {
    ajax: {
      query: async ({ page }) => {
        const formValuess = tableApi.formApi.form.values;
        return await wcldTasksList({
          pageNum: page.currentPage,
          pageSize: page.pageSize,
          ...formValuess,
        });
      },
    },
  },
  rowConfig: {
    keyField: 'instanceId',
  },
  // 表格全局唯一表示 保存列配置需要用到
  id: 'web-news-index',
};

const [BasicTable, tableApi] = useVbenVxeGrid({
  formOptions,
  gridOptions,
});

//详情
function handleDetail(row: Recordable<any>) {
  router.push('/tasks/detail?instanceId=' + row.instanceId);
}
</script>

<template>
  <Page :auto-content-height="true">
    <BasicTable table-title="已审批的任务中心">
      <template #toolbar-tools>
        <Space>
          <a-button>
            {{ $t('pages.common.export') }}
          </a-button>
        </Space>
      </template>
      <template #missionStatus="{ row }">
        <Tag color="#006be6" v-if="row.missionStatus === '审批进行中'">{{
          row.missionStatus
        }}</Tag>
        <Tag color="#87d068" v-else>{{ row.missionStatus }}</Tag>
      </template>
       <template #startUser="{ row }">
        {{ row.startUser.nickName }}
      </template>
      <template #action="{ row }">
        <Space>
          <ghost-button @click.stop="handleDetail(row)"> 详情 </ghost-button>
        </Space>
      </template>
    </BasicTable>
  </Page>
</template>
<style>
.hide-label > label {
  width: 0 !important;
}
</style>
