import { h } from "vue";

import { ElTag } from "element-plus";
import { statusOptions } from "./_options"
import { hasAccountOptions, orderTypeCgOptions } from "/@/utils/status";
import { ContentConfig } from "/@/components/PageContent";
import { httpList } from "/@/api/InvoiceSales/currentcyOrderRecord";
import { renderIconLabelLeft, renderProp } from "/@/utils/columnRenderHelper";

const columns = [
  {
    label: "对账编号",
    prop: "payNo",
    fixed: "left",
    minWidth: "150px"
  },
  {
    label: '对账单总金额',
    prop: 'total_fee',
    width: '100px'
  },
  {
    label: '状态',
    prop: 'status',
    width: '120px',
    cellRenderer({ row }) {
      return h(ElTag, null, {
        default: () => {
          return statusOptions.find(({ value }) => value === String(row.status))?.label || '--'
        }
      })
    }
  },
  {
    label: '业务类型',
    width: 95,
    ...renderProp(orderTypeCgOptions, 'is_comon')
  },
  {
    label: '供应商端',
    prop: 'has_account',
    width: 80,
    ...renderProp(hasAccountOptions, "has_account")
  },
  {
    label: '买入方公司',
    prop: 'companyName',
    minWidth: 175,
    ...renderIconLabelLeft('companyNo', 'companyName', '买入方公司:')
  },
  {
    label: '卖出方公司',
    prop: 'supplierName',
    minWidth: 175,
    ...renderIconLabelLeft('supplierNo', 'supplierName', '卖出方公司编码:')
  },
  {
    label: '创建人',
    prop: 'apply_name',
    minWidth: '100px'
  },
  {
    label: '创建时间',
    prop: 'addtime',
    width: '145px'
  },
  {
    label: "操作",
    fixed: "right",
    width: 140, //后期修改
    slot: "operation"
  }
];

const contentConfig: ContentConfig = {
  title: "通用订单对账管理",
  columns,
  transformCompany: true,
  companyProp: 'supplierNo',
  apis: {
    httpList: (data) => httpList({ ...data, noRela: true })
  },
  payProps: {
    prop: "payNo",
    type: "1"
  },
  returnProps: {
    prop: "payNo",
    type: "2"
  },
  showPayTagFn: ({ status, is_comon }, permissions) =>
    String(status) === "2" && permissions.includes("013") && String(is_comon) === "1",
  showReturnTagFn: ({ status, is_comon }, permissions) =>
    String(status) === "2" && permissions.includes("014") && String(is_comon) === "1"
};

export default contentConfig;
