/* eslint-disable prettier/prettier */
import { ContentConfig } from "/@/components/PageContent";

import { httpList } from "/@/api/dashboard/accountsReceivable";
import { addition, unit2TenThousand } from "/@/utils/calc";

const columns = [
  {
    label: "业务公司",
    prop: "depart",
    cellRenderer({ row }) {
      return row.depart === '总计' ? row.depart : row.depart.split("@")[1]
    }
  },
  {
    label: "应收账款",
    prop: "wpay_fee"
  },
  {
    label: "已开票未回款",
    prop: "wpay_ainv_fee"
  },
  {
    label: "未开票",
    prop: "winv_fee"
  },
  {
    label: "待开票",
    prop: "inv_fee"
  },
  {
    label: "已发货未开票",
    prop: "winv_asend_fee"
  },
  {
    label: "未发货",
    prop: "wpay_send_fee"
  },
  {
    label: "超60天已发货未开票",
    prop: "winv_two_month"
  },
  {
    label: "超180天应收账款",
    prop: "wpay_six_month"
  }
];

const contentConfig: ContentConfig = {
  title: "万宇应收账款报表看板",
  superUserNoAction: false,
  showTitle: true,
  handleData(data = []) {
    return new Promise(resolve => {
      const totalItem = data.reduce((prev, current) => Object.keys(current).reduce((prev, currentKey) => ({
        ...prev,
        [currentKey]: currentKey !== 'depart' ? addition(current[currentKey] || 0, prev[currentKey] || 0) : '总计'
      }), prev), {})
      resolve([...data, totalItem])
    })
  },
  columns: columns.map(column => ({
    align: 'center',
    ...column, ...(column.prop !== "depart" ? { cellRenderer: ({ row }) => unit2TenThousand(row[column.prop]) } : {})
  })),
  apis: {
    httpList
  }
};

export default contentConfig;
