import { ref } from 'vue';
//数据录入
export const dayColumns = ref([
  { field: 'platformNumber', title: '平台编号', align: 'center', width: 90, },
  { field: 'platformName', title: '平台名称', align: 'center', width: 142, },
  { field: 'country', title: '国家', align: 'center', width: 90, },
  { field: 'brandName', title: '品牌', align: 'center', width: 90, },
  { field: 'operater', title: '运营', align: 'center', width: 100 },
  { field: 'currencyCode', title: '平台币种', align: 'center', width: 100 },
  {
    title: '销售额', align: 'center', children: [
      { field: 'sales', title: '销售额', align: 'center', minWidth: 120 },
      {
        field: 'sales_original',
        title: '销售额(本币)',
        editRender: {},
        slots: { edit: 'sales_original_edit' },
        width: 123,
        align: 'center'
      },
    ]
  },
  {
    title: '广告销售额', align: 'center', children: [
      { field: 'ad_sales', title: '广告销售额', align: 'center', minWidth: 120 },
      {
        field: 'ad_sales_original',
        title: '广告销售额(本币)',
        editRender: {},
        slots: { edit: 'ad_sales_original_edit' },
        width: 151,
        align: 'center'
      },
    ]
  },
  //{field: 'sales', title: '销售额', editRender: {}, slots: {edit: 'sales_edit', default: 'sales_default',header: 'sales_header'}},
  {
    title: '广告花费', align: 'center', children: [
      { field: 'ad_cost', title: '广告花费', align: 'center', minWidth: 120 },
      {
        field: 'ad_cost_original',
        title: '广告花费(本币)',
        editRender: {},
        slots: { edit: 'ad_cost_original_edit' },
        width: 138,
        align: 'center'
      },
    ]
  },
  { title: '操作', width: 120, slots: { default: 'operate' }, align: 'center' , fixed: 'right'},
]);

export const weekColumns = ref([
  { field: 'platformNumber', title: '平台编号', fixed: 'left', width: 81, align: 'center' },
  { field: 'platformName', title: '平台名称', fixed: 'left', width: 142, align: 'center' },
  { field: 'country', title: '国家', fixed: 'left', width: 80, align: 'center' },
  { field: 'brandName', title: '品牌', fixed: 'left', width: 60 },
  { field: 'operater', title: '运营', fixed: 'left', width: 80, align: 'center' },
  { field: 'currencyCode', title: '平台币种', fixed: 'left', width: 80, align: 'center' },

  {
    title: '销售额', align: 'center', children: [
      { field: 'sales', title: '销售额', width: 120, align: 'center' },
      {
        field: 'sales_original',
        title: '销售额(本币)',
        editRender: {},
        slots: { edit: 'sales_original_edit' },
        width: 123,
        align: 'center'
      },
    ]
  },
  {
    title: '广告销售额', align: 'center', children: [
      { field: 'ad_sales', title: '广告销售额', width: 120 },
      {
        field: 'ad_sales_original',
        title: '广告销售额(本币)',
        editRender: {},
        slots: { edit: 'ad_sales_original_edit' },
        width: 151,
        align: 'center'
      },
    ]
  },
  {
    title: '广告花费', align: 'center', children: [
      { field: 'ad_cost', title: '广告花费', width: 120, align: 'center' },
      {
        field: 'ad_cost_original',
        title: '广告花费(本币)',
        editRender: {},
        slots: { edit: 'ad_cost_original_edit' },
        width: 138,
        align: 'center'
      },
    ]
  },
  {
    title: '当月累计销售额', align: 'center', slots: { header: 'total_header' },
    children: [
      { field: 'total_sales_current_monthly', title: '当月累计销售额', width: 120 },
      {
        field: 'total_sales_current_monthly_original',
        title: '当月累计销售额(本币)',
        editRender: {},
        slots: { edit: 'total_sales_current_monthly_edit' },
        width: 180,
        align: 'center'
      },
    ]
  },

  {
    field: 'impression',
    title: '广告曝光',
    editRender: {},
    slots: { edit: 'impression_edit' },
    width: 100,
    align: 'center'
  },
  {
    field: 'ad_click',
    title: '广告点击',
    editRender: {},
    slots: { edit: 'ad_click_edit' },
    width: 100,
    align: 'center'
  },
  {
    field: 'ad_order',
    title: '广告订单',
    editRender: {},
    slots: { edit: 'ad_order_edit' },
    width: 95,
    align: 'center'
  },
  {
    field: 'money_by_amazon',
    title: 'Amazon回款金额',
    editRender: {},
    slots: { edit: 'money_by_amazon_edit' },
    width: 134, align: 'center'
  },
  { field: 'currencyCodePlatform', title: '回款/余额币种', width: 115 ,align: 'center'},
  {
    field: 'money_by_other',
    title: 'Other回款金额',
    editRender: {},
    slots: { edit: 'money_by_other_edit' },
    width: 134, align: 'center'
  },
  { field: 'session', title: '流量', editRender: {}, slots: { edit: 'session_edit' }, width: 95, align: 'center' },
  { field: 'order', title: '订单', editRender: {}, slots: { edit: 'order_edit' }, width: 95, align: 'center' },
  {
    field: 'availableSalesDay',
    title: '当前存货可售天',
    editRender: {},
    slots: { edit: 'availableSalesDay_edit'},
    width: 120, align: 'center'
  },
  {
    field: 'intransitInventory',
    title: '当前在途库存',
    editRender: {},
    slots: { edit: 'intransitInventory_edit' },
    width: 120, align: 'center'
  },
  {
    field: 'overseasStorage',
    title: '当前海外仓库存',
    editRender: {},
    slots: { edit: 'overseasStorage_edit' },
    width: 120, align: 'center'
  },
  {
    field: 'refundRate',
    title: '最近90天平台退货率',
    editRender: {},
    slots: { edit: 'refundRate_edit' ,default: 'refundRate_default'},
    width: 120,
    align: 'center'
  },
  { title: '操作', width: 120, slots: { default: 'operate' }, fixed: 'right' },
]);

