import { ContentConfig } from "/@/components/PageContent";
import { httpList } from "/@/api/invoiceInOut/clientC";
import { typeOptions } from "./shared";
import { h } from "vue";
import { ElTag } from "element-plus";
import { cg_order_type_options, useTypeOptions } from "/@/utils/status";
import { renderIconLabelLeft } from "/@/utils/columnRenderHelper";
import { basicStatusOptions } from "/@/views/invoiceInOut/productManager/config/columns";

export const statusOptions = [
  { value: '1', label: '待处理', type: 'warning' },
  { value: '2', label: '正常', type: 'success' },
  { value: '3', label: '计提', type: 'success' },
  { value: '4', label: '异常', type: 'danger' },
]


const columns = [
  {
    width: 40,
    type: 'selection',
    fixed: 'left'
  },
  {
    label: "确认单编号",
    prop: "orderCode",
    width: 150
  },

  {
    label: "销售主单号",
    prop: 'cxCode',
    width: 150
  },

  {
    label: "业务类型",
    prop: 'type',
    width: 80,
    cellRenderer({ row }) {
      return h(ElTag, { size: 'small' }, {
        default: () => typeOptions.find(item => item.value == row.type)?.label || '--'
      })
    }
  },

  {
    label: "状态",
    width: 90,
    cellRenderer({ row }) {
      return h(ElTag, { size: 'small', type: statusOptions.find(item => item.value == row.status)?.type || 'warning' }, {
        default: () => statusOptions.find(item => item.value == row.status)?.label || '--'
      })
    }
  },

  {
    label: "异常原因",
    width: 120,
    prop: 'error_remark'
  },

  {
    label: "平台订单号",
    prop: 'poCode',
    width: 100
  },

  {
    label: "平台类型",
    width: 80,
    cellRenderer({ row }) {
      return h(ElTag, { size: 'small' }, {
        default: () => useTypeOptions.find(item => item.value == row.platform_type)?.label || '--'
      })
    }
  },
  {
    label: "卖出方公司",
    width: 160,
    ...renderIconLabelLeft('seller_code', 'seller_name', '卖出方公司编号：')
  },
  {
    label: "客户公司",
    width: 160,
    ...renderIconLabelLeft('buyer_code', 'buyer_name', '客户公司编号:')
  },
  {
    label: '商品名称',
    width: 160,
    ...renderIconLabelLeft('goodNo', 'goodName', '商品编号:')
  },
  {
    label: '商品类型',
    width: 95,
    cellRenderer({ row }) {
      return h(ElTag, { size: 'small' }, {
        default: () => cg_order_type_options.find(item => item.value == row.goodType)?.label || '--'
      })
    }
  },
  {
    label: '商品来源',
    width: 95,
    cellRenderer({ row }) {
      return h(ElTag, { size: 'small' }, {
        default: () => basicStatusOptions.find(item => item.value == row.source)?.label || '--'
      })
    }
  },
  {
    label: '数量',
    prop: 'balance_num',
    width: 100
  },

  {
    label: '销售单价',
    prop: 'goodPrice',
    width: 100
  },

  {
    label: '销售合计',
    prop: 'totalPrice',
    width: 100
  },
  {
    label: '出库时间',
    prop: 'fz_date',
    width: 100
  },

  {
    label: "操作",
    fixed: "right",
    width: 50,
    slot: "operation"
  }
];

const contentConfig: ContentConfig = {
  columns,
  permissions: ['007'],
  companyProp: 'seller_code',
  apis: {
    httpList: (parameter = {}) => httpList({ ...parameter, channel: [3], status: '1,4' }),
    httpAdd: true
  }
};

export default contentConfig;
