import { httpList, httpDel } from "/@/api/purchase/orderRecord";
import { ContentConfig } from "/@/components/PageContent";

import { statusOptions, payStatusOptions, invStatusOptions } from "./_options";
import { renderIconLabelLeft, renderProp } from "/@/utils/columnRenderHelper";
import { orderTypeCgOptions } from "/@/utils/status";
import { h } from "vue";
import { ElTag } from "element-plus";


const hasAccountOptions = [
  { value: true, type: "", label: "未开通" },
  { value: false, type: "success", label: "已开通" }
];

const columns = [
  {
    type: "selection",
    width: 40,
    align: "center",
    fixed: 'left'
  },
  {
    label: "对账编码",
    prop: "payNo",
    width: 150,
    align: "left"
  },

  {
    label: "对账总额",
    prop: "total_fee",
    width: 110,
    align: "total_fee"
  },

  {
    label: '业务类型',
    width: 90,
    ...renderProp(orderTypeCgOptions, 'is_comon')
  },
  {
    label: "状态",
    prop: "status",
    width: 140,
    transform: status => statusOptions.find(s => status === s.value)?.label || "--",
    ...renderProp(statusOptions)
  },
  {
    label: '付款状态',
    prop: 'pay_status',
    width: 80,
    transform: pay_status =>
      payStatusOptions.find(s => pay_status === s.value)?.label || "--",
    ...renderProp(payStatusOptions, 'pay_status')
  },
  {
    label: '回票状态',
    prop: 'inv_status',
    width: 80,
    transform: inv_status =>
      payStatusOptions.find(s => inv_status === s.value)?.label || "--",
    ...renderProp(invStatusOptions, 'inv_status')
  },
  {
    label: "供应商端",
    prop: "has_account",
    width: 80,
    cellRenderer({ row }){
      return h(ElTag, { size: 'small' }, {
        default: () => row.has_account ? '已开通' : '未开通'
      })
    }
  },
  {
    label: "卖出方公司",
    prop: "supplierName",
    minWidth: 160,
    align: "left",
    ...renderIconLabelLeft('supplierNo','supplierName','卖出方公司:')
  },
  {
    label: "买入方公司",
    prop: "companyName",
    minWidth: 180,
    align: "left",
    ...renderIconLabelLeft('companyNo', 'companyName', '买入方公司:')
  },

  {
    label: "申请人",
    prop: "apply_name",
    width: 70,
    align: "left"
  },
  {
    label: "申请时间",
    width: 140,
    prop: "addtime"
  }
];

const contentConfig: ContentConfig = {
  title: "订单对账",
  columns,
  pagination: { layout: 'prev, pager, next' },
  notNeedCompanyFilter: true,
  apis: {
    httpList: (parameter = {}) => {

      const { is_comon = '0', ...rest } = parameter

      return httpList({ ...rest,  inv_status: '0', status: '2', is_comon })
    },
    httpDelete: httpDel,
    httpAdd: true
  },
};

export default contentConfig;