export const monthColumns = ref([
  { field: 'platformNumber', title: '平台编号', fixed: 'left', width: 81, align: 'center' },
  { field: 'platformName', title: '平台名称', fixed: 'left', width: 142, align: 'center' },
  { field: 'country', title: '国家', fixed: 'left', width: 80, align: 'center' },
  { field: 'brandName', title: '品牌', fixed: 'left', width: 60 },
  { field: 'operater', title: '运营', fixed: 'left', width: 80, align: 'center' },
  { field: 'currencyCode', title: '平台币种', fixed: 'left', width: 80, align: 'center' },

  {
    title: '销售额', align: 'center', children: [
      { field: 'sales', title: '销售额', width: 120 },
      {
        field: 'sales_original',
        title: '销售额(本币)',
        editRender: {},
        slots: { edit: 'sales_original_edit' },
        minWidth: 123,
      },
    ]
  },
  {
    title: '广告销售额', align: 'center', children: [
      { field: 'ad_sales', title: '广告销售额', width: 120 },
      {
        field: 'ad_sales_original',
        title: '广告销售额(本币)',
        editRender: {},
        slots: { edit: 'ad_sales_original_edit' },
        minWidth: 151,
      },
    ]
  },
  {
    title: '广告花费', align: 'center', children: [
      { field: 'ad_cost', title: '广告花费', width: 120 },
      {
        field: 'ad_cost_original',
        title: '广告花费(本币)',
        editRender: {},
        slots: { edit: 'ad_cost_original_edit' },
        minWidth: 138,
      },
    ]
  },

  { field: 'impression', title: '广告曝光', editRender: {}, slots: { edit: 'impression_edit' }, width: 120 },
  { field: 'ad_click', title: '广告点击', editRender: {}, slots: { edit: 'ad_click_edit' }, width: 120 },
  { field: 'ad_order', title: '广告订单', editRender: {}, slots: { edit: 'ad_order_edit' }, width: 120 },
  { title: '操作', width: 120, slots: { default: 'operate' }, fixed: 'right' },
]);

