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

const columns = [
  { 
    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: 80,
    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: '下单数量',
    prop: '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,
  title: "商品管理",
  permissions: ['007'],
  apis: { 
    httpList: (parameter = {}) => httpList({ ...parameter, channel: [3] }),
    httpAdd: true
  }
};

export default contentConfig;
