// @ts-ignore: 忽略
import type { FormSchemaGetter } from '#/adapter/form';
// @ts-ignore: 忽略
import type { VxeGridProps } from '#/adapter/vxe-table';

const totalScore = (row: any) => {
  const score =
    Number(row.customerService) +
    Number(row.safetyAssessment) +
    Number(row.dailyPerformance) +
    Number(row.performance) +
    Number(row.selfEvaluation);
  return score;
};

// 抽屉表单配置
export const drawerFormSchema: any | FormSchemaGetter = () => [
  {
    fieldName: 'weeklyEvaluationTable',
    label: '员工周评价表格',
    hideLabel: true,
    renderComponentContent: () => {
      return {
        default: () => [],
      };
    },
  },
];

// 默认表格列配置
export const defautTableColumns: VxeGridProps['columns'] = [
  {
    field: 'userName',
    title: '姓名',
    width: 100,
    fixed: 'left',
  },
  {
    field: 'postName',
    title: '岗位',
    width: 100,
  },
  {
    field: 'customerService',
    title: '顾客服务(30分)',
    width: 120,
    editRender: {
      name: 'input',
      immediate: true,
      events: {
        change: (cellParams) => {
          const { row } = cellParams;
          row.totalScore = totalScore(row);
        },
      },
    },
  },
  {
    field: 'safetyAssessment',
    title: '安全考核(15分)',
    width: 120,
    editRender: {
      name: 'input',
      immediate: true,
      events: {
        change: (cellParams) => {
          const { row } = cellParams;
          row.totalScore = totalScore(row);
        },
      },
    },
  },
  {
    field: 'dailyPerformance',
    title: '日常综合表现(25分)',
    width: 150,
    editRender: {
      name: 'input',
      immediate: true,
      events: {
        change: (cellParams) => {
          const { row } = cellParams;
          row.totalScore = totalScore(row);
        },
      },
    },
  },
  {
    field: 'performance',
    title: '业绩表现(20分)',
    width: 120,
    editRender: {
      name: 'input',
      immediate: true,
      events: {
        change: (cellParams) => {
          const { row } = cellParams;
          row.totalScore = totalScore(row);
        },
      },
    },
  },
  {
    field: 'selfEvaluation',
    title: '自主评分(10分)',
    width: 120,
    editRender: {
      name: 'input',
      immediate: true,
      events: {
        change: (cellParams) => {
          const { row } = cellParams;
          row.totalScore = totalScore(row);
        },
      },
    },
  },
  {
    field: 'totalScore',
    title: '总分',
    width: 80,
    // formatter: ({ row }) => {
    //   return (
    //     Number(row.customerService) +
    //     Number(row.safetyAssessment) +
    //     Number(row.dailyPerformance) +
    //     Number(row.performance) +
    //     Number(row.selfEvaluation)
    //   );
    // },
  },
  {
    field: 'comments',
    title: '评语',
    width: 200,
    editRender: { name: 'input' },
  },
];
