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

export const config = {
  title: '常用线路',
  permission: 'common_route',
  exportUrl: '/blade-transport/common-route/export-common-route',
  exportName: '常用线路',
  importUrl: '/blade-transport/common-route/import-common-route',
  templateUrl: '/blade-transport/common-route/export-template',
  enableAllDept: false,
};

export const option = createCrudOption([
  {
    label: '线路名称',
    prop: 'routeName',
    span: 12,
    minWidth: 150,
    overHidden: true,
    rules: textRule('线路名称', 100, true),
  },
  {
    label: '线路编号',
    prop: 'routeCode',
    minWidth: 120,
    addDisplay: false,
    editDisabled: true,
  },
  {
    label: '发货地',
    prop: 'departureName',
    minWidth: 140,
    addDisplay: false,
    editDisplay: false,
  },
  {
    label: '发货地址',
    prop: 'departureAddress',
    formslot: true,
    span: 24,
    minWidth: 220,
    overHidden: true,
    rules: textRule('发货地址', 255, true),
  },
  {
    label: '发货经度',
    prop: 'departureLongitude',
    type: 'number',
    precision: 6,
    minWidth: 120,
    hide: true,
    addDisplay: false,
    editDisplay: false,
  },
  {
    label: '发货纬度',
    prop: 'departureLatitude',
    type: 'number',
    precision: 6,
    minWidth: 120,
    hide: true,
    addDisplay: false,
    editDisplay: false,
  },
  {
    label: '发货联系人',
    prop: 'departureContact',
    minWidth: 120,
    rules: textRule('发货联系人', 50),
  },
  {
    label: '发货联系方式',
    prop: 'departurePhone',
    minWidth: 140,
    rules: [phoneRule('发货联系方式'), ...textRule('发货联系方式', 50)],
  },
  {
    label: '收货地',
    prop: 'arrivalName',
    minWidth: 140,
    addDisplay: false,
    editDisplay: false,
  },
  {
    label: '收货地址',
    prop: 'arrivalAddress',
    formslot: true,
    span: 24,
    minWidth: 220,
    overHidden: true,
    rules: textRule('收货地址', 255, true),
  },
  {
    label: '收货经度',
    prop: 'arrivalLongitude',
    type: 'number',
    precision: 6,
    minWidth: 120,
    hide: true,
    addDisplay: false,
    editDisplay: false,
  },
  {
    label: '收货纬度',
    prop: 'arrivalLatitude',
    type: 'number',
    precision: 6,
    minWidth: 120,
    hide: true,
    addDisplay: false,
    editDisplay: false,
  },
  {
    label: '收货联系人',
    prop: 'arrivalContact',
    minWidth: 120,
    rules: textRule('收货联系人', 50),
  },
  {
    label: '收货联系方式',
    prop: 'arrivalPhone',
    minWidth: 140,
    rules: [phoneRule('收货联系方式'), ...textRule('收货联系方式', 50)],
  },
  {
    label: '备注',
    prop: 'remark',
    type: 'textarea',
    minRows: 4,
    span: 24,
    minWidth: 180,
    maxlength: 500,
    showWordLimit: true,
    rules: textRule('备注', 500),
  },
  {
    label: '组织',
    prop: 'deptName',
    minWidth: 150,
    addDisplay: false,
    editDisplay: false,
  },
  // 搜索字段独立于表格和表单字段，避免筛选配置影响数据展示和编辑布局。
  {
    label: '线路名称',
    prop: 'searchRouteName',
    searchProp: 'routeName',
    search: true,
    searchOrder: 7,
    searchPlaceholder: '请输入',
    hide: true,
    display: false,
    addDisplay: false,
    editDisplay: false,
    viewDisplay: false,
  },
  {
    label: '线路编号',
    prop: 'searchRouteCode',
    searchProp: 'routeCode',
    search: true,
    searchOrder: 6,
    searchPlaceholder: '请输入',
    hide: true,
    display: false,
    addDisplay: false,
    editDisplay: false,
    viewDisplay: false,
  },
  {
    label: '发货地',
    prop: 'searchDepartureName',
    searchProp: 'departureName',
    search: true,
    searchOrder: 5,
    searchPlaceholder: '请输入',
    hide: true,
    display: false,
    addDisplay: false,
    editDisplay: false,
    viewDisplay: false,
  },
  {
    label: '发货地址',
    prop: 'searchDepartureAddress',
    searchProp: 'departureAddress',
    search: true,
    searchOrder: 4,
    searchPlaceholder: '请输入',
    hide: true,
    display: false,
    addDisplay: false,
    editDisplay: false,
    viewDisplay: false,
  },
  {
    label: '收货地',
    prop: 'searchArrivalName',
    searchProp: 'arrivalName',
    search: true,
    searchOrder: 3,
    searchPlaceholder: '请输入',
    hide: true,
    display: false,
    addDisplay: false,
    editDisplay: false,
    viewDisplay: false,
  },
  {
    label: '收货地址',
    prop: 'searchArrivalAddress',
    searchProp: 'arrivalAddress',
    search: true,
    searchOrder: 2,
    searchPlaceholder: '请输入',
    hide: true,
    display: false,
    addDisplay: false,
    editDisplay: false,
    viewDisplay: false,
  },
  {
    label: '组织',
    prop: 'searchDeptId',
    searchProp: 'deptId',
    search: true,
    searchOrder: 1,
    searchType: 'cascader',
    searchPlaceholder: '请选择',
    hide: true,
    display: false,
    addDisplay: false,
    editDisplay: false,
    viewDisplay: false,
    dicData: [],
    props: {
      label: 'label',
      value: 'value',
      children: 'children',
    },
    checkStrictly: true,
    emitPath: false,
    showAllLevels: false,
    filterable: true,
  },
  ...auditColumns
    .filter(column => column.prop !== 'createUserName')
    .map(column =>
      ['createTime', 'updateTime'].includes(column.prop) ? { ...column, minWidth: 190 } : column
    )
    .sort(
      (first, second) =>
        ['updateUserName', 'updateTime', 'createTime'].indexOf(first.prop) -
        ['updateUserName', 'updateTime', 'createTime'].indexOf(second.prop)
    ),
]);

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 标准格式文件',
    },
  ],
};
