/* eslint-disable prettier/prettier */
import { BeforeRequestType, ContentConfig } from "/@/components/PageContent";
import apis from "./apis";
import { h } from "vue";
import { ElMessage, ElTag } from "element-plus";

const send_status_list = [
  { value: "1", label: "未发货", type: "warning" },
  { value: "2", label: "部分已发", type: "primary" },
  { value: "3", label: "全部已发", type: "success" },
  { value: "4", label: "发货完成", type: "warning" }
];

const inv_status_list = [
  { value: "1", label: "未开票", type: "warning" },
  { value: "2", label: "部分开票", type: "primary" },
  { value: "3", label: "全部开票", type: "success" }
];


const pay_status_list = [
  { value: "1", label: "未回款", type: "warning" },
  { value: "2", label: "部分回款", type: "primary" },
  { value: "3", label: "全部回款", type: "success" }
];



const columns = [
  {
    type: 'index',
    label: '序号',
    minWidth: '50px'
  },
  {
    prop: 'sequenceNo',
    label: '确认单编号',
    minWidth: '155px'
  },
  {
    prop: 'cxCode',
    label: '销售订单主编号',
    minWidth: '155px'
  },

  {
    prop: 'createdTime',
    label: '确认单下单时间',
    minWidth: '155px'
  },
  {
    prop: 'customerName',
    label: '客户名称',
    minWidth: '155px'
  },
  {
    prop: 'department',
    label: '业务员部门',
    minWidth: '155px'
  },
  {
    prop: 'ownerName',
    label: '业务员',
    width: '90px',
  },
  {
    prop: 'manager',
    label: '业务经理',
    width: '90px',
  },
  {
    prop: 'goodName',
    label: '产品名称',
    width: '100px',
  },
  {
    prop: 'goodNum',
    label: '下单数量',
    width: '100px',
  },
  {
    prop: 'goodPrice',
    label: '销售单价',
    width: '100px',
  },
  {
    prop: 'totalPrice',
    label: '销售总额',
    width: '100px',
  },
  {
    prop: 'apay_fee',
    label: '已回款',
    width: '100px',
  },
  {
    prop: 'wpay_fee',
    label: '未回款',
    width: '100px',
  },
  {
    prop: 'ainv_fee',
    label: '已开票',
    width: '100px',
  },
  {
    prop: 'winv_fee',
    label: '未开票',
    width: '100px',
  },
  {
    prop: 'ainv_wpay',
    label: '开票进行中',
    width: '100px',
  },
  {
    prop: 'inv_fee',
    label: '已开票未回款',
    width: '100px',
  },
  {
    prop: 'pay_status',
    label: "回款状态",
    width: '100px',
    cellRenderer({ row }) {
      const item = pay_status_list.find(({ value }) => String(value) === String(row.pay_status))
      return h(ElTag, {
        type: item ? item.type : "danger",
        size: 'small'
      }, {
        default: () => item ? item.label : "--"
      })
    }
  },
  {
    prop: 'inv_status',
    label: "开票状态",
    width: '100px',
    cellRenderer({ row }) {
      const item = inv_status_list.find(({ value }) => String(value) === String(row.inv_status))
      return h(ElTag, {
        type: item ? item.type : "danger",
        size: 'small'
      }, {
        default: () => item ? item.label : "--"
      })
    }
  },
  {
    prop: 'sendStatus',
    label: "发货状态",
    width: '100px',
    cellRenderer({ row }) {
      const item = send_status_list.find(({ value }) => String(value) === String(row.sendStatus))
      return h(ElTag, {
        type: item ? item.type : "danger",
        size: 'small'
      }, {
        default: () => item ? item.label : "--"
      })
    }
  }
];

const contentConfig: ContentConfig = {
  columns,
  showTitle: false,
  title: "仅统计toB订单",
  superUserNoAction: false,
  responseCode: 0,
  beforeRequestList(params) {
    const { start, end } = params;
    if (start && end) return BeforeRequestType.NEXT;
    ElMessage.warning("请选择下单月份");
    return BeforeRequestType.EMPTY
  },
  apis: { httpList: apis.list }
};

export default contentConfig;
