/**
 * 应急物资表单配置
 */
import type { FormConfig } from '@/types/basic-form';
import { validateFormTime } from '@/utils/validateFormTime';
import { NOTIFY_RANGE } from '../constant';

// 盘点任务表单信息
export const INVENTORY_TASK_FROM_CONFIG: FormConfig[] = [
  {
    label: '盘点任务名称：',
    prop: 'taskName',
    component: 'ElInput',
    componentProps: {
      placeholder: '请输入盘点任务名称',
    },
  },
  {
    label: '任务截止时间：',
    prop: 'endTime',
    component: 'ElDatePicker',
    componentProps: {
      placeholder: '请选择任务截止时间',
      type: 'datetime',
      format: 'YYYY-MM-DD HH:mm',
      dateFormat: 'MMM DD, YYYY',
      timeFormat: 'HH:mm',
      valueFormat: 'YYYY-MM-DD HH:mm',
    },
  },
];

// 盘点任务表单数据
export const INVENTORY_TASK_FROM_DATA = {
  taskName: '',
  endTime: '',
};

// 盘点任务表单规则
export const INVENTORY_TASK_FROM_RULES = {
  taskName: [{ required: true, message: '请输入盘点任务名称', trigger: 'blur' }],
  endTime: [
    { required: true, message: '请选择任务截止时间', trigger: 'change' },
    { validator: validateFormTime, trigger: 'change' },
  ],
};

const BASIC_EMERGENCY_ITEM_FROM_CONFIG = {
  REQUIRED_QUANTITY: {
    label: '应备数量：',
    prop: 'requiredQuantity',
    slot: 'requiredQuantity',
  },
  CURRENT_QUANTITY: {
    label: '当前数量：',
    prop: 'currentQuantity',
    slot: 'currentQuantity',
  },
  UNIT: {
    label: '数量单位：',
    prop: 'unit',
    component: 'ElInput',
    componentProps: {
      placeholder: '请输入数量单位',
    },
  },
  PARK: {
    label: '园区：',
    prop: 'park',
    slot: 'park',
  },
  LOCATION: {
    label: '地点：',
    prop: 'location',
    slot: 'location',
  },
  KEEPER_NAME: {
    label: '保管人：',
    prop: 'keeperName',
    slot: 'keeperName',
  },
  EXPIRATION_DATE: {
    label: '使用期限：',
    prop: 'expirationDate',
    component: 'ElDatePicker',
    componentProps: {
      placeholder: '请选择使用期限',
      type: 'date',
      format: 'YYYY-MM-DD',
      valueFormat: 'YYYY-MM-DD',
    },
  },
  REMARK: {
    label: '备注：',
    prop: 'remark',
    component: 'ElInput',
    componentProps: {
      placeholder: '请输入备注',
      type: 'textarea',
      rows: 5,
    },
  },
};

export const ADD_EMERGENCY_ITEM_FROM_CONFIG: FormConfig[] = [
  {
    label: '应急类型：',
    prop: 'emergencyType',
    slot: 'emergencyType',
  },
  {
    label: '物资类型：',
    prop: 'supplyType',
    slot: 'supplyType',
  },
  {
    label: '应急物资名称：',
    prop: 'supplyName',
    component: 'ElInput',
    componentProps: {
      placeholder: '请输入应急物资名称',
    },
  },
  BASIC_EMERGENCY_ITEM_FROM_CONFIG.REQUIRED_QUANTITY,
  BASIC_EMERGENCY_ITEM_FROM_CONFIG.CURRENT_QUANTITY,
  BASIC_EMERGENCY_ITEM_FROM_CONFIG.UNIT,
  BASIC_EMERGENCY_ITEM_FROM_CONFIG.PARK,
  BASIC_EMERGENCY_ITEM_FROM_CONFIG.LOCATION,
  BASIC_EMERGENCY_ITEM_FROM_CONFIG.KEEPER_NAME,
  BASIC_EMERGENCY_ITEM_FROM_CONFIG.EXPIRATION_DATE,
  BASIC_EMERGENCY_ITEM_FROM_CONFIG.REMARK,
];

