 import myClass from '@/views/TMS/transportation/$common/mainTable/Class.js'
export default (self, expData = []) => {
  let 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
    }
  }

  let consignee = new myClass({ name: '收货方', key: 'consignee', customRender })
  let shipper = new myClass({ name: '发货方', key: 'shipper', customRender })
  return [
    {
      dataIndex: 'shipbillNo',
      title: '运单号',
      width: 200,
      sorter: (a, b) => {
        if (!b.shipbillNo || !b.shipbillNo) return
        return a.shipbillNo.replace(/[^0-9]/gi, '') - b.shipbillNo.replace(/[^0-9]/gi, '')
      },
    },
    { dataIndex: 'itemCode', title: '商品编码', width: 150 },
    { dataIndex: 'itemName', title: '商品名称', width: 150 },
    { dataIndex: 'closingPcs', title: '关闭件数', width: 150 },
    { dataIndex: 'closeperson', title: '关闭人' },
    {
      title: '关闭时间',
      dataIndex: 'closeDt',
      width: 150,
      sorter: (a, b) => {
        return +new Date(a.closeDt) - +new Date(b.closeDt)
      },
    },
    {
      title: '运单关闭类型',
      width: 150,

      dataIndex: 'closeTypeName',
      sorter: (a, b) => {
        return a.closeType - b.closeType
      },
    },
    {
      width: 150,
      title: '运单关闭原因',
      dataIndex: 'closeReason',
    },
    {
      dataIndex: 'cargoOwnerName',
      title: '货主',
      width: 150,
      sorter: (a, b) => {
        return a.cargoOwnerName != b.cargoOwnerName
      },
    },

    {
      dataIndex: 'orderNo',
      title: '订单号',
      width: 200,

      sorter: (a, b) => {
        if (!a.orderNo || !b.orderNo) {
          return
        }
        return a.orderNo.replace(/[^0-9]/gi, '') - b.orderNo.replace(/[^0-9]/gi, '')
      },
    },
    {
      dataIndex: 'departmentName',
      title: '所属部门',
      width: 100,

      sorter: (a, b) => {
        return a.departmentName != b.departmentName
      },
    },

    {
      width: 80,

      dataIndex: 'statusName',
      title: '运单状态',
      align: 'center',
      sorter: (a, b) => {
        return a.status - b.status
      },
    },
    {
      dataIndex: 'transportStatusName',
      title: '运输状态',
      width: 80,

      align: 'center',
      sorter: (a, b) => {
        return a.transportStatus - b.transportStatus
      },
    },
    {
      width: 80,

      dataIndex: 'abnormalStatusName',
      title: '异常状态',
      align: 'center',
      sorter: (a, b) => {
        return a.abnormalStatus - b.abnormalStatus
      },
    },
    {
      width: 80,

      dataIndex: 'scanStatusName',
      title: '扫描状态',
      align: 'center',
      sorter: (a, b) => {
        return a.scanStatus - b.scanStatus
      },
    },
    {
      width: 100,
      dataIndex: 'carrierTypeNameCarrier',
      title: '承运方类型',
      align: 'center',
      sorter: (a, b) => {
        return a.carrierTypeCodeCarrier - b.carrierTypeCodeCarrier
      },
    },
    {
      width: 100,
      dataIndex: 'loadingBillNoCarrier',
      title: '调度单号',
      align: 'center',
      sorter: (a, b) => {
        if (!a.loadingBillNoCarrier || !a.loadingBillNoCarrier) return
        return a.loadingBillNoCarrier.replace(/[^0-9]/gi, '') - b.loadingBillNoCarrier.replace(/[^0-9]/gi, '')
      },
    },
    {
      width: 100,
      dataIndex: 'carrierNameCarrier',
      title: '承运方名称',
      align: 'center',
      sorter: (a, b) => {
        return a.carrierTypeCodeCarrier - b.carrierTypeCodeCarrier
      },
    },
    {
      width: 150,

      dataIndex: 'deliverymanName',
      title: '送货员姓名',
      align: 'center',
      sorter: (a, b) => {
        return a.deliverymanName != b.deliverymanName
      },
    },
    {
      width: 100,
      dataIndex: 'vehiclePlateNumber',
      title: '车牌号',
      align: 'center',
      sorter: (a, b) => {
        return a.vehiclePlateNumber != b.vehiclePlateNumber
      },
    },
    {
      dataIndex: 'wmsOrderNo',
      title: 'WMS单号',
      width: 200,

      sorter: (a, b) => {
        if (!a.wmsOrderNo || !a.wmsOrderNo) return
        return a.wmsOrderNo.replace(/[^0-9]/gi, '') - b.wmsOrderNo.replace(/[^0-9]/gi, '')
      },
    },
    {
      width: 100,
      dataIndex: 'orderTypeName',
      title: '订单类型',
      sorter: (a, b) => {
        return a.orderType - b.orderType
      },
    },
    {
      dataIndex: 'orderBusinessTypeName',
      title: '业务类型',
      width: 100,
      sorter: (a, b) => {
        return a.orderBusinessType - b.orderBusinessType
      },
    },
    {
      dataIndex: 'deliveryMethodTypeName',
      title: '配送方式',
      align: 'center',
      width: 150,
      sorter: (a, b) => {
        return a.deliveryMethodType - b.deliveryMethodType
      },
    },
    {
      dataIndex: 'transportTypeName',
      title: '运输模式',
      width: 150,
      sorter: (a, b) => {
        return a.transportType - b.transportType
      },
    },
    {
      dataIndex: 'temperatureRequirementName',
      title: '温度要求',
      width: 100,
      sorter: (a, b) => {
        return a.temperatureRequirement - b.temperatureRequirement
      },
    },
    {
      dataIndex: 'lineName',
      title: '线路',
      width: 100,
      sorter: (a, b) => {
        return a.temperatureRequirement != b.temperatureRequirement
      },
    },
    {
      dataIndex: 'memo',
      title: '备注',
      width: 120,
      sorter: (a, b) => {
        return a.temperatureRequirement != b.temperatureRequirement
      },
    },
    ...expData,
    {
      dataIndex: 'orderDate',
      title: '订单下单日期',
      width: 120,
      sorter: (a, b) => {
        return +new Date(a.orderDate) - +new Date(b.orderDate)
      },
    },
    {
      dataIndex: 'estimatedPickupStartTime',
      title: '预计提货时间',
      width: 120,
      customRender(text, data) {
        if (!text) {
          return data.estimatedPickupEndTime
        }
        return text
      },
      sorter: (a, b) => {
        return +new Date(a.estimatedPickupStartTime) - +new Date(b.estimatedPickupStartTime)
      },
    },
    {
      dataIndex: 'estimatedDeliveryStartTime',
      title: '预计送达时间',
      width: 120,
      sorter: (a, b) => {
        return +new Date(a.estimatedDeliveryStartTime) - +new Date(b.estimatedDeliveryStartTime)
      },
    },
    {
      dataIndex: 'transportAging',
      title: '时效',
      width: 80,
      sorter: (a, b) => {
        return a.transportAging - b.transportAging
      },
    },

    ...consignee.init(self), //收
    ...shipper.init(self), //发
    {
      dataIndex: 'totalPcs',
      title: '总件数',
      width: 120,
      sorter: (a, b) => {
        return a.totalPcs - b.totalPcs
      },
    },
    {
      dataIndex: 'totalWeight',
      title: '总重量',
      width: 120,
      sorter: (a, b) => {
        return a.totalWeight - b.totalWeight
      },
    },
    {
      dataIndex: 'totalVolume',
      title: '总体积',
      width: 120,
      sorter: (a, b) => {
        return a.totalVolume - b.totalVolume
      },
    },
    {
      dataIndex: 'packageWholePiece',
      title: '整件数',
      width: 120,
      sorter: (a, b) => {
        return a.packageWholePiece - b.packageWholePiece
      },
    },
    {
      dataIndex: 'packageLclPiece',
      title: '拼箱数',
      width: 120,
      sorter: (a, b) => {
        return a.packageLclPiece - b.packageLclPiece
      },
    },
    {
      dataIndex: 'packageTotalWeight',
      title: '包裹总重量',
      width: 120,
      sorter: (a, b) => {
        return a.packageTotalWeight - b.packageTotalWeight
      },
    },
    {
      dataIndex: 'packageTotalVolume',
      title: '包裹总体积',
      width: 120,
      sorter: (a, b) => {
        return a.packageTotalVolume - b.packageTotalVolume
      },
    },

    {
      dataIndex: 'createperson',
      title: '创建人',
      width: 100,
      sorter: (a, b) => {
        return a.createperson != b.createperson
      },
    },
    {
      dataIndex: 'createtime',
      title: '创建时间',
      width: 150,
      sorter: (a, b) => {
        return +new Date(a.createtime) - +new Date(b.createtime)
      },
    },
    {
      dataIndex: 'updateperson',
      title: '修改人',
      width: 100,
      sorter: (a, b) => {
        return a.updateperson != b.updateperson
      },
    },
    {
      dataIndex: 'updatetime',
      title: '修改时间',
      width: 150,
      sorter: (a, b) => {
        return +new Date(a.updatetime) - +new Date(b.updatetime)
      },
    },

  ]
}
