import { listDictModel } from '@/api/common';
import { FormSchema } from '@/components/Form';
import { BasicColumn } from '@/components/Table';
import dayjs from 'dayjs';

// 枚举类型
export enum DiagnosisEnum {
  firstDialysis = '首次透析',
  firstDialysis_field = 'firstDialysis',
  operation = '手术史',
  operation_field = 'operation',
  allergic = '过敏史',
  allergic_field = 'allergic',
  contagious = '传染病史',
  contagious_field = 'contagious',
  complications = '治疗前合并症',
  complications_field = 'complications',
  clinic = '临床诊断',
  clinic_field = 'clinic',
  pathological = '病理诊断',
  pathological_field = 'pathological',
  ckd = 'CKD/AKI',
  ckd_field = 'ckd',
  elseRemark = '其他',
  elseRemark_field = 'elseRemark',
}

// 表单新增编辑
export const dataFormSchema: FormSchema[] = [
  {
    label: 'type',
    field: 'type',
    component: 'PlainText',
    show: false,
  },
  {
    label: '记录日期',
    field: 'recordTime',
    component: 'PlainText',
  },
  {
    label: '记录人',
    field: 'name',
    component: 'PlainText',
  },
  {
    label: '首次透析时间',
    field: 'firstDialysisDate',
    required: true,
    component: 'DatePicker',
    componentProps: {
      format: 'YYYY-MM-DD',
      placeholder: '请输入记录日期',
      getPopupContainer: () => document.body,
      valueFormat: 'YYYY-MM-DD',
    },
    ifShow: ({ values }) => {
      return values.type == DiagnosisEnum.firstDialysis_field;
    },
  },
  {
    label: '首次透析方式',
    field: 'firstDialysisType',
    required: true,
    component: 'ApiSelect',
    componentProps: {
      api: listDictModel,
      params: {
        dictCode: 'dt',
      },
      getPopupContainer: () => document.body,
    },
    ifShow: ({ values }) => {
      return values.type == DiagnosisEnum.firstDialysis_field;
    },
  },
];

