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

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

// 岗位列表接口
import { requestClient } from '#/api/request';

// 获取岗位列表
const getPostList = async () => {
  const resp = await requestClient.get('/system/post/list');
  return resp || [];
};

export const querySchema: FormSchemaGetter = () => [
  {
      component: 'ApiSelect',
      fieldName: 'stationId',
      label: '油站',
      componentProps: {
        placeholder: '请选择油站',
        clearable: true,
        api: async () => {
          const resp = await selectAllSysStationAreaList();
          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: 0 },
         { 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: async () => {
         const data = await getPostList();
         return Array.isArray(data.rows)
           ? data.rows.map((item: any) => ({
               label: item.postName || item.name,
               value: item.postId,
             }))
           : [];
       },
       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: 150,
  },
  {
    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: (cellValue: number) => {
      return cellValue === 0 ? '按时完成' : '逾期完成';
    },
  },
  {
    field: 'createType',
    title: '创建',
    minWidth: 100,
    align: 'center',
    formatter: (cellValue: number) => {
      return cellValue === 0 ? '系统' : '新增';
    },
  },
  {
    field: 'sitePriceStrategy',
    title: '本站价格策略',
    minWidth: 150,
  },
  {
    field: 'competitorStrategy',
    title: '竞对油站策略',
    minWidth: 150,
  },
  {
    field: 'weekSummary',
    title: '本周工作总结',
    minWidth: 180,
  },
  {
    field: 'nextWeekPlan',
    title: '下周工作计划',
    minWidth: 180,
  },
];