export const universal = [
  {
    field: 'platformNumber',
    title: '平台编号',
    fixed: 'left',
    align: 'center',
    minWidth: 75,
    slots: { default: 'platformNumber_default' }
  },
  {
    field: 'platformName',
    title: '平台名称',
    fixed: 'left',
    minWidth: 100,
    slots: { default: 'platformName_default' },
    align: 'center',
    titlePrefix: { icon: 'vxe-icon-goods-fill' },
  },
  {
    field: 'department',
    title: '部门',
    fixed: 'left',
    minWidth: 75,
    align: 'center',
  },
  {
    field: 'operater',
    title: '运营',
    fixed: 'left',
    minWidth: 75,
    align: 'center',
    titlePrefix: { icon: 'vxe-icon-user' }
  },
  {
    field: 'country',
    title: '国家',
    fixed: 'left',
    minWidth: 75,
    titlePrefix: { icon: 'vxe-icon-location' },
    align: 'center'
  },
  {
    field: 'brandName',
    title: '品牌',
    fixed: 'left',
    minWidth: 80,
    align: 'center',
    titlePrefix: { icon: 'vxe-icon-brand' },
  },
  //{
  //  field: 'currencyCode',
  //  title: '平台币种',
  //  fixed: 'left',
  //  minWidth: 75,
  //  align: 'center',
  //  slots: { default: 'currencyCode_default' }
  //},
];

// 表格展示
export const dayDataColumns = ref([
  ...universal
]);
export const weekDataColumns = ref([
  ...universal
]);
export const monthDataColumns = ref([
  ...universal
]);

// 计划销售额
function formatEmptyCell(cellValue) {
  if (cellValue === null || cellValue === undefined || cellValue === '' || cellValue === 'nan') {
    return '--';
  }
  else {
    const formatter = new Intl.NumberFormat('en-US', {
      minimumFractionDigits: 2,
    });
    return formatter.format(cellValue);
  }
}

function formatRateCell(cellValue) {
  if (cellValue ==='nan%'|| cellValue === null || cellValue === undefined || cellValue === ''){
    return '--';
  }
  else {
    return cellValue;
  }
}