export const EDIT_EMERGENCY_ITEM_FROM_CONFIG: FormConfig[] = [
  {
    label: '应急类型：',
    prop: 'emergencyTypeName',
    component: 'ElInput',
    componentProps: {
      disabled: true,
      placeholder: '请输入应急类型',
    },
  },
  {
    label: '物资类型：',
    prop: 'supplyTypeName',
    component: 'ElInput',
    componentProps: {
      disabled: true,
      placeholder: '请输入物资类型',
    },
  },
  {
    label: '应急物资名称：',
    prop: 'supplyName',
    component: 'ElInput',
    componentProps: {
      placeholder: '请输入应急物资名称',
      disabled: true,
    },
  },
  BASIC_EMERGENCY_ITEM_FROM_CONFIG.REQUIRED_QUANTITY,
  BASIC_EMERGENCY_ITEM_FROM_CONFIG.CURRENT_QUANTITY,
  BASIC_EMERGENCY_ITEM_FROM_CONFIG.UNIT,
  BASIC_EMERGENCY_ITEM_FROM_CONFIG.PARK,
  BASIC_EMERGENCY_ITEM_FROM_CONFIG.LOCATION,
  BASIC_EMERGENCY_ITEM_FROM_CONFIG.KEEPER_NAME,
  BASIC_EMERGENCY_ITEM_FROM_CONFIG.EXPIRATION_DATE,
  BASIC_EMERGENCY_ITEM_FROM_CONFIG.REMARK,
];

export const VIEW_EMERGENCY_ITEM_FROM_CONFIG: FormConfig[] = [
  {
    label: '应急类型：',
    prop: 'emergencyTypeName',
    component: 'ElInput',
    componentProps: {
      placeholder: '请输入应急类型',
    },
  },
  {
    label: '物资类型：',
    prop: 'supplyTypeName',
    component: 'ElInput',
    componentProps: {
      placeholder: '请输入物资类型',
    },
  },
  {
    label: '应急物资名称：',
    prop: 'supplyName',
    component: 'ElInput',
    componentProps: {
      placeholder: '请输入应急物资名称',
    },
  },
  {
    label: '应备数量：',
    prop: 'requiredQuantity',
    component: 'ElInput',
    componentProps: {
      placeholder: '请输入应备数量',
    },
  },
  {
    label: '当前数量：',
    prop: 'currentQuantity',
    component: 'ElInput',
    componentProps: {
      placeholder: '请输入当前数量',
    },
  },
  BASIC_EMERGENCY_ITEM_FROM_CONFIG.UNIT,
  {
    label: '园区：',
    prop: 'parkName',
    component: 'ElInput',
    componentProps: {
      placeholder: '请输入园区',
    },
  },
  {
    label: '地点：',
    prop: 'locationName',
    component: 'ElInput',
    componentProps: {
      placeholder: '请输入地点',
    },
  },
  {
    label: '保管人：',
    prop: 'keeperName',
    component: 'ElInput',
    componentProps: {
      placeholder: '请输入保管人',
    },
  },
  BASIC_EMERGENCY_ITEM_FROM_CONFIG.EXPIRATION_DATE,
  BASIC_EMERGENCY_ITEM_FROM_CONFIG.REMARK,
];

const EMERGENCY_ITEM_DATA = {
  emergencyType: '',
  emergencyTypeName: '',
  supplyType: '',
  supplyTypeName: '',
  supplyName: '',
  requiredQuantity: null,
  currentQuantity: null,
  unit: '',
  park: '',
  location: '',
  expirationDate: '',
  remark: '',
  keeperId: null,
  keeperName: '',
};

// 盘点任务表单数据
export const ADD_EMERGENCY_ITEM_DATA = {
  ...EMERGENCY_ITEM_DATA,
};

export const EDIT_EMERGENCY_ITEM_DATA = {
  ...EMERGENCY_ITEM_DATA,
  id: null,
};

export const VIEW_EMERGENCY_ITEM_DATA = {
  ...EDIT_EMERGENCY_ITEM_DATA,
  parkName: '',
  locationName: '',
};

const BASIC_EMERGENCY_ITEM_RULES = {
  requiredQuantity: [{ required: true, message: '请输入应备数量', trigger: 'change' }],
  location: [{ required: true, message: '请选择地点', trigger: 'change' }],
  expirationDate: [{ validator: validateFormTime, trigger: 'change' }],
  keeperName: [{ required: true, message: '请选择保管人', trigger: 'change' }],
};

export const ADD_EMERGENCY_ITEM_RULES = {
  emergencyType: [{ required: true, message: '请选择应急类型', trigger: 'change' }],
  supplyType: [{ required: true, message: '请选择物资类型', trigger: 'change' }],
  supplyName: [{ required: true, message: '请输入应急物资名称', trigger: 'change' }],
  park: [{ required: true, message: '请选择园区', trigger: 'change' }],
  ...BASIC_EMERGENCY_ITEM_RULES,
};

