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

export const BasicCnt = {
  title: '基本信息',
  icon: 'icon-xt-edit_default',
  type: 'basic',
  data: [
    { field: 'setUpHospital', label: '建立医院', value: '' },
    { field: 'puncture', label: '穿刺体侧', value: '', dict: true },
    { field: 'location', label: '手术部位', value: '' },
    { field: 'anastomosis', label: '吻合方式', value: '', dict: true },
    { field: 'catheterGuidance', label: '置管引导', value: '', dict: true },
    { field: 'vascularMaterial', label: '血管材料', value: '', hidden: true, dict: true },
    { field: 'updatorName', label: '记录人', value: '' },
    { field: 'accessReturn', label: '转归记录', value: '', span: 12 },
  ],
};

export const DictCommon = {
  basic: {
    va_type_avf: 'va_type_avf',
    va_type_avg: 'va_type_avg',
    va_type_ncc: 'va_type_ncc',
    va_type_tcc: 'va_type_tcc',
  },
  va_type_avf: {
    loc: 'va_avf_loc',
    arteries: 'va_avf_arteries',
    vein: 'va_avf_vein',
  },
  va_type_avg: {
    loc: 'va_avg_loc',
    arteries: 'va_avg_arteries',
    vein: 'va_avg_vein',
  },
  va_type_ncc: {
    loc: 'va_ncc_loc',
    jnjm: 'ncc_loc_jnjm',
    sg: 'ncc_loc_sg',
  },
  va_type_tcc: {
    loc: 'va_tcc_loc',
    jnjm: 'tcc_loc_jnjm',
    jwjm: 'tcc_loc_jwjm',
    sg: 'tcc_loc_sg',
  },
};
// 通路转归 Form 表单
export const dataFormSchemaAccessReturn: FormSchema[] = [
  {
    label: '类型',
    field: 'accessType',
    component: 'PlainText',
    componentProps: {
      placeholder: '请输入类型',
    },
  },
  {
    label: '建立时间',
    field: 'accessSetUpTime',
    component: 'PlainText',
    componentProps: {
      placeholder: '请输入类型',
    },
  },
  {
    label: '转归日期',
    field: 'returnTime',
    required: true,
    component: 'DatePicker',
    componentProps: ({ formModel }) => {
      return {
        placeholder: '请输入转归日期',
        getPopupContainer: () => document.body,
        valueFormat: 'YYYY-MM-DD',
        disabledDate: current => {
          return current < dayjs(formModel.accessSetUpTime).subtract(1, 'day').endOf('day');
        },
      };
    },
    colProps: {
      span: 24,
    },
  },
  {
    label: '使用时间',
    field: 'useTime',
    component: 'PlainText',
    componentProps: ({ formModel }) => {
      formModel.useTime = dayjs(formModel.returnTime).diff(formModel.accessSetUpTime, 'day') + '天';
    },
  },
  {
    label: '转归原因',
    field: 'returnCause',
    component: 'ApiSelect',
    componentProps: {
      api: listDictModel,
      params: {
        dictCode: 'va_return',
      },
    },
    colProps: {
      span: 24,
    },
  },
];