export const planSalesColumns = ref([
  // { field: 'platformNumber', title: '平台编号', fixed: 'left', width: 81, align: 'center' },
  // { field: 'platformName', title: '平台名称', fixed: 'left', width: 142, align: 'center' ,},
  // { field: 'country', title: '国家', fixed: 'left', width: 80, align: 'center' },
  // { field: 'brandName', title: '品牌', fixed: 'left', width: 90 ,align: 'center'},
  // { field: 'operater', title: '运营', fixed: 'left', width: 80, align: 'center' },
  ...universal,
  {title:'1月', align: 'center', children: [
      { field: '1月', title: '计划销售额', minWidth: 105, align: 'center', formatter: ({ cellValue }) => formatEmptyCell(cellValue?.planSales) },
      { field: '1月', title: '销售额', minWidth: 105, align: 'center', formatter: ({ cellValue }) => formatEmptyCell(cellValue?.sales) },
      { field: '1月', title: '销售额完成率', minWidth: 105, align: 'center', formatter: ({ cellValue }) => formatRateCell(cellValue?.sales_completion_rate) },
    ]},
    {title:'2月', align: 'center', children: [
      { field: '2月', title: '计划销售额', minWidth: 105, align: 'center', formatter: ({ cellValue }) => formatEmptyCell(cellValue?.planSales) },
      { field: '2月', title: '销售额', minWidth: 105, align: 'center', formatter: ({ cellValue }) => formatEmptyCell(cellValue?.sales) },
      { field: '2月', title: '销售额完成率', minWidth: 105, align: 'center', formatter: ({ cellValue }) => formatRateCell(cellValue?.sales_completion_rate) },
    ]},
    {title:'3月', align: 'center', children: [
      { field: '3月', title: '计划销售额', minWidth: 105, align: 'center', formatter: ({ cellValue }) => formatEmptyCell(cellValue?.planSales) },
      { field: '3月', title: '销售额', minWidth: 105, align: 'center', formatter: ({ cellValue }) => formatEmptyCell(cellValue?.sales) },
      { field: '3月', title: '销售额完成率', minWidth: 105, align: 'center', formatter: ({ cellValue }) => formatRateCell(cellValue?.sales_completion_rate) },
    ]},
    {title:'4月', align: 'center', children: [
      { field: '4月', title: '计划销售额', minWidth: 105, align: 'center', formatter: ({ cellValue }) => formatEmptyCell(cellValue?.planSales) },
      { field: '4月', title: '销售额', minWidth: 105, align: 'center', formatter: ({ cellValue }) => formatEmptyCell(cellValue?.sales) },
      { field: '4月', title: '销售额完成率', minWidth: 105, align: 'center', formatter: ({ cellValue }) => formatRateCell(cellValue?.sales_completion_rate) },
    ]},
    {title:'5月', align: 'center', children: [
      { field: '5月', title: '计划销售额', minWidth: 105, align: 'center', formatter: ({ cellValue }) => formatEmptyCell(cellValue?.planSales) },
      { field: '5月', title: '销售额', minWidth: 105, align: 'center', formatter: ({ cellValue }) => formatEmptyCell(cellValue?.sales) },
      { field: '5月', title: '销售额完成率', minWidth: 105, align: 'center', formatter: ({ cellValue }) => formatRateCell(cellValue?.sales_completion_rate) },
    ]},
    {title:'6月', align: 'center', children: [
      { field: '6月', title: '计划销售额', minWidth: 105, align: 'center', formatter: ({ cellValue }) => formatEmptyCell(cellValue?.planSales) },
      { field: '6月', title: '销售额', minWidth: 105, align: 'center', formatter: ({ cellValue }) => formatEmptyCell(cellValue?.sales) },
      { field: '6月', title: '销售额完成率', minWidth: 105, align: 'center', formatter: ({ cellValue }) => formatRateCell(cellValue?.sales_completion_rate) },
    ]},
    {title:'7月', align: 'center', children: [
      { field: '7月', title: '计划销售额', minWidth: 105, align: 'center', formatter: ({ cellValue }) => formatEmptyCell(cellValue?.planSales) },
      { field: '7月', title: '销售额', minWidth: 105, align: 'center', formatter: ({ cellValue }) => formatEmptyCell(cellValue?.sales) },
      { field: '7月', title: '销售额完成率', minWidth: 105, align: 'center', formatter: ({ cellValue }) => formatRateCell(cellValue?.sales_completion_rate) },
    ]},
    {title:'8月', align: 'center', children: [
      { field: '8月', title: '计划销售额', minWidth: 105, align: 'center', formatter: ({ cellValue }) => formatEmptyCell(cellValue?.planSales) },
      { field: '8月', title: '销售额', minWidth: 105, align: 'center', formatter: ({ cellValue }) => formatEmptyCell(cellValue?.sales) },
      { field: '8月', title: '销售额完成率', minWidth: 105, align: 'center', formatter: ({ cellValue }) => formatRateCell(cellValue?.sales_completion_rate) },
    ]},
    {title:'9月', align: 'center', children: [
      { field: '9月', title: '计划销售额', minWidth: 105, align: 'center', formatter: ({ cellValue }) => formatEmptyCell(cellValue?.planSales) },
      { field: '9月', title: '销售额', minWidth: 105, align: 'center', formatter: ({ cellValue }) => formatEmptyCell(cellValue?.sales) },
      { field: '9月', title: '销售额完成率', minWidth: 105, align: 'center', formatter: ({ cellValue }) => formatRateCell(cellValue?.sales_completion_rate) },
    ]},
    {title:'10月', align: 'center', children: [
      { field: '10月', title: '计划销售额', minWidth: 105, align: 'center', formatter: ({ cellValue }) => formatEmptyCell(cellValue?.planSales) },
      { field: '10月', title: '销售额', minWidth: 105, align: 'center', formatter: ({ cellValue }) => formatEmptyCell(cellValue?.sales) },
      { field: '10月', title: '销售额完成率', minWidth: 105, align: 'center', formatter: ({ cellValue }) => formatRateCell(cellValue?.sales_completion_rate) },
    ]},
    {title:'11月', align: 'center', children: [
      { field: '11月', title: '计划销售额', minWidth: 105, align: 'center', formatter: ({ cellValue }) => formatEmptyCell(cellValue?.planSales) },
      { field: '11月', title: '销售额', minWidth: 105, align: 'center', formatter: ({ cellValue }) => formatEmptyCell(cellValue?.sales) },
      { field: '11月', title: '销售额完成率', minWidth: 105, align: 'center', formatter: ({ cellValue }) => formatRateCell(cellValue?.sales_completion_rate) },
    ]},
    {title:'12月', align: 'center', children: [
      { field: '12月', title: '计划销售额', minWidth: 105, align: 'center', formatter: ({ cellValue }) => formatEmptyCell(cellValue?.planSales) },
      { field: '12月', title: '销售额', minWidth: 105, align: 'center', formatter: ({ cellValue }) => formatEmptyCell(cellValue?.sales) },
      { field: '12月', title: '销售额完成率', minWidth: 105, align: 'center', formatter: ({ cellValue }) => formatRateCell(cellValue?.sales_completion_rate) },
    ]}
])