const customRender = (self, type) => {
  return (text, data) => {
    if (self.options[type] && Array.isArray(self.options[type])) {
      let value = self.options[type].find((item) => item.value === text);
      return value ? value.label : text;
    }
    return text;
  };
};

//托运单
export const setConsignColumns = (self) => {
  return [
    { dataIndex: 'loadingBillId', title: '托运单号id', hidden: true, width: 100 },
    {
      dataIndex: 'loadingBillNo',
      title: '托运单号',
      width: 200,
      sorter: (a, b) => {
        if (a.loadingBillNo && b.loadingBillNo) {
          return a.loadingBillNo.replace(/[^0-9]/gi, '') - b.loadingBillNo.replace(/[^0-9]/gi, '');
        }
      },
    },
    { dataIndex: 'groupName', title: '分组名称', width: 100 },
    {
      dataIndex: 'statusName',
      title: '托运单状态',
      sorter: (a, b) => {
        if (!a.statusName) return;
        return a.statusName.length - b.statusName.length;
      },
      width: 100,
    },
    {
      dataIndex: 'shipbillNumber',
      title: '运单数',
      sorter: (a, b) => {
        return a.shipbillNumber - b.shipbillNumber;
      },
      width: 100,
    },
    {
      dataIndex: 'customerNumber',
      title: '客户数',
      sorter: (a, b) => {
        return a.customerNumber - b.customerNumber;
      },
      width: 100,
    },
    {
      dataIndex: 'siteNumber',
      title: '总站数',
      sorter: (a, b) => {
        return a.siteNumber - b.siteNumber;
      },
      width: 100,
    },
    {
      dataIndex: 'totalWholePiece',
      title: '总整件数',
      sorter: (a, b) => {
        return a.totalWholePiece - b.totalWholePiece;
      },
      width: 100,
    },
    {
      dataIndex: 'totalLclPiece',
      title: '总拼箱数',
      align: 'center',
      sorter: (a, b) => {
        return a.totalLclPiece - b.totalLclPiece;
      },
      width: 100,
    },
    {
      dataIndex: 'totalPcs',
      title: '总件数',
      sorter: (a, b) => {
        return a.totalPcs - b.totalPcs;
      },
      width: 100,
    },
    {
      dataIndex: 'totalWeight',
      title: '总重量',
      sorter: (a, b) => {
        return a.totalWeight - b.totalWeight;
      },
      width: 100,
    },
    {
      dataIndex: 'totalVolume',
      title: '总体积',
      sorter: (a, b) => {
        return a.totalVolume - b.totalVolume;
      },
      width: 100,
    },

    { dataIndex: 'carrierCode', title: '承运商编码', width: 120 },
    { dataIndex: 'carrierName', title: '承运商名称', width: 120 },

    { dataIndex: 'memo', title: '备注', width: 120 },
    { dataIndex: 'createperson', title: '创建人', width: 100 },
    { dataIndex: 'createtime', title: '创建时间', width: 150 },
    { dataIndex: 'updateperson', title: '修改人', width: 100 },
    { dataIndex: 'updatetime', title: '修改时间', width: 150 },
    {
      key: 'operation',
      title: '操作',
      fixed: 'right',
      align: 'center',
      scopedSlots: { customRender: 'operation' },
      ...self.operation,
    },
  ];
};
