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

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

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

// 员工评价记录表格配置
export const tableColumns: VxeGridProps['columns'] = [
  {
    type: 'checkbox',
    width: 80,
  },
  {
    title: '被评人',
    field: 'userName',
    minWidth: 120,
    align: 'center',
  },
  {
    title: '被评人岗位',
    field: 'postName',
    minWidth: 120,
    align: 'center',
  },
  {
    title: '油站',
    field: 'stationName',
    minWidth: 150,
    align: 'center',
  },
  {
    title: '顾客服务(30分)',
    field: 'customerService',
    minWidth: 130,
    align: 'center',
  },
  {
    title: '安全考核(15分)',
    field: 'safetyAssessment',
    minWidth: 130,
    align: 'center',
  },
  {
    title: '日常综合表现(25分)',
    field: 'dailyPerformance',
    minWidth: 150,
    align: 'center',
  },
  {
    title: '业绩表现(20分)',
    field: 'performance',
    minWidth: 130,
    align: 'center',
  },
  {
    title: '自主评分(10分)',
    field: 'selfEvaluation',
    minWidth: 130,
    align: 'center',
  },
  {
    title: '总分',
    field: 'totalScore',
    minWidth: 100,
    align: 'center',
  },
  {
    title: '评语',
    field: 'comments',
    minWidth: 200,
    align: 'left',
  },
  {
    title: '评价时间',
    field: 'evaluationDate',
    minWidth: 160,
    align: 'center',
  },
  {
    title: '完成状态',
    field: 'completionStatus',
    minWidth: 120,
    align: 'center',
    formatter: ({ row }) => {
      return row.completionStatus === 2 ? '按时完成' : '逾期完成';
    },
  },
];

export const queryFormSchema: FormSchemaGetter = () => [
  {
    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: 'DatePicker',
    fieldName: 'evaluationDate',
    label: '评价时间',
    componentProps: {
      placeholder: '请选择时间范围',
      type: 'daterange',
      rangeSeparator: '至',
      startPlaceholder: '开始时间',
      endPlaceholder: '结束时间',
      valueFormat: 'YYYY-MM-DD HH:mm:ss'
    },
  },
  {
    component: 'Input',
    fieldName: 'userName',
    label: '被评人',
    componentProps: {
      placeholder: '请输入被评人',
    },
  },
  {
    component: 'ApiSelect',
    fieldName: 'postId',
    label: '被评人岗位',
    componentProps: {
      placeholder: '请选择被评人岗位',
      clearable: true,
      api: getFilteredPositions,
      labelField: 'label',
      valueField: 'value',
    },
  },
  {
    component: 'Select',
    fieldName: 'completionStatus',
    label: '完成状态',
    componentProps: {
      placeholder: '请选择完成状态',
      options: [
        { label: '按时完成', value: 2 },
        { label: '逾期完成', value: 1 },
      ],
    },
  },
];

