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

import { httpList } from "/@/api/dashboard/accountsReceivableExpired";
import { send_status_list } from "/@/utils/status";
import {addition} from "/@/utils/calc";

export const retrun_status = [
  {
    value: "1",
    label: "未回款"
  },
  {
    value: "2",
    label: "部分回款"
  },
  {
    value: "3",
    label: "已回款"
  }
];

export const inv_status = [
  {
    value: "1",
    label: "未开票"
  },
  {
    value: "2",
    label: "开票中"
  },
  {
    value: "3",
    label: "已开票"
  }
];


const columns = [
  {
    label: '序号',
    prop: 'index'
  },
  {
    label: "确认单编码",
    prop: "sequenceNo",
    width: '115px'
  },
  {
    label: "销售订单主编号",
    prop: "cxCode",
    width: '115px'
  },
  {
    label: "确认单下单时间",
    prop: "createdTime",
    width: '115px'
  },
  {
    label: "客户名称",
    prop: "customerName"
  },
  {
    label: "业务员部门",
    prop: "department"
  },
  {
    label: "业务员",
    prop: "ownerName"
  },
  {
    label: "产品名称",
    prop: "goodName"
  },
  {
    label: "下单数量",
    prop: "goodNum"
  },
  {
    label: "销售单价",
    prop: "goodPrice"
  },
  {
    label: "销售总额",
    prop: "totalPrice"
  },
  {
    label: "已回款",
    prop: "apay_fee"
  },
  {
    label: "未回款",
    prop: "wpay_fee"
  },
  {
    label: "已开票",
    prop: "ainv_fee"
  },
  {
    label: "未开票",
    prop: "winv_fee"
  },
  {
    label: "开票进行中",
    prop: "inv_fee"
  },
  {
    label: "已开票未回款",
    prop: "ainv_wpay",
    width: '110px'
  },
  {
    label: "账期",
    prop: "dz_day"
  },
  {
    label: "回款状态",
    prop: "pay_status",
    cellRenderer({ row }) {
      return retrun_status.find(({ value }) => value === row.pay_status)?.label || '--'
    }
  },
  {
    label: "开票状态",
    prop: "inv_status",
    cellRenderer({ row }) {
      return inv_status.find(({ value }) => value === row.inv_status)?.label || '--'
    }
  },
  {
    label: "发货状态",
    prop: "sendStatus",
    cellRenderer({ row }) {
      return send_status_list.find(({ value }) => value === row.sendStatus)?.label || '--'
    }
  }
];



const contentConfig: ContentConfig = {
  title: "超期应收账明细表",
  superUserNoAction: false,
  showTitle: true,
  responseCode:0,
  columns,
  tableRowClassName({rowIndex}){
    console.log(rowIndex)
    if(rowIndex === 0){
      return "warning-row"
    }
  },
  handleData(list){
    const mapTotal:Record<string, string> = {
      index:'合计',
      totalPrice: 0,
      apay_fee: 0,
      wpay_fee: 0,
      ainv_fee: 0,
      winv_fee: 0,
      inv_fee: 0,
      ainv_wpay: 0
    }
    list.forEach(item => {
      const {
        totalPrice,
        apay_fee,
        wpay_fee,
        ainv_fee,
        winv_fee,
        inv_fee,
        ainv_wpay
      } = item;
      mapTotal.totalPrice = Number( addition(mapTotal.totalPrice, totalPrice)).toFixed(2);
      mapTotal.apay_fee =Number(addition(mapTotal.apay_fee, apay_fee)).toFixed(2);
      mapTotal.wpay_fee =Number( addition(mapTotal.wpay_fee, wpay_fee)).toFixed(2);
      mapTotal.ainv_fee = Number(addition(mapTotal.ainv_fee, ainv_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_wpay = Number( addition(mapTotal.ainv_wpay, ainv_wpay)).toFixed(2);
    });

    return [mapTotal,...list.map((item,index) => ({
      index:index + 1,
      ...item,
    }))]
  },
  apis: {
    httpList
  }
};

export default contentConfig;
