/**
 * 灾害预警信息表单配置
 */
import type { FormConfig } from '@/types/basic-form';
import { validateFormTime } from '@/utils/validateFormTime';
import { FIX_STATUS_OPTIONS_DISPOSAL_RECTIFICATION } from '../constant';
// 通用表单信息
const BASIC_FROM_CONFIG = {};

// 通用处置管理表单信息
const DISPOSAL_MANAGEMENT_BASIC_FROM_CONFIG: FormConfig[] = [
  {
    label: '应完成上报时间：',
    prop: 'dueCompleteTime',
    component: 'ElDatePicker',
    componentProps: {
      placeholder: '请选择应完成上报时间',
      type: 'datetime',
      format: 'YYYY-MM-DD HH:mm:ss',
      dateFormat: 'MMM DD, YYYY',
      timeFormat: 'HH:mm:ss',
      valueFormat: 'YYYY-MM-DD HH:mm:ss',
    },
  },
  {
    label: '上报要求：',
    prop: 'reportRequirement',
    component: 'ElInput',
    componentProps: {
      type: 'textarea',
      rows: 5,
      placeholder: '请输入上报要求',
      maxlength: 1000,
      showWordLimit: true,
    },
  },
  {
    label: '上报人员：',
    prop: 'userGroupList',
    slot: 'userGroupList',
  },
  {
    label: '是否推送：',
    prop: 'isPush',
    slot: 'isPush',
  },
  {
    label: '创建人：',
    prop: 'createdByName',
    component: 'ElInput',
    componentProps: {
      disabled: true,
    },
  },
];

// 处置管理表单信息（任务项）
export const DISPOSAL_MANAGEMENT_TASK_FROM_CONFIG: FormConfig[] = [
  {
    label: '任务名称：',
    prop: 'taskName',
    component: 'ElInput',
    componentProps: {
      placeholder: '请输入任务名称',
    },
  },
  {
    label: '上报部门：',
    prop: 'deptIds',
    slot: 'deptIds',
  },
  ...DISPOSAL_MANAGEMENT_BASIC_FROM_CONFIG,
];

// 处置管理表单信息（列表项）
export const DISPOSAL_MANAGEMENT_ITEM_FROM_CONFIG_CREATE: FormConfig[] = [
  {
    label: '任务名称：',
    prop: 'taskName',
    component: 'ElInput',
    componentProps: {
      placeholder: '请输入任务名称',
      disabled: true,
    },
  },
  {
    label: '上报部门：',
    prop: 'deptIds',
    slot: 'deptIds',
  },
  ...DISPOSAL_MANAGEMENT_BASIC_FROM_CONFIG,
];

// 处置管理表单信息（列表项）
export const DISPOSAL_MANAGEMENT_ITEM_FROM_CONFIG_EDIT: FormConfig[] = [
  {
    label: '任务名称：',
    prop: 'taskName',
    component: 'ElInput',
    componentProps: {
      placeholder: '请输入任务名称',
      disabled: true,
    },
  },
  {
    label: '上报部门：',
    prop: 'deptName',
    component: 'ElInput',
    componentProps: {
      disabled: true,
    },
  },
  ...DISPOSAL_MANAGEMENT_BASIC_FROM_CONFIG,
];

// 创建损失记录表单信息通用项目
const LOSS_REPORT_ITEM_FORM_CONFIG_COMMON = {
  TASK_NAME: {
    label: '任务名称：',
    prop: 'reportTaskName',
    component: 'ElInput',
    componentProps: {
      disabled: true,
    },
  },
  IS_LOSS: {
    label: '是否损失：',
    prop: 'isLoss',
    slot: 'isLoss',
  },
  CREATED_BY: {
    label: '创建人：',
    prop: 'createdBy',
    component: 'ElInput',
    componentProps: {
      disabled: true,
    },
  },
};

// 创建损失记录表单信息（无损失）
export const LOSS_REPORT_ITEM_FORM_CONFIG_NO_LOSS: FormConfig[] = [
  LOSS_REPORT_ITEM_FORM_CONFIG_COMMON.TASK_NAME,
  LOSS_REPORT_ITEM_FORM_CONFIG_COMMON.IS_LOSS,
  LOSS_REPORT_ITEM_FORM_CONFIG_COMMON.CREATED_BY,
];

