/* 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";

const columns = [
  {
    prop: 'manager',
    label: '业务经理',
    minWidth: '155px'
  },
  {
    prop: 'department',
    label: '所在部门',
    minWidth: '155px'
  },
  {
    prop: 'orderNum',
    label: '订单数量',
    minWidth: '100px'
  },

  {
    prop: 'totalPrice',
    label: '销售金额',
    minWidth: '100px'
  },
  {
    prop: 'th_fee',
    label: '退货金额',
    minWidth: '100px'
  },
  {
    prop: 'realTotal',
    label: '实际金额',
    minWidth: '100px'
  },
];

const contentConfig: ContentConfig = {
  columns,
  responseCode: 0,
  notPagination: true,
  superUserNoAction: false,
  beforeRequestList(params) {
    const { start, end } = params;
    const beyondTime = isBeyondTime({
      name: "下单时间",
      len: 30,
      start,
      end,
    });

    if (beyondTime) {
      return BeforeRequestType.EMPTY
    }
    return BeforeRequestType.NEXT;
  },
  tableRowClassName({ rowIndex }) {
    if (rowIndex === 0) {
      return "warning-row"
    }
  },
  handleData(list) {
    const mapTotal: Record<string, string | number> = {
      manager: '合计',
      department: '--',
      orderNum: 0,
      totalPrice: 0,
      th_fee: 0,
      realTotal: 0,
    }

    list.forEach(item => {
      const {
        orderNum,
        totalPrice,
        th_fee,
        realTotal,
      } = item;

      mapTotal.orderNum = Number(addition(mapTotal.orderNum, orderNum)).toFixed(0);
      mapTotal.totalPrice = Number(addition(mapTotal.totalPrice, totalPrice)).toFixed(2);
      mapTotal.th_fee = Number(addition(mapTotal.th_fee, th_fee)).toFixed(2);
      mapTotal.realTotal = Number(addition(mapTotal.realTotal, realTotal)).toFixed(2);
    });

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

export default contentConfig;
