import { h } from "vue";
import { httpList } from "/@/api/postSupplierOrder/sendOrder";
import { ContentConfig } from "/@/components/PageContent";
import { hasAccountOptions, xs_order_source_options, xs_order_type_options } from "/@/utils/status";
import { orderOptions } from "./options";
import { ElTag } from "element-plus";
import { renderProp } from "/@/utils/columnRenderHelper";

const columns = [
  {
    width: 40,
    type: "selection",
    align: "center",
    fixed: "left"
  },
  {
    prop: "TrackCode",
    width: '150px',
    label: "发货运单编号"
  },
  {
    prop: "outChildCode",
    width: '150px',
    label: "发货工单编号"
  },
  {
    width: '150px',
    label: "发货单编号",
    cellRenderer({ row }) { return row.fhdChild ? row.fhdChild.outCode : '--' }
  },
  {
    prop: "orderCode",
    width: '150px',
    label: "销售订单编号"
  },
  {
    prop: "cgdNo",
    width: '150px',
    label: "采购单编号"
  },
  {
    prop: "status",
    width: '90px',
    label: "状态",
    cellRenderer({ row }) {
      return h(
        ElTag,
        {
          type: orderOptions.find(({ value }) => Number(value) === Number(row.status))?.type || 'info',
          size: "small"
        },
        { default: () => orderOptions.find(({ value }) => Number(value) === Number(row.status))?.label || '--' }
      )
    }
  },
  {
    'min-width': '80px',
    label: "供应商端",
    ...renderProp(hasAccountOptions, "has_account")
  },
  {
    width: '80px',
    label: "订单来源",
    cellRenderer({ row }) {
      return xs_order_source_options.find(({ value }) => String(value) === String(row.fhdChild ? row.fhdChild.order_source : ''))?.label || '--'
    }
  },
  {
    width: '80px',
    label: "商品类型",
    cellRenderer({ row }) {
      return xs_order_type_options.find(({ value }) => String(value) === String(row.fhdChild ? row.fhdChild.order_type : ''))?.label || '--'
    }
  },
  {
    width: '120px',
    label: "商品名称",
    cellRenderer({ row }) {
      return row.fhdChild ? row.fhdChild.good_name : '--'
    }
  },
  {
    width: '120px',
    label: "物流供应商",
    prop: 'supplierName'
  },
  {
    width: '120px',
    label: "业务公司",
    prop: 'companyName'
  },
  {
    width:'90px',
    label: '商品数量',
    cellRenderer({ row }){
      return row.fhdChild ? row.fhdChild.num : '--'
    }
  },
  {
    width: '100px',
    label: "物流费用",
    prop: 'post_fee'
  },
  {
    prop: "remark",
    width: '120px',
    label: "备注"
  },
  {
    prop: "apply_name",
    width: '80px',
    label: "创建人"
  },
  {
    prop: "create_time",
    width: '120px',
    label: "创建时间"
  },
  {
    label: "操作",
    fixed: "right",
    slot: "operation",
    width: 50
  }
];

const contentConfig: ContentConfig = {
  columns,
  apis: {
    httpList,
  }
};

export default contentConfig;
