import {
  auditColumns,
  createCrudOption,
  packageOptions,
  priceUnitOptions,
  textRule,
} from './common';

export const config = {
  title: '常用货物',
  permission: 'common_cargo',
  exportUrl: '/blade-transport/common-cargo/export-common-cargo',
  exportName: '常用货物',
  importUrl: '/blade-transport/common-cargo/import-common-cargo',
  templateUrl: '/blade-transport/common-cargo/export-template',
  enableAllDept: false,
};

export const option = createCrudOption([
  {
    label: '一级货物类型',
    prop: 'firstCargoTypeName',
    formslot: true,
    search: true,
    searchOrder: 3,
    minWidth: 150,
    editDisabled: true,
    rules: [{ required: true, message: '请选择一级货物类型', trigger: 'change' }],
  },
  {
    label: '一级货物类型编码',
    prop: 'firstCargoTypeCode',
    hide: true,
    display: false,
    addDisplay: false,
    editDisabled: true,
  },
  {
    label: '二级货物类型',
    prop: 'secondCargoTypeName',
    formslot: true,
    search: true,
    searchOrder: 4,
    minWidth: 150,
    editDisabled: true,
    rules: [{ required: true, message: '请选择二级货物类型', trigger: 'change' }],
  },
  {
    label: '二级货物类型编码',
    prop: 'secondCargoTypeCode',
    hide: true,
    display: false,
    addDisplay: false,
    editDisabled: true,
  },
  {
    label: '货物名称',
    prop: 'cargoName',
    search: true,
    searchOrder: 1,
    minWidth: 150,
    rules: textRule('货物名称', 100, true),
  },
  {
    label: '货物编号',
    prop: 'cargoCode',
    formslot: true,
    search: true,
    searchOrder: 2,
    minWidth: 120,
    maxlength: 20,
    showWordLimit: true,
    rules: [
      { required: true, message: '请输入货物编号', trigger: 'blur' },
      { max: 20, message: '货物编号不能超过20个字符', trigger: 'blur' },
    ],
  },
  {
    label: '组织',
    prop: 'deptName',
    search: true,
    searchOrder: 5,
    minWidth: 150,
    addDisplay: false,
    editDisplay: false,
  },
  {
    label: '品牌',
    prop: 'brand',
    search: false,
    minWidth: 120,
    rules: textRule('品牌', 50),
  },
  {
    label: '包装',
    prop: 'packageType',
    type: 'select',
    dicData: packageOptions,
    minWidth: 100,
  },
  {
    label: '货值',
    prop: 'cargoValue',
    formslot: true,
    minWidth: 120,
    rules: [
      {
        validator: (rule, value, callback) => {
          if (value === undefined || value === null || value === '') {
            callback();
            return;
          }
          if (!/^\d+(\.\d{1,2})?$/.test(String(value))) {
            callback(new Error('货值只能输入数字，最多保留2位小数'));
            return;
          }
          callback();
        },
        trigger: 'blur',
      },
    ],
  },
  {
    label: '计价单位',
    prop: 'priceUnit',
    type: 'select',
    dicData: priceUnitOptions,
    display: false,
    minWidth: 120,
  },
  {
    label: '规格',
    prop: 'specification',
    minWidth: 120,
    rules: textRule('规格', 50),
  },
  {
    label: '型号',
    prop: 'model',
    minWidth: 120,
    rules: textRule('型号', 50),
  },
  {
    label: '说明',
    prop: 'descriptionOne',
    minWidth: 160,
    rules: textRule('说明', 100),
  },
  {
    label: '数据来源',
    prop: 'dataSource',
    minWidth: 120,
    addDisplay: false,
    editDisplay: false,
  },
  {
    label: '备注',
    prop: 'remark',
    type: 'textarea',
    minRows: 4,
    span: 24,
    hide: true,
    maxlength: 200,
    showWordLimit: true,
    rules: textRule('备注', 200),
  },
  ...auditColumns,
]);

export const excelOption = {
  submitBtn: false,
  emptyBtn: false,
  column: [
    {
      label: '导入模板',
      prop: 'excelTemplate',
      formslot: true,
      span: 24,
    },
    {
      label: 'Excel文件',
      prop: 'excelFile',
      type: 'upload',
      drag: true,
      loadText: '模板上传中，请稍等',
      span: 24,
      propsHttp: {
        res: 'data',
      },
      tip: '请上传 .xls,.xlsx 标准格式文件',
    },
  ],
};
