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

const templateTypeOptions = [
  { label: '运输计划', value: '运输计划' },
  { label: '运单', value: '运单' },
];

export const config = {
  title: '发货模板',
  permission: 'shipping_template',
  exportUrl: '/blade-transport/shipping-template/export-shipping-template',
  exportName: '发货模板',
  enableAllDept: false,
  enableProjectSelect: true,
  enableAttachmentTable: true,
  enableTransportPlanForm: true,
  enableTemplateCodePreview: true,
  attachmentTitle: '附件',
  defaultForm: {
    templateType: '运输计划',
  },
  transportFormRequiredFields: [
    ['projectName', '项目'],
    ['contractName', '客户合同'],
    ['transportType', '运输方式'],
    ['departureAddress', '发货地址'],
    ['arrivalAddress', '收货地址'],
  ],
  actions: ['copy'],
  operations: [
    {
      action: 'createFromTemplate',
      label: '从模板新建',
      permission: 'shipping_template_add',
    },
  ],
};

export const option = {
  ...createCrudOption([
    {
      label: '',
      prop: 'templateInfoTitle',
      formslot: true,
      span: 24,
      order: 400,
      hide: true,
      labelWidth: 0,
    },
    {
      label: '模板编号',
      prop: 'templateCode',
      search: true,
      searchOrder: 4,
      span: 8,
      order: 390,
      minWidth: 170,
      disabled: true,
      placeholder: '系统自动生成',
    },
    {
      label: '模板名称',
      prop: 'templateName',
      search: true,
      searchOrder: 3,
      span: 8,
      order: 380,
      minWidth: 150,
      rules: textRule('模板名称', 50, true),
    },
    {
      label: '模板类型',
      prop: 'templateType',
      type: 'select',
      search: true,
      searchOrder: 2,
      span: 8,
      order: 370,
      dicData: templateTypeOptions,
      minWidth: 120,
      rules: selectRule('模板类型'),
    },
    {
      label: '备注',
      prop: 'remark',
      type: 'textarea',
      minRows: 3,
      span: 24,
      order: 360,
      minWidth: 180,
      maxlength: 200,
      showWordLimit: true,
      rules: textRule('备注', 200),
    },
    {
      label: '',
      prop: 'basicInfoTitle',
      formslot: true,
      span: 24,
      order: 350,
      hide: true,
      labelWidth: 0,
    },
    {
      label: '项目',
      prop: 'projectName',
      formslot: true,
      search: true,
      searchOrder: 1,
      span: 8,
      order: 340,
      minWidth: 150,
      rules: textRule('项目', 100, true),
    },
    {
      label: '客户合同',
      prop: 'contractName',
      formslot: true,
      span: 8,
      order: 330,
      minWidth: 160,
      rules: textRule('客户合同', 100, true),
    },
    {
      label: '运输方式',
      prop: 'transportType',
      type: 'select',
      span: 8,
      order: 320,
      dicData: transportTypeOptions,
      minWidth: 130,
      rules: selectRule('运输方式'),
    },
    {
      label: '',
      prop: 'shippingInfoTitle',
      formslot: true,
      span: 24,
      order: 310,
      hide: true,
      labelWidth: 0,
    },
    {
      label: '发货地址',
      prop: 'departureAddress',
      formslot: true,
      span: 24,
      order: 300,
      minWidth: 220,
      rules: textRule('发货地址', 255, true),
    },
    {
      label: '收货地址',
      prop: 'arrivalAddress',
      formslot: true,
      span: 24,
      order: 290,
      minWidth: 220,
      rules: textRule('收货地址', 255, true),
    },
    {
      label: '',
      prop: 'goodsInfoTitle',
      formslot: true,
      span: 24,
      order: 280,
      hide: true,
      labelWidth: 0,
    },
    {
      label: '',
      prop: 'goodsJson',
      type: 'textarea',
      formslot: true,
      span: 24,
      order: 270,
      hide: true,
      labelWidth: '0px',
      className: 'business-crud-page__full-form-item',
    },
    {
      label: '',
      prop: 'attachmentTitle',
      formslot: true,
      span: 24,
      order: 260,
      hide: true,
      labelWidth: 0,
    },
    {
      label: '',
      prop: 'attachmentsJson',
      type: 'textarea',
      formslot: true,
      span: 24,
      order: 250,
      hide: true,
      labelWidth: '0px',
      className: 'business-crud-page__full-form-item',
    },
    { label: '项目ID', prop: 'projectId', hide: true, display: false },
    { label: '客户合同ID', prop: 'contractId', hide: true, display: false },
    { label: '发货地', prop: 'departureName', hide: true, display: false },
    { label: '发货联系人', prop: 'departureContact', hide: true, display: false },
    { label: '发货联系方式', prop: 'departurePhone', hide: true, display: false },
    { label: '收货地', prop: 'arrivalName', hide: true, display: false },
    { label: '收货联系人', prop: 'arrivalContact', hide: true, display: false },
    { label: '收货联系方式', prop: 'arrivalPhone', hide: true, display: false },
    { label: '所属组织', prop: 'deptName', minWidth: 150, addDisplay: false, editDisplay: false },
    ...auditColumns,
  ]),
  dialogWidth: '96%',
};
