import type { FormSchemaGetter } from '#/adapter/form';
import type { VxeGridProps } from '#/adapter/vxe-table';

import {
  selectAllSysAreaList,
  selectAllSysStation,
} from '#/api/system/infoEntry/stationInfo/stationInfo';

// 获取过滤后的岗位列表
import { getFilteredPositions } from '../../utils/positionFilter';

export const querySchema: FormSchemaGetter = () => [
  {
      component: 'ApiSelect',
      fieldName: 'areaId',
      label: '片区',
      componentProps: {
        placeholder: '请选择片区',
        clearable: true,
        api: async () => {
          const resp = await selectAllSysAreaList();
          const data = resp || [];
          return Array.isArray(data)
            ? data.map((item: any) => ({
                label: item.areaName,
                value: item.id,
              }))
            : [];
        },
        labelField: 'label',
        valueField: 'value',
      },
    },
  {
      component: 'ApiSelect',
      fieldName: 'stationId',
      label: '油站',
      componentProps: {
        placeholder: '请选择油站',
        clearable: true,
        api: async () => {
          const resp = await selectAllSysStation();
          const data = resp || [];
          return Array.isArray(data)
            ? data.map((item: any) => ({
                label: item.stationName,
                value: item.id.toString(),
              }))
            : [];
        },
        labelField: 'label',
        valueField: 'value',
      },
    },
   {
     component: 'Select',
     componentProps: {
       options: [
         { label: '按时完成', value: 2 },
         { label: '逾期完成', value: 1 },
       ],
     },
     fieldName: 'completionStatus',
     label: '状态',
   },
   {
     component: 'DatePicker',
     componentProps: {
       type: 'daterange',
       format: 'YYYY-MM-DD HH:mm:ss',
       valueFormat: 'YYYY-MM-DD HH:mm:ss',
       startPlaceholder: '开始日期',
       endPlaceholder: '结束日期',
     },
     fieldName: 'processTime',
     label: '处理时间',
   },
   {
     component: 'Select',
     componentProps: {
       options: [
         { label: '否', value: 0 },
         { label: '是', value: 1 },
       ],
     },
     fieldName: 'isComment',
     label: '评论',
   },
   {
     component: 'ApiSelect',
     fieldName: 'position',
     label: '岗位',
     componentProps: {
       placeholder: '请选择岗位',
       clearable: true,
       api: getFilteredPositions,
       labelField: 'label',
       valueField: 'value',
     },
   },
   {
     component: 'Select',
     componentProps: {
       options: [
         { label: '系统', value: 0 },
         { label: '新增', value: 1 },
       ],
     },
     fieldName: 'createType',
     label: '创建',
   },
   {
     component: 'Input',
     componentProps: {
       placeholder: '请输入执行人',
     },
     fieldName: 'executorName',
     label: '执行人',
   },
];

export const columns: VxeGridProps['columns'] = [
  {
    type: 'checkbox',
    width: 80,
  },
  {
    field: 'action',
    fixed: 'right',
    slots: { default: 'action' },
    title: '操作',
    width: 230,
  },
  {
    field: 'taskName',
    title: '任务名称',
    minWidth: 150,
  },
  {
    field: 'stationId',
    title: '油站',
    minWidth: 120,
  },
  {
    field: 'executorName',
    title: '执行人',
    minWidth: 120,
  },
  {
    field: 'position',
    title: '岗位',
    minWidth: 120,
  },
  {
    field: 'isComment',
    title: '评论',
    minWidth: 100,
    align: 'center',
    formatter: (cellValue: number) => {
      return cellValue === 1 ? '已评' : '未评';
    },
  },
  {
    field: 'deadline',
    title: '截止时间',
    minWidth: 180,
  },
  {
    field: 'processTime',
    title: '处理时间',
    minWidth: 180,
  },
  {
    field: 'completionStatus',
    title: '完成状态',
    minWidth: 120,
    align: 'center',
    formatter: ({ row }) => {
      return row.completionStatus === 2 ? '按时完成' : '逾期完成';
    },
  },
  {
    field: 'createType',
    title: '创建',
    minWidth: 100,
    align: 'center',
    formatter: (cellValue: number) => {
      return cellValue === 0 ? '系统' : '新增';
    },
  },
  {
    field: 'meetingType',
    title: '会议类型',
    minWidth: 120,
    align: 'center',
    formatter: (cellValue: number) => {
      return cellValue === 0 ? '例会' : '片区会议';
    },
  },
  {
    field: 'meetingTheme',
    title: '会议主题',
    minWidth: 150,
  },
  {
    field: 'meetingHost',
    title: '会议主持',
    minWidth: 120,
  },
  {
    field: 'meetingLocation',
    title: '会议地点',
    minWidth: 150,
  },
];

