import { ContentConfig } from "/@/components/PageContent";
import { httpList } from "/@/api/sellOut/salesOrder";
import { statusOptions, platformTypeOptions, xsOrderTypeOptions } from "./_options"


import { ElTag } from "element-plus";
import { h } from "vue";
import { xsOrderSourceOptions } from "../components/ProductModal/config/_options";

const columns = [
  { type: 'selection', fixed: 'left', _noset_: true },
  {
    prop: 'orderCode',
    label: '订单编号',
    width: '155px'
  },
  {
    prop: 'good_name',
    label: '商品名称',
    _slot_: 'good_name',
    width: '180'
  },
  {
    prop: 'good_class',
    label: '商品分类',
    width: '120',
    cellRenderer({ row }){
      return (row.can || []).map(({ name }) => name).join('_')
    }
  },
  {
    prop: 'good_num',
    label: '商品数量',
    width: '110'
  },
  {
    prop: 'sale_price',
    label: '销售单价',
    width: '110'
  },
  {
    label:'平台订单号',
    width: '140',
    render(_, { platform_order }){ return platform_order }
  },
  {
    label: '总价',
    width: '110',
    cellRenderer({ row }){
      return Number(row.good_num * row.sale_price).toFixed(2)
    }
  },
  {
    prop: 'status',
    label: '订单状态',
    width: '120px',
    cellRenderer({ row }){
      return h(
        ElTag, 
        { size: 'small',  type: statusOptions.find(({ value }) => value == row.status).type || 'info'  }, 
        { default: () => statusOptions.find(({ value }) => value == row.status).label || '--' }
      )
    }
  },
  {
    prop: 'use_type',
    label: '平台类型',
    width: '80',
    cellRenderer({ row }){
      return h(ElTag, {}, {
        default: platformTypeOptions.find(({ value }) => value == row.use_type)?.label || '--'
      })
    }
  },
  {
    prop: 'order_source',
    label: '订单来源',
    width: '100px',
    cellRenderer({ row }){
      return h(ElTag, {}, {
        default: xsOrderSourceOptions.find(({ value }) => value == row.order_source)?.label || '--'
      })
    }
  },
  {
    prop: 'order_type',
    label: '商品类型',
    width: '100px',
    cellRenderer({ row }){
      return h(ElTag, {}, {
        default: xsOrderTypeOptions.find(({ value }) => value == row.order_type)?.label || '--'
      })
    }
  },
  {
    prop: 'customerName',
    label: '企业客户名称',
    width: '145px',
    _slot_: 'cutsomer'
  },
  {
    prop: 'supplierName',
    label: '销售方公司',
    width: '145px',
    _slot_:'supplier'
  },
  {
    prop: 'apply_name',
    label: '订单创建人',
    width: '85px'
  },
  {
    prop: 'cgder',
    label: '供应商负责人',
    width: '95'
  },
  {
    prop: 'good_creater',
    label: '商品创建人',
    width: '85px'
  },
  {
    prop: 'addtime',
    label: '创建时间',
    width: '145px'
  },
  {
    prop: "",
    label: "操作",
    fixed: "right",
    width: "50px",
    slot: "operation",
  }
];

const contentConfig: ContentConfig = {
  title: "销售订单管理",
  columns,
  apis: {
    httpList,
    httpAdd: true
  }
};

export default contentConfig;
