import { h } from "vue"
import { ContentConfig } from "/@/components/PageContent";
import { httpList } from "/@/api/InvoiceSales/currentcyAssOrderRecord";
import { renderIconLabelLeft } from "/@/utils/columnRenderHelper";
import { tyStatusOptions } from "/@/utils/status";
import { ElTag } from "element-plus";


const columns = [
  {
    label: '通用订单编号',
    prop: 'tyCode',
    width: "150px",
    fixed: "left"
  },
  {
    label: "确认单编号",
    prop: "orderCode",
    width: "150px"
  },
  {
    label: '销售主单号',
    prop: 'cxCode',
    width: "150px"
  },
  {
    label: '商品编号',
    prop: 'goodNo',
    width: 175
  },
  {
    label: '商品名称',
    prop: 'goodName',
    width: 160
  },
  {
    label: '申请人',
    prop: 'apply_name',
    width: '100px'
  },
  {
    label: '卖出方公司',
    prop: 'supplierName',
    minWidth: 175,
    ...renderIconLabelLeft('supplierNo', 'supplierName', '卖出方公司编码:')
  },
  {
    label: '买入方公司',
    prop: 'companyName',
    minWidth: 175,
    ...renderIconLabelLeft('customerNo', 'customerName', '买入方公司编码:')
  },
  {
    label: '下单数量',
    prop: 'num',
    width: 80,
    cellRenderer({ row }) {
      return row.qrd?.goodNum || '--';
    }
  },
  {
    label: '销售单价',
    prop: 'num',
    width: 80,
    cellRenderer({ row }) {
      return row.qrd?.goodPrice || '--';
    }
  },
  {
    label: '销售总额',
    prop: 'num',
    width: 80,
    cellRenderer({ row }) {
      return row.qrd?.totalPrice || '--';
    }
  },
  {
    label: '对账状态',
    prop: 'status',
    width: 160,
    cellRenderer({ row }) {
      return h(ElTag, null, {
        default: () => tyStatusOptions.find(c => c.value == row.status)?.label || '--'
      });
    }
  }
];

const contentConfig: ContentConfig = {
  title: "通用订单关联订单已回款列表",
  companyProp: 'companyNo',
  columns,
  apis: {
    httpList: (data:any = ({} as any)) => {
     
      let status = [0, 1, 2];
      if(data.status === '0'){
        status = [0];
      }

      if(data.status === '1'){
        status = [1];
      }

      if(data.status === '2'){
        status = [2];
      }

      if(data.orderCode) {
        data.orderCode = [data.orderCode];
      }
     
      return httpList({
        ...data,
        // pay_status: '2',
        status
      })
    }
  }
};

export default contentConfig;