// 通路转归 Form 表单
export const dataFormSchemaVascularAccess: FormSchema[] = [
  {
    label: '类型',
    field: 'accessType',
    component: 'PlainText',
    show: false,
    componentProps: {
      placeholder: '请输入类型',
    },
    defaultValue: 'va_type_avf',
  },
  {
    label: '建立时间',
    field: 'setUpTime',
    required: true,
    component: 'DatePicker',
    componentProps: {
      placeholder: '请输入建立时间',
      getPopupContainer: () => document.body,
      valueFormat: 'YYYY-MM-DD',
      format: 'YYYY-MM-DD',
    },
  },
  {
    label: '建立医院',
    field: 'setUpHospital',
    required: true,
    component: 'Input',
    componentProps: {
      placeholder: '请输入建立医院名称',
    },
  },
  {
    label: '血管材料(AVG)',
    field: 'vascularMaterial',
    required: true,
    component: 'ApiSelect',
    ifShow: ({ values }) => {
      return values.accessType == DictCommon.basic.va_type_avg;
    },
    componentProps: {
      api: listDictModel,
      params: {
        dictCode: 'va_material',
      },
      placeholder: '请输入血管材料',
    },
  },
  {
    label: '穿刺体侧',
    field: 'puncture',
    required: true,
    component: 'ApiRadioGroup',
    componentProps: {
      api: listDictModel,
      params: {
        dictCode: 'va_puncture',
      },
    },
  },
  {
    label: '手术部位 (位置)',
    field: 'location',
    required: true,
    component: 'ApiRadioGroup',
    componentProps: ({ formModel }) => {
      console.log(formModel['accessType']);
      return {
        api: listDictModel,
        params: {
          dictCode: DictCommon[formModel['accessType']]['loc'],
        },
      };
    },
  },
  {
    label: '手术部位 (动脉)',
    field: 'arteries',
    required: true,
    component: 'ApiRadioGroup',
    componentProps: ({ formModel }) => {
      return {
        api: listDictModel,
        params: {
          dictCode: DictCommon[formModel['accessType']]['arteries'],
        },
      };
    },
    ifShow: ({ values }) => {
      console.log('🚀 ~ file: data.ts:191 ~ values:', values);

      return (
        values.accessType == DictCommon.basic.va_type_avf ||
        values.accessType == DictCommon.basic.va_type_avg
      );
    },
  },
  {
    label: '手术部位 (静脉)',
    field: 'vein',
    required: true,
    component: 'ApiRadioGroup',
    componentProps: ({ formModel }) => {
      return {
        api: listDictModel,
        params: {
          dictCode: DictCommon[formModel['accessType']]['vein'],
        },
      };
    },
    ifShow: ({ values }) => {
      return (
        values.accessType == DictCommon.basic.va_type_avf ||
        values.accessType == DictCommon.basic.va_type_avg
      );
    },
  },

  {
    label: '路径',
    field: 'path',
    required: true,
    component: 'ApiRadioGroup',
    componentProps: ({ formModel }) => {
      return {
        api: listDictModel,
        params: {
          dictCode: formModel['location'],
        },
      };
    },
    ifShow: ({ values }) => {
      return (
        (values.accessType == DictCommon.basic.va_type_ncc ||
          values.accessType == DictCommon.basic.va_type_tcc) &&
        (values['location'] == DictCommon.va_type_ncc.jnjm ||
          values['location'] == DictCommon.va_type_ncc.sg ||
          values['location'] == DictCommon.va_type_tcc.jnjm ||
          values['location'] == DictCommon.va_type_tcc.sg)
      );
    },
  },
  {
    label: '吻合方式',
    field: 'anastomosis',
    required: true,
    component: 'ApiRadioGroup',
    componentProps: {
      api: listDictModel,
      params: {
        dictCode: 'va_anastomosis',
      },
    },
    ifShow: ({ values }) => {
      console.log('🚀 ~ file: data.ts:256 ~ values:', values);
      console.log(
        '🚀 ~ file: data.ts:254 ~ values.accessType == DictCommon.basic.va_type_avf',
        values.accessType == DictCommon.basic.va_type_avf ||
          values.accessType == DictCommon.basic.va_type_avg,
      );
      return (
        values.accessType == DictCommon.basic.va_type_avf ||
        values.accessType == DictCommon.basic.va_type_avg
      );
    },
  },
  {
    label: '置管引导',
    field: 'catheterGuidance',
    required: true,
    component: 'ApiRadioGroup',
    componentProps: {
      api: listDictModel,
      params: {
        dictCode: 'va_guidance',
      },
    },
    ifShow: ({ values }) => {
      return (
        values.accessType == DictCommon.basic.va_type_ncc ||
        values.accessType == DictCommon.basic.va_type_tcc
      );
    },
  },
];

export const columnsComplication: BasicColumn[] = [
  {
    title: '发生时间',
    dataIndex: 'occurredTime',
    width: 200,
    editRow: true,
    editComponent: 'DatePicker',
    // 默认必填校验
    editRule: true,
    editComponentProps: {
      showTime: true,
      valueFormat: 'YYYY-MM-DD HH:mm:ss',
      format: 'YYYY-MM-DD HH:mm:ss',
      getPopupContainer: () => document.body,
    },
  },
  {
    title: '并发症名称',
    dataIndex: 'name',
    width: 220,
    editRow: true,
    editComponent: 'ApiSelect',
    // 默认必填校验
    editRule: true,
    editComponentProps: {
      api: listDictModel,
      params: {
        dictCode: 'va_comp',
      },
    },
  },
  {
    title: '说明',
    dataIndex: 'remark',
    editRow: true,
    editComponent: 'Input',
  },
];