// 创建损失记录表单信息（有损失）
export const LOSS_REPORT_ITEM_FORM_CONFIG_LOSS: FormConfig[] = [
  LOSS_REPORT_ITEM_FORM_CONFIG_COMMON.TASK_NAME,
  LOSS_REPORT_ITEM_FORM_CONFIG_COMMON.IS_LOSS,
  {
    label: '损失楼号、楼层、房间号：',
    prop: 'affectedRoom',
    slot: 'affectedRoom',
  },
  {
    label: '受灾物品：',
    prop: 'affectedItems',
    component: 'ElInput',
    componentProps: {
      placeholder: '请输入受灾物品',
    },
  },
  {
    label: '受灾图片：',
    prop: 'images',
    slot: 'affectedImages',
  },
  {
    label: '损失描述：',
    prop: 'description',
    component: 'ElInput',
    componentProps: {
      placeholder: '请输入损失描述',
      type: 'textarea',
      rows: 4,
      maxlength: 1000,
      showWordLimit: true,
    },
  },
  {
    label: '影响安全评估：',
    prop: 'safetyLevel',
    slot: 'safetyLevel',
  },
  {
    label: '是否影响正常工作：',
    prop: 'isAffectWork',
    slot: 'isAffectWork',
  },
  {
    label: '损失评估金额：',
    prop: 'lossAssessmentAmount',
    slot: 'lossAssessmentAmount',
  },
  {
    label: '处置优先级：',
    prop: 'priority',
    slot: 'priority',
  },
  {
    label: '整改责任部门：',
    prop: 'responsibleDeptId',
    slot: 'responsibleDeptId',
  },
  {
    label: '整改责任人：',
    prop: 'userGroupList',
    slot: 'userGroupList',
  },
  {
    label: '是否推送：',
    prop: 'isPush',
    slot: 'isPush',
  },
  {
    label: '备注：',
    prop: 'remark',
    component: 'ElInput',
    componentProps: {
      placeholder: '请输入备注',
      type: 'textarea',
      rows: 4,
      maxlength: 1000,
      showWordLimit: true,
    },
  },
  LOSS_REPORT_ITEM_FORM_CONFIG_COMMON.CREATED_BY,
];

// 处置整改表单信息
export const DISPOSAL_RECTIFICATION_FORM_CONFIG: FormConfig[] = [
  {
    label: '整改进度：',
    prop: 'fixStatus',
    component: 'ElSelect',
    componentProps: {
      placeholder: '请选择整改进度',
    },
    selectOptions: FIX_STATUS_OPTIONS_DISPOSAL_RECTIFICATION,
  },
  {
    label: '整改措施：',
    prop: 'fixMethod',
    component: 'ElInput',
    componentProps: {
      placeholder: '请输入整改措施',
      type: 'textarea',
      rows: 3,
      maxlength: 500,
      showWordLimit: true,
    },
  },
  {
    label: '整改时限：',
    prop: 'fixDeadline',
    component: 'ElDatePicker',
    componentProps: {
      placeholder: '请选择整改时限',
      type: 'datetime',
      format: 'YYYY-MM-DD HH:mm:ss',
      dateFormat: 'MMM DD, YYYY',
      timeFormat: 'HH:mm:ss',
      valueFormat: 'YYYY-MM-DD HH:mm:ss',
    },
  },
  {
    label: '整改图片：',
    prop: 'fixImages',
    slot: 'fixImages',
  },
  {
    label: '整改材料：',
    prop: 'fixMaterials',
    slot: 'fixMaterials',
  },
  {
    label: '备注：',
    prop: 'remark',
    component: 'ElInput',
    componentProps: {
      placeholder: '请输入备注',
      type: 'textarea',
      rows: 3,
      maxlength: 500,
      showWordLimit: true,
    },
  },
  {
    label: '创建人：',
    prop: 'createdByName',
    component: 'ElInput',
    componentProps: {
      disabled: true,
    },
  },
];

// 灾后评估及重建材料表单信息
export const POST_DISASTER_MATERIAL_FORM_CONFIG: FormConfig[] = [
  {
    label: '灾后评估材料：',
    prop: 'disasterAssessMaterials',
    slot: 'disasterAssessMaterials',
  },
  {
    label: '灾后重建方案：',
    prop: 'disasterReconstructMaterials',
    slot: 'disasterReconstructMaterials',
  },
];

