export const initialColumns = [
  {
    label: '分组',
    minWidth: '80px',
    prop: 'group',
    required: true
  },
  {
    label: '发票类型',
    minWidth: '140px',
    prop: 'invtype',
    required: true
  },
  {
    label: '电子邮箱',
    minWidth: '140px',
    prop: 'email',
    required: true
  },
  {
    label: '订单编号',
    minWidth: '140px',
    prop: 'sequenceNo',
    required: true
  },
  {
    label: '订单平台类型',
    minWidth: '120px',
    prop: 'platform_type',
    required: true
  },
  {
    label: '开票金额',
    minWidth: '160px',
    prop: 'inv_fee',
    required: true
  },
  {
    label: '平台采购PO',
    minWidth: '160px',
    prop: 'poCode',
    required: true
  },
  {
    label: '状态',
    minWidth: '100px',
    prop: 'status',
    required: false
  },
  {
    label: '备注',
    minWidth: '160px',
    prop: 'remark',
    required: false
  }
 ] as const

export const columns = [{ prop: "index", width: "50", fixed: "left", label: "序号" }, ...initialColumns]

export const getPropertyAsLabel = (label: string) =>  { return initialColumns.find((column) => column.label === label)?.prop }

export const requiredColumns = initialColumns.filter(({ required }) => !!required)

export const mapPropertyToLabel = initialColumns.reduce((prev, current) => ({...prev, [current.prop]: current.label }), {})


export const invoice_columns = [
  { label: "抬头", span: 24, field: "invoice_title" },
  { label: "纳税人识别号", span: 24, field: "invoice_code" },
];


/**
 * @invoice_addr 公司注册地址
 * @invoice_people  法人
 * @invoice_mobile 联系方式
 * @invoice_code 纳税识别号
 * @invoice_bank 开户行
 * @invoice_bankNo 开户账户
 */
export const convertInvoiceTitle = (title: Record<string, string>) => {
  const {
    company_address,
    mobile,
    company_license,
    bank_name,
    bankNo,
    company_name
  } = title;

  return {
    invoice_addr: company_address,
    invoice_mobile: mobile,
    invoice_code: company_license,
    invoice_bank: bank_name,
    invoice_bankNo: bankNo,
    invoice_title: company_name
  };
};

export const convertInvoiceTitleData = (title: Record<string, string>) => {
  const {
    invoice_addr,
    invoice_mobile,
    invoice_code,
    invoice_bank,
    invoice_bankNo,
    invoice_title
  } = title;

  return {
    invoice_code,
    invoice_title,
    addrAndmobile: invoice_addr + " " + invoice_mobile,
    bankAndBankNo: invoice_bank + " " + invoice_bankNo
  };
};

export const statusOptions = [
  { type: 'info', label: '待创建', value: 0 },
  { type: '', label: '创建中', value: 1 },
  { type: 'success', label: '创建成功', value: 2 },
  { type: 'danger', label: '创建失败', value: 3 },
]