export const columnsAllergic: BasicColumn[] = [
  {
    title: '过敏名称数组',
    dataIndex: 'nameOptions',
    ifShow: false,
  },
  {
    title: '诊断类型字典默认值',
    dataIndex: 'typeOptions',
    ifShow: false,
  },
  {
    title: '过敏原',
    dataIndex: 'contentType',
    width: 150,
    edit: true,
    editable: true,
    editComponent: 'Select',
    // 默认必填校验
    editRule: true,
    editComponentProps: ({ record }) => {
      return {
        options: record.typeOptions,
        showSearch: true,
        placeholder: '请选择',
        getPopupContainer: () => document.body,
        filterOption: false,
      };
    },
  },
  {
    title: '名称',
    dataIndex: 'name',
    width: 220,
    edit: true,
    editable: true,
    // ApiSelect 多选会出现闪屏问题,请尽量使用默认隐藏字段
    // editComponent: 'ApiSelect',
    // // 默认必填校验
    // editRule: true,
    // editComponentProps: ({ record }) => {
    //   // console.log('🚀 ~ file: data.ts:103 ~ record:', record);
    //   return {
    //     api: listDictModel,
    //     params: {
    //       dictCode: record.contentType,
    //     },
    //     mode: 'multiple',
    //     placeholder: '请选择',
    //   };
    // },
    editComponent: 'Select',
    editComponentProps({ record }) {
      return {
        options: record.nameOptions,
        mode: 'multiple',
        showSearch: true,
      };
    },
  },
];
export const columnsOperation: BasicColumn[] = [
  {
    title: '手术时间',
    dataIndex: 'recordTime',
    width: 120,
    edit: true,
    editable: true,
    editComponent: 'DatePicker',
    // 默认必填校验
    editRule: true,
    editComponentProps: {
      placeholder: '请选择时间',
      format: 'YYYY-MM-DD',
      valueFormat: 'YYYY-MM-DD',
      getPopupContainer: () => document.body,
    },
  },
  {
    title: '名称',
    dataIndex: 'singleName',
    width: 100,
    edit: true,
    editable: true,
    editComponent: 'Input',
    // 默认必填校验
    editRule: true,
    editComponentProps: {
      placeholder: '请输入手术名称',
    },
  },
  {
    title: '备注',
    dataIndex: 'remark',
    width: 200,
    edit: true,
    editable: true,
    editComponent: 'Input',
    // 默认必填校验
    editRule: true,
    editComponentProps: {
      placeholder: '请输入备注',
    },
  },
];
export const columnsContagious: BasicColumn[] = [
  {
    title: '诊断名称',
    dataIndex: 'contentType',
    width: 90,
    edit: true,
    editable: true,
    editComponent: 'ApiSelect',
    // 默认必填校验
    editRule: true,
    editComponentProps: {
      api: listDictModel,
      params: {
        dictCode: 'pb_epidemic',
      },
      placeholder: '请选择',
      getPopupContainer: () => document.body,
      filterOption: false,
      showSearch: false,
    },
  },
  {
    title: '开始时间',
    dataIndex: 'startTime',
    width: 100,
    edit: true,
    editable: true,
    editComponent: 'DatePicker',
    // 默认必填校验
    editRule: true,
    editComponentProps: {
      placeholder: '请选择时间',
      format: 'YYYY-MM-DD',
      valueFormat: 'YYYY-MM-DD',
      getPopupContainer: () => document.body,
    },
  },
  {
    title: '结束时间',
    dataIndex: 'endTime',
    width: 100,
    edit: true,
    editable: true,
    editComponent: 'DatePicker',
    // 默认必填校验
    editRule: true,
    editComponentProps: ({ record }) => {
      return {
        placeholder: '请选择时间',
        format: 'YYYY-MM-DD',
        valueFormat: 'YYYY-MM-DD',
        getPopupContainer: () => document.body,
        disabledDate: current => {
          return current < dayjs(record.startTime).subtract(1, 'day').endOf('day');
        },
      };
    },
  },
  {
    title: '当前状态',
    dataIndex: 'status',
    width: 90,
    edit: true,
    editable: true,
    editComponent: 'ApiSelect',
    // 默认必填校验
    editRule: true,
    editComponentProps: {
      api: listDictModel,
      params: {
        dictCode: 'contagious',
      },
      placeholder: '请选择',
      getPopupContainer: () => document.body,
    },
  },
  {
    title: '备注',
    dataIndex: 'remark',
    width: 100,
    edit: true,
    editable: true,
    editComponent: 'Input',
  },
];

export const columnsMulti: BasicColumn[] = [
  {
    title: '诊断类型',
    dataIndex: 'type',
    ifShow: false,
  },
  {
    title: '名称数组',
    dataIndex: 'nameOptions',
    ifShow: false,
  },
  {
    title: '诊断类型字典默认值',
    dataIndex: 'typeDict',
    ifShow: false,
  },
  {
    title: '诊断类型',
    dataIndex: 'contentType',
    width: 80,
    edit: true,
    editable: true,
    editComponent: 'Select',
    // 默认必填校验
    editRule: true,
    editComponentProps: ({ record }) => {
      return {
        options: record.typeOptions,
        placeholder: '请选择',
        getPopupContainer: () => document.body,
        filterOption: false,
        showSearch: false,
        // 尽量不要在 此处使用 onChange,不然会有 warning 错误
        // onChange: async data => {
        //   console.log('🚀 ~ onChange file: data.ts:99 ~ data:', data);
        //   const res = await listDictModel({ dictCode: data });
        //   // console.log('🚀 ~ file: data.ts:99 ~ res:', res);
        //   record.nameOptions = res;
        //   record.name = [];
        // },
      };
    },
  },
  {
    title: '名称',
    dataIndex: 'name',
    width: 180,
    edit: true,
    editable: true,
    editComponent: 'Select',
    editComponentProps({ record }) {
      return {
        options: record.nameOptions,
        mode: 'multiple',
      };
    },
  },
];

export const columnsOther: BasicColumn[] = [
  {
    title: '诊断结果',
    dataIndex: 'remark',
    width: 220,
    edit: true,
    editable: true,
    editComponent: 'Input',
    editComponentProps: {
      placeholder: '请输入诊断结果',
    },
  },
];
