/* 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: 'sale_name',
    label: '销售员',
    minWidth: '155px'
  },
  {
    prop: 'depart_name',
    label: '所在部门',
    minWidth: '155px'
  },
  {
    prop: 'consult_num',
    label: '竞价单数量',
    minWidth: '155px'
  },

  {
    prop: 'consult_total',
    label: '竞价单总金额',
    minWidth: '155px'
  },
  {
    prop: 'sale_num',
    label: '订单数量',
    minWidth: '155px'
  },
  {
    prop: 'sale_total',
    label: '销售金额',
    minWidth: '155px'
  },
  {
    prop: 'th_total',
    label: '退货金额',
    minWidth: '155px'
  },
  {
    prop: 'sale_real_total',
    label: '实际金额',
    minWidth: '155px'
  }
];

const contentConfig: ContentConfig = {
  columns,
  showTitle: false,
  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> = {
      sale_name:'合计',
      depart_name: '--',
      consult_num: 0,
      consult_total: 0,
      sale_total: 0,
      th_total: 0,
      sale_real_total: 0,
      sale_num:0
    }

    list.forEach(item => {
      const {
        consult_num,
        consult_total,
        sale_total,
        th_total,
        sale_real_total,
        sale_num
      } = item;

      mapTotal.consult_num = Number( addition(mapTotal.consult_num, consult_num)).toFixed(0);
      mapTotal.consult_total = Number(addition(mapTotal.consult_total, consult_total)).toFixed(2);
      mapTotal.sale_total = Number( addition(mapTotal.sale_total, sale_total)).toFixed(2);
      mapTotal.th_total = Number(addition(mapTotal.th_total, th_total)).toFixed(2);
      mapTotal.sale_real_total = Number(addition(mapTotal.sale_real_total, sale_real_total)).toFixed(2);
      mapTotal.sale_num = Number(addition(mapTotal.sale_num, sale_num)).toFixed(0)
    });

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

export default contentConfig;
