import { ContentConfig } from "/@/components/PageContent";
import { httpList } from "/@/api/InvoiceSales/sheetOrderPool";

import { inv_open_status, retrun_status, cat_status } from "./search.config";
import { renderIconLabelLeft } from "/@/utils/columnRenderHelper";
import { ElImage, ElTag } from "element-plus";
import { h } from "vue";

import {
  xs_order_source_options,
  xs_order_type_options,
  send_status_list,
  useTypeOptions
} from "/@/utils/status";

const columns = [
  {
    type: "selection",
    width: 40,
    align: "center",
    fixed: "left"
  },
  {
    label: "销售订单编码",
    prop: "sequenceNo",
    width: 150
  },
  {
    label: "销售订单主编码",
    prop: "cxCode",
    width: 150
  },
  {
    label: "平台类型",
    width: 70,
    cellRenderer: ({ row }) =>
      h(ElTag, null, {
        default: () =>
          useTypeOptions.find(s => s.value === row.platform_type)?.label || "--"
      })
  },
  {
    label: "卖出方公司",
    prop: "companyName",
    minWidth: 130,
    ...renderIconLabelLeft("companyNo", "companyName", "卖出方公司编码:")
  },
  {
    label: "客户公司",
    prop: "customerName",
    minWidth: 130,
    ...renderIconLabelLeft("customerNo", "customerName", "客户公司编码:")
  },

  {
    label: "商品名称",
    prop: "goodName",
    minWidth: 130,
    ...renderIconLabelLeft("goodNo", "goodName", "商品编码:")
  },
  {
    label: "平台名称",
    prop: "platName",
    width: 90
  },
  {
    label: "类目设置状态",
    width: 100,
    cellRenderer: ({ row }) =>
      h(ElTag, null, {
        default: () =>
          cat_status.find(s => s.value === row.cat_status)?.label || "--"
      })
  },
  {
    label: "商品类型",
    width: 100,
    cellRenderer: ({ row }) =>
      h(ElTag, null, {
        default: () =>
          xs_order_type_options.find(s => s.value === row.qrdType)?.label ||
          "--"
      })
  },
  {
    label: "发货状态",
    width: 100,
    cellRenderer: ({ row }) =>
      h(ElTag, null, {
        default: () =>
          send_status_list.find(s => s.value === row.sendStatus)?.label || "--"
      })
  },
  {
    label: "订单来源",
    width: 100,
    cellRenderer: ({ row }) =>
      h(ElTag, null, {
        default: () =>
          xs_order_source_options.find(s => s.value === row.qrdSource)?.label ||
          "--"
      })
  },
  {
    label: "开票状态",
    width: 100,
    cellRenderer: ({ row }) =>
      h(ElTag, null, {
        default: () =>
          inv_open_status.find(s => s.value === row.inv_status)?.label || "--"
      })
  },
  {
    label: "已开票",
    prop: "ainv_fee",
    width: 110
  },
  {
    label: "开票中",
    prop: "inv_fee",
    width: 110
  },
  {
    label: "未开票",
    prop: "winv_fee",
    width: 110
  },
  {
    label: "开票标签金额",
    prop: "inv_tag_fee",
    width: 110
  },
  {
    label: "标签图片",
    width: "70px",
    cellRenderer({ row }) {
      if (!row.inv_tag_img) return null;

      return h(ElImage, {
        src: row.inv_tag_img,
        previewSrcList: [row.inv_tag_img],
        previewTeleported: true,
        style: {
          height: "20px",
          width: "20px"
        }
      });
    }
  },
  {
    label: "回款状态",
    width: 100,
    cellRenderer: ({ row }) => {
      return h(ElTag, null, {
        default: () =>
          retrun_status.find(s => s.value === row.pay_status)?.label
      });
    }
  },
  {
    label: "已回款",
    prop: "apay_fee",
    width: 110
  },
  {
    label: "回款中",
    prop: "pay_fee",
    width: 110
  },
  {
    label: "未回款",
    prop: "wpay_fee",
    width: 110
  },
  {
    label: "回款标签金额",
    prop: "pay_tag_fee",
    width: 110
  },
  {
    label: "标签图片",
    width: "70px",
    cellRenderer({ row }) {
      if (!row.pay_tag_img) return null;

      return h(ElImage, {
        src: row.pay_tag_img,
        previewSrcList: [row.pay_tag_img],
        previewTeleported: true,
        style: {
          height: "20px",
          width: "20px"
        }
      });
    }
  },

  {
    label: "销售员",
    prop: "ownerName",
    width: 70
  },
  {
    label: "部门",
    prop: "department",
    width: 70
  },
  {
    label: "操作",
    fixed: "right",
    width: 120,
    slot: "operation"
  }
];

const contentConfig: ContentConfig = {
  title: "销售订单公海池",
  columns,
  superUserNoAction: true,
  payProps: {
    prop: "sequenceNo",
    type: "3"
  },
  returnProps: {
    prop: "sequenceNo",
    type: "4"
  },
  showPayTagFn: (_, permissions) => permissions.includes("016"),
  showReturnTagFn: (_, permissions) => permissions.includes("015"),
  apis: {
    httpList
  }
};

export default contentConfig;
