import { formatUpdateUserName } from '@/utils/audit';

const validateNonNegative = (rule, value, callback) => {
  if (value === undefined || value === null || value === '') {
    callback();
  } else if (Number(value) < 0) {
    callback(new Error('不能小于 0'));
  } else {
    callback();
  }
};

export const vehicleTypeDic = [
  { label: '车辆', value: '车辆' },
  { label: '船舶', value: '船舶' },
];

export const accidentNatureDic = [
  { label: '重大事故', value: '重大事故' },
  { label: '一般事故', value: '一般事故' },
  { label: '轻微事故', value: '轻微事故' },
  { label: '其他', value: '其他' },
];

export const accidentResponsibilityDic = [
  { label: '全部责任', value: '全部责任' },
  { label: '主要责任', value: '主要责任' },
  { label: '同等责任', value: '同等责任' },
  { label: '次要责任', value: '次要责任' },
  { label: '无责任', value: '无责任' },
];

export const option = {
  height: 'auto',
  calcHeight: 32,
  dialogWidth: 960,
  labelPosition: 'right',
  labelWidth: 'auto',
  searchLabelWidth: 160,
  tip: false,
  searchBtnText: '查询',
  emptyBtnText: '重置',
  saveBtnText: '提交',
  updateBtnText: '提交',
  searchShow: true,
  searchMenuSpan: 24,
  searchIcon: true,
  searchIndex: 4,
  searchMenuPosition: 'right',
  border: true,
  index: true,
  indexLabel: '序号',
  viewBtn: true,
  selection: true,
  dialogClickModal: false,
  menuWidth: 180,
  column: [
    {
      label: '车船类型',
      prop: 'vehicleType',
      type: 'radio',
      minWidth: 110,
      dicData: vehicleTypeDic,
      value: '车辆',
      search: true,
      span: 24,
      rules: [{ required: true, message: '请选择车船类型', trigger: 'change' }],
    },
    {
      label: '车牌号/船号',
      prop: 'vehicleNo',
      slot: true,
      formslot: true,
      search: true,
      minWidth: 140,
      span: 12,
      placeholder: '输入车牌号/船号查询选择',
      rules: [
        { required: true, message: '请输入车牌号/船号', trigger: 'blur' },
        { max: 30, message: '最多 30 个字符', trigger: 'blur' },
      ],
    },
    {
      label: '事故发生日期',
      prop: 'accidentDate',
      sortable: true,
      type: 'date',
      format: 'YYYY-MM-DD',
      valueFormat: 'YYYY-MM-DD',
      minWidth: 140,
      span: 12,
      placeholder: '请选择，日期选择器',
      rules: [{ required: true, message: '请选择事故发生日期', trigger: 'click' }],
    },
    {
      label: '事故发生地点',
      prop: 'accidentLocation',
      minWidth: 200,
      overHidden: true,
      span: 12,
      placeholder: '请输入，100字内',
      rules: [{ max: 100, message: '最多 100 个字符', trigger: 'blur' }],
    },
    {
      label: '事故性质',
      prop: 'accidentNature',
      type: 'select',
      dicData: accidentNatureDic,
      search: true,
      minWidth: 120,
      span: 12,
      placeholder: '请选择',
      rules: [{ required: true, message: '请选择事故性质', trigger: 'change' }],
    },
    {
      label: '事故责任',
      prop: 'accidentResponsibility',
      type: 'select',
      dicData: accidentResponsibilityDic,
      search: true,
      minWidth: 120,
      span: 12,
      placeholder: '请选择',
      rules: [{ required: true, message: '请选择事故责任', trigger: 'change' }],
    },
    {
      label: '直接经济损失',
      prop: 'directEconomicLoss',
      type: 'input',
      formslot: true,
      minWidth: 140,
      span: 12,
      placeholder: '请输入',
      rules: [{ validator: validateNonNegative, trigger: 'blur' }],
    },
    {
      label: '保险理赔金额',
      prop: 'insuranceClaimAmount',
      type: 'input',
      formslot: true,
      minWidth: 140,
      span: 12,
      placeholder: '请输入',
      rules: [{ validator: validateNonNegative, trigger: 'blur' }],
    },
    {
      label: '事故原因及损坏情况',
      prop: 'accidentReasonDamage',
      type: 'textarea',
      minRows: 4,
      span: 24,
      search: true,
      minWidth: 220,
      overHidden: true,
      placeholder: '请输入，500字以内',
      rules: [{ max: 500, message: '最多 500 个字符', trigger: 'blur' }],
    },
    {
      label: '备注',
      prop: 'remark',
      type: 'textarea',
      minRows: 3,
      span: 24,
      minWidth: 180,
      overHidden: true,
      placeholder: '请输入，200字以内',
      rules: [{ max: 200, message: '最多 200 个字符', trigger: 'blur' }],
    },
    {
      label: '附件',
      prop: 'attachments',
      span: 24,
      minWidth: 100,
      slot: true,
      formslot: true,
    },
    {
      label: '事故评定开始日期',
      prop: 'accidentAssessmentDateStart',
      type: 'date',
      format: 'YYYY-MM-DD',
      valueFormat: 'YYYY-MM-DD',
      search: true,
      hide: true,
      addDisplay: false,
      editDisplay: false,
      viewDisplay: false,
    },
    {
      label: '事故评定结束日期',
      prop: 'accidentAssessmentDateEnd',
      type: 'date',
      format: 'YYYY-MM-DD',
      valueFormat: 'YYYY-MM-DD',
      search: true,
      hide: true,
      addDisplay: false,
      editDisplay: false,
      viewDisplay: false,
    },
    {
      label: '创建时间',
      prop: 'createTime',
      sortable: true,
      type: 'date',
      format: 'YYYY-MM-DD HH:mm:ss',
      valueFormat: 'YYYY-MM-DD HH:mm:ss',
      addDisplay: false,
      editDisplay: false,
      viewDisplay: false,
      display: false,
      minWidth: 170,
    },
    {
      label: '创建时间',
      prop: 'createTimeRange',
      type: 'date',
      format: 'YYYY-MM-DD',
      valueFormat: 'YYYY-MM-DD',
      searchRange: true,
      search: true,
      hide: true,
      addDisplay: false,
      editDisplay: false,
      viewDisplay: false,
    },
    {
      label: '组织',
      prop: 'createDept',
      type: 'tree',
      dicData: [],
      props: {
        label: 'title',
        value: 'id',
      },
      checkStrictly: true,
      search: true,
      hide: true,
      addDisplay: false,
      editDisplay: false,
      viewDisplay: false,
    },
    {
      label: '更新人',
      prop: 'updateUserName',
      formatter: formatUpdateUserName,
      addDisplay: false,
      editDisplay: false,
      display: false,
      minWidth: 180,
    },
    {
      label: '更新时间',
      prop: 'updateTime',
      sortable: true,
      type: 'datetime',
      format: 'YYYY-MM-DD HH:mm:ss',
      valueFormat: 'YYYY-MM-DD HH:mm:ss',
      addDisplay: false,
      editDisplay: false,
      display: false,
      minWidth: 170,
    },
  ],
};

export const excelOption = {
  labelPosition: 'right',
  submitBtn: false,
  emptyBtn: false,
  column: [
    {
      label: '模板上传',
      prop: 'excelFile',
      type: 'upload',
      drag: true,
      loadText: '模板上传中，请稍等',
      span: 24,
      propsHttp: {
        res: 'data',
      },
      tip: '请上传 .xls,.xlsx 标准格式文件',
      action: '/blade-transport/accident-record/import-accident-record',
    },
    {
      label: '模板下载',
      prop: 'excelTemplate',
      formslot: true,
      span: 24,
    },
  ],
};