export const EDIT_EMERGENCY_ITEM_RULES = {
  ...BASIC_EMERGENCY_ITEM_RULES,
};

// 导出报废记录表单配置
export const EXPORT_DISCARD_FROM_CONFIG: FormConfig[] = [
  {
    label: '报废时间段：',
    prop: 'discardTime',
    slot: 'discardTime',
  },
];

// 导出报废记录数据
export const EXPORT_DISCARD_FROM_DATA = {
  discardTime: [],
};

// 导出报废记录规则
export const EXPORT_DISCARD_FROM_RULES = {
  discardTime: [{ required: true, message: '请输入报废时间段', trigger: 'change' }],
};

// 物资报废单数据
export const SUPPLIES_DISCARD_FROM_CONFIG: FormConfig[] = [
  {
    label: '报废数量：',
    prop: 'quantity',
    slot: 'quantity',
  },
  {
    label: '报废理由：',
    prop: 'scrapReason',
    slot: 'scrapReason',
  },
  {
    label: '报废照片：',
    prop: 'scrapImage',
    slot: 'scrapImage',
  },
];

// 物资报废单数据
export const SUPPLIES_DISCARD_FROM_DATA = {
  quantity: null,
  scrapReason: '',
  scrapImage: '',
};

// 物资报废单规则
export const SUPPLIES_DISCARD_FROM_RULES = {
  quantity: [{ required: true, message: '请输入报废数量', trigger: 'blur' }],
  scrapReason: [{ required: true, message: '请输入报废理由', trigger: 'blur' }],
};

// 物资申领计划表单配置
export const SUPPLY_REQUEST_FORM_CONFIG: FormConfig[] = [
  {
    label: '物资申领计划：',
    prop: 'planName',
    component: 'ElInput',
    componentProps: {
      placeholder: '请输入物资申领计划',
    },
  },
  {
    label: '采购日期：',
    prop: 'purchaseDate',
    component: 'ElDatePicker',
    componentProps: {
      placeholder: '请选择采购日期',
      type: 'date',
      format: 'YYYY-MM-DD',
      valueFormat: 'YYYY-MM-DD',
    },
  },
];

// 物资申领计划表单数据
export const SUPPLY_REQUEST_FORM_DATA = {
  planName: '',
  purchaseDate: '',
};

// 物资申领计划表单规则
export const SUPPLY_REQUEST_FORM_RULES = {
  planName: [{ required: true, message: '请输入物资申领计划', trigger: 'blur' }],
};

// 发起采购表单配置
export const START_PURCHASE_FORM_CONFIG: FormConfig[] = [
  {
    label: '采购日期：',
    prop: 'purchaseDate',
    component: 'ElDatePicker',
    componentProps: {
      placeholder: '请选择采购日期',
      type: 'date',
      format: 'YYYY-MM-DD',
      valueFormat: 'YYYY-MM-DD',
    },
  },
];

// 发起采购表单数据
export const START_PURCHASE_FORM_DATA = {
  purchaseDate: '',
};

// 发起采购表单规则
export const START_PURCHASE_FORM_RULES = {
  purchaseDate: [{ required: true, message: '请选择采购日期', trigger: 'change' }],
};

// 物资领用通知表单配置
export const NOTIFY_DEPARTMENT_FORM_CONFIG: FormConfig[] = [
  {
    label: '通知范围：',
    prop: 'noticeScope',
    slot: 'noticeScope',
  },
  {
    label: '领用时间：',
    prop: 'requestTime',
    component: 'ElDatePicker',
    componentProps: {
      placeholder: '请选择领用时间',
      type: 'date',
      format: 'YYYY-MM-DD',
      valueFormat: 'YYYY-MM-DD',
    },
  },
  {
    label: '领用地点：',
    prop: 'requestLocation',
    component: 'ElInput',
    componentProps: {
      placeholder: '请输入领用地点',
    },
  },
];

// 物资领用通知表单数据
export const NOTIFY_DEPARTMENT_FORM_DATA = {
  noticeScope: NOTIFY_RANGE.ALL,
  requestTime: '',
  requestLocation: '',
};

// 物资领用通知表单规则
export const NOTIFY_DEPARTMENT_FORM_RULES = {
  noticeScope: [{ required: true, message: '请选择通知范围', trigger: 'change' }],
  requestTime: [{ required: true, message: '请选择领用时间', trigger: 'change' }],
  requestLocation: [{ required: true, message: '请输入领用地点', trigger: 'blur' }],
};
