/* eslint-disable prettier/prettier */
import { BeforeRequestType, ContentConfig } from "/@/components/PageContent";
import apis from "./apis";
import { isBeyondTime } from "/@/views/reportCollection/_utils";
import { addition } from "/@/utils/calc";
import { ElMessage } from "element-plus";

const columns = [
  {
    prop: 'ownerName',
    label: '销售员',
    minWidth: '155px'
  },
  {
    prop: 'department',
    label: '所在部门',
    minWidth: '155px'
  },
  {
    prop: 'wpay_fee',
    label: '未回款总额',
    minWidth: '155px'
  },

  {
    prop: 'pay_fee',
    label: '回款进行中总额',
    minWidth: '155px'
  },
  {
    prop: 'apay_fee',
    label: '已回款总额',
    minWidth: '155px'
  },
  {
    prop: 'winv_fee',
    label: '未开票总额',
    minWidth: '155px'
  },
  {
    prop: 'inv_fee',
    label: '开票进行中总额',
    minWidth: '155px'
  },
  {
    prop: 'ainv_fee',
    label: '已开票总额',
    minWidth: '155px'
  }
];

const contentConfig: ContentConfig = {
  columns,
  title: "仅统计toB订单",
  responseCode: 0,
  notPagination: true,
  superUserNoAction: false,
  tableRowClassName({ rowIndex }) {
    if (rowIndex === 0) {
      return "warning-row"
    }
  },
  beforeRequestList(params) {
    const { start, end } = params;
    if (start && end) return BeforeRequestType.NEXT;
    ElMessage.warning("请选择下单月份");
    return BeforeRequestType.EMPTY
  },
  handleData(list) {
    const mapTotal: Record<string, string | number> = {
      ownerName: '合计',
      department: '--',
      wpay_fee: 0,
      pay_fee: 0,
      apay_fee: 0,
      winv_fee: 0,
      inv_fee: 0,
      ainv_fee: 0,
    }

    list.forEach(item => {
      const {
        wpay_fee,
        pay_fee,
        apay_fee,
        winv_fee,
        inv_fee,
        ainv_fee
      } = item;

      mapTotal.wpay_fee = Number(addition(mapTotal.wpay_fee, wpay_fee)).toFixed(2);
      mapTotal.pay_fee = Number(addition(mapTotal.pay_fee, pay_fee)).toFixed(2);
      mapTotal.apay_fee = Number(addition(mapTotal.apay_fee, apay_fee)).toFixed(2);
      mapTotal.winv_fee = Number(addition(mapTotal.winv_fee, winv_fee)).toFixed(2);
      mapTotal.inv_fee = Number(addition(mapTotal.inv_fee, inv_fee)).toFixed(2);
      mapTotal.ainv_fee = Number(addition(mapTotal.ainv_fee, ainv_fee)).toFixed(2);
    });

    return [mapTotal, ...list]
  },
  apis: { httpList: apis.list }
};

export default contentConfig;
