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 setTruckingColumns = (self) => {
  return [
    { dataIndex: 'id', title: 'id', hidden: true,width: 100  },

    { dataIndex: 'loadingBillId', title: '派车单id', hidden: true,width: 100  },
    {
      dataIndex: 'loadingBillNo',
      title: '派车单号',
      width: 200,
      sorter: (a, b) => {
        return a.loadingBillNo.replace(/[^0-9]/gi, '') - b.loadingBillNo.replace(/[^0-9]/gi, '')
      },
    },
    { dataIndex: 'groupName', title: '分组名称' ,width: 100 },
    {
      dataIndex: 'statusName',
      width: 100 ,
      title: '派车单状态',
      sorter: (a, b) => {
        if (!a.statusName) return
        return a.statusName.length - b.statusName.length
      },
    },
    {
      dataIndex: 'shipbillNumber',
      width: 100 ,
      title: '运单数',
      sorter: (a, b) => {
        return a.shipbillNumber - b.shipbillNumber
      },
    },

    {
      dataIndex: 'customerNumber',
      title: '客户数',
      width: 100 ,
      sorter: (a, b) => {
        return a.customerNumber - b.customerNumber
      },
    },
    {
      dataIndex: 'siteNumber',
      title: '总站数',
      width: 100 ,
      sorter: (a, b) => {
        return a.siteNumber - b.siteNumber
      },
    },
    {
      dataIndex: 'pickupStations',
      title: '提货站点数',
      width: 100 ,
      sorter: (a, b) => {
        return a.pickupStations - b.pickupStations
      },
    },
    {
      dataIndex: 'deliveryStations',
      title: '送货站点数',
      width: 100 ,
      sorter: (a, b) => {
        return a.deliveryStations - b.deliveryStations
      },
    },
    {
      dataIndex: 'totalStations',
      title: '总站点数',
      width: 100 ,
      sorter: (a, b) => {
        return a.totalStations - b.totalStations
      },
    },
    {
      dataIndex: 'totalWholePiece',
      title: '总整件数',
      width: 100 ,
      sorter: (a, b) => {
        return a.totalWholePiece - b.totalWholePiece
      },
    },
    {
      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: 'totalMileage',
      title: '总里程数',
      width: 120,
      sorter: (a, b) => {
        return a.totalMileage - b.totalMileage
      },
    },
    { dataIndex: 'shipperName', title: '发货方', width: 120 },
    { dataIndex: 'driverName', title: '司机姓名', width: 120 },
    { dataIndex: 'driverPhoneNumber', title: '司机手机号', width: 120 },
    { dataIndex: 'deliverymanName', title: '送货员姓名', width: 80 },

    { dataIndex: 'deliverymanPhoneNumber', title: '送货员手机号', width: 120 },
    { dataIndex: 'vehiclePlateNumber', title: '车牌号', width: 120 },
    { dataIndex: 'vehicleTypeName', title: '车型', width: 120 },
    { dataIndex: 'volumeLoadingRate', title: '装载率' },
    { 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,
    },
  ]
}