// 通用表单数据
const BASIC_FROM_DATA = {};
const DISPOSAL_MANAGEMENT_BASIC_FROM_DATA = {
  taskName: '',
  dueCompleteTime: '',
  reportRequirement: '',
  userGroupList: [],
  isPush: null,
  createdByName: '',
};
export const DISPOSAL_MANAGEMENT_TASK_FROM_DATA = {
  ...DISPOSAL_MANAGEMENT_BASIC_FROM_DATA,
  deptIds: [],
};
export const DISPOSAL_MANAGEMENT_TASK_FROM_DATA_EDIT = {
  ...DISPOSAL_MANAGEMENT_BASIC_FROM_DATA,
  deptName: '',
};
export const LOSS_REPORT_ITEM_FORM_DATA = {
  reportTaskName: '',
  isLoss: 1,
  buildingNo: '',
  floorNo: '',
  roomNo: '',
  affectedItems: '',
  images: [],
  description: '',
  safetyLevel: '',
  isAffectWork: null,
  estimatedLoss: null,
  responsibleDeptId: null,
  userGroupList: [],
  isPush: 1,
  priority: '',
  createdBy: '',
  remark: '',
  affectedRoom: '永远存在', //自己创造的一个数值，不要传给后端 这个数值永远存在
  uploadImages: [],
};
export const DISPOSAL_RECTIFICATION_FORM_DATA = {
  fixStatus: '',
  fixMethod: '',
  fixDeadline: '',
  fixImages: '',
  fixMaterials: '',
  remark: '',
  createdBy: null,
  createdByName: '',
  uploadImages: [],
  uploadFiles: [],
};

export const POST_DISASTER_MATERIAL_FORM_DATA = {
  disasterAssessMaterials: [],
  disasterReconstructMaterials: [],
};

// 通用表单规则
const BASIC_FROM_RULES = {};

// 处置管理通用表单规则
const DISPOSAL_MANAGEMENT_BASIC_FROM_RULES = {
  dueCompleteTime: [
    { required: true, message: '请选择应完成上报时间', trigger: 'change' },
    { validator: validateFormTime, trigger: 'change' },
  ],
  userGroupList: [{ required: true, message: '请选择上报人员', trigger: 'change' }],
  isPush: [{ required: true, message: '请选择是否推送', trigger: 'change' }],
};

// 处置管理任务项表单规则（任务项）
export const DISPOSAL_MANAGEMENT_TASK_FROM_RULES = {
  taskName: [{ required: true, message: '请输入任务名称', trigger: 'blur' }],
  deptIds: [{ required: true, message: '请选择上报部门', trigger: 'change' }],
  ...DISPOSAL_MANAGEMENT_BASIC_FROM_RULES,
};

// 处置管理列表项表单规则（列表项）
export const DISPOSAL_MANAGEMENT_ITEM_FROM_RULES_CREATE = {
  deptIds: [{ required: true, message: '请选择上报部门', trigger: 'change' }],
  ...DISPOSAL_MANAGEMENT_BASIC_FROM_RULES,
};

// 处置管理列表项表单规则（列表项）
export const DISPOSAL_MANAGEMENT_ITEM_FROM_RULES_EDIT = {
  ...DISPOSAL_MANAGEMENT_BASIC_FROM_RULES,
};

// 创建损失记录表单规则
export const LOSS_REPORT_ITEM_FROM_RULES = {
  isLoss: [{ required: true, message: '请选择是否损失', trigger: 'change' }],
  affectedRoom: [{ required: true, message: '', trigger: 'blur' }],
  buildingNo: [{ required: true, message: '请输入楼号', trigger: 'blur' }],
  floorNo: [{ required: true, message: '请输入楼层', trigger: 'blur' }],
  roomNo: [{ required: true, message: '请输入房间号', trigger: 'blur' }],
  affectedItems: [{ required: true, message: '请输入受灾物品', trigger: 'blur' }],
  description: [{ required: true, message: '请输入损失描述', trigger: 'blur' }],
  safetyLevel: [{ required: true, message: '请选择影响安全评估', trigger: 'change' }],
  isAffectWork: [{ required: true, message: '请选择是否影响正常工作', trigger: 'change' }],
  priority: [{ required: true, message: '请选择处置优先级', trigger: 'change' }],
  responsibleDeptId: [{ required: true, message: '请选择整改责任部门', trigger: 'change' }],
  userGroupList: [{ required: true, message: '请选择整改责任人', trigger: 'change' }],
  isPush: [{ required: true, message: '请选择是否推送', trigger: 'change' }],
};

// 处置整改表单规则
export const DISPOSAL_RECTIFICATION_FORM_RULES = {
  fixStatus: [{ required: true, message: '请选择整改进度', trigger: 'change' }],
  fixMethod: [{ required: true, message: '请输入整改措施', trigger: 'blur' }],
  fixDeadline: [
    { required: true, message: '请选择整改时限', trigger: 'change' },
    { validator: validateFormTime, trigger: 'change' },
  ],
};
