import myClass from '@/blocks/components/scheduling/js/table/Class.js'

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
  }
}
let consignee = new myClass({ name: '收货方', key: 'consignee', customRender })
let shipper = new myClass({ name: '发货方', key: 'shipper', customRender })

// 主表
export const setMainColumns = (self, expData = []) => {
  return [
    {
      dataIndex: 'reserveNumber',
      title: '预约号',
      width: 120,
      sorter: (a, b) => {
        if (!a.reserveNumber || !b.reserveNumber) {
          return
        }
        return a.reserveNumber.replace(/[^0-9]/gi, '') - b.reserveNumber.replace(/[^0-9]/gi, '')
      },
    },
    {
      dataIndex: 'appointmentTypeName',
      title: '预约类型',
      width: 120,
      sorter: (a, b) => {
        return a.appointmentType - b.appointmentType
      },
    },
    {
      dataIndex: 'statusName',
      title: '预约状态',
      width: 120,
      sorter: (a, b) => {
        return a.status - b.status
      },
    },
    {
      dataIndex: 'queueNumber',
      title: '排队号',
      width: 120,
      sorter: (a, b) => {
        return a.queueNumber - b.queueNumber
      },
    },
    {
      dataIndex: 'queueNumberTime',
      title: '取号时间',
      width: 120,
      sorter: (a, b) => {
        return +new Date(a.queueNumberTime) - +new Date(b.queueNumberTime)
      },
    },
    {
      dataIndex: 'callNumber',
      title: '叫号顺序',
      width: 120,
      sorter: (a, b) => {
        return a.callNumber - b.callNumber
      },
    },
    {
      dataIndex: 'urgentQuantity',
      title: '紧急运单数量',
      width: 120,
      sorter: (a, b) => {
        return a.urgentQuantity - b.urgentQuantity
      },
    },
    {
      dataIndex: 'branchName',
      title: '预约地点',
      width: 120,
      sorter: (a, b) => {
        return a.branchName.length - b.branchName.length
      },
    },
    {
      dataIndex: 'loadingBillIds',
      title: '派车单号',
      width: 120,
      sorter: (a, b) => {
        if (!a.loadingBillIds || !b.loadingBillIds) {
          return
        }
        return a.loadingBillIds.replace(/[^0-9]/gi, '') - b.loadingBillIds.replace(/[^0-9]/gi, '')
      },
    },
    {
      dataIndex: 'branchAddress',
      title: '预约位置',
      width: 120,
      sorter: (a, b) => {
        return a.branchAddress.length - b.branchAddress.length
      },
    },
    {
      dataIndex: 'reserveNumberTime',
      title: '预约时间',
      width: 120,
      sorter: (a, b) => {
        return +new Date(a.reserveNumberTime) - +new Date(b.reserveNumberTime)
      },
    },
    {
      dataIndex: 'driverName',
      title: '预约司机',
      width: 120,
      sorter: (a, b) => {
        return a.driverName.length - b.driverName.length
      },
    },
    {
      dataIndex: 'driverPhoneNumber',
      title: '预约电话',
      width: 120,
      sorter: (a, b) => {
        return a.driverPhoneNumber - b.driverPhoneNumber
      },
    },
    {
      dataIndex: 'vehiclePlateNumber',
      title: '车牌号',
      width: 120,
      sorter: (a, b) => {
        return a.vehiclePlateNumber - b.vehiclePlateNumber
      },
    },
    {
      dataIndex: 'carrierName',
      title: '承运商',
      width: 120,
      sorter: (a, b) => {
        return a.carrierName.length - b.carrierName.length
      },
    },
    {
      dataIndex: 'shipbillQuantity',
      title: '运单数',
      width: 120,
      sorter: (a, b) => {
        return a.shipbillQuantity - b.shipbillQuantity
      },
    },
    {
      dataIndex: 'totalPcs',
      title: '总件数',
      width: 120,
      sorter: (a, b) => {
        return a.totalPcs - b.totalPcs
      },
    },
    ...expData,
    {
      dataIndex: 'createperson',
      title: '创建人',
      width: 120,
      sorter: (a, b) => {
        return a.createperson.length - b.createperson.length
      },
    },
    {
      dataIndex: 'createtime',
      title: '创建时间',
      width: 120,
      sorter: (a, b) => {
        return +new Date(a.createtime) - +new Date(b.createtime)
      },
    },
    {
      dataIndex: 'updateperson',
      title: '修改人',
      width: 120,
      sorter: (a, b) => {
        return a.updateperson.length - b.updateperson.length
      },
    },
    {
      dataIndex: 'updatetime',
      title: '修改时间',
      width: 120,
      sorter: (a, b) => {
        return +new Date(a.updatetime) - +new Date(b.updatetime)
      },
    },
    {
      key: 'operation',
      title: '操作',
      width: 180,
      fixed: 'right',
      align: 'center',
      scopedSlots: { customRender: 'operation' },
    },
  ]
}

// 运单 takeNumber.vue 取号管理-取号 使用
export const setWaybill2Columns = (self, expData = []) => {
  return [
    {
      dataIndex: 'shipbillNo',
      title: '运单号',
      width: 120,
      sorter: (a, b) => {
        if (!a.shipbillNo || !b.shipbillNo) return
        return a.shipbillNo.replace(/[^0-9]/gi, '') - b.shipbillNo.replace(/[^0-9]/gi, '')
      },
    },
    {
      dataIndex: 'cargoOwnerName',
      title: '货主',
      width: 120,
      sorter: (a, b) => {
        return a.cargoOwnerName != b.cargoOwnerName
      },
    },
    {
      dataIndex: 'orderNo',
      title: '订单号',
      width: 120,
      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: 120,
      sorter: (a, b) => {
        return a.departmentName.length - b.departmentName.length
      },
    },
    {
      dataIndex: 'statusName',
      title: '运单状态',
      width: 120,
      sorter: (a, b) => {
        return a.status - b.status
      },
    },
    {
      dataIndex: 'transportStatusName',
      title: '运输状态',
      width: 120,
      sorter: (a, b) => {
        return a.transportStatus - b.transportStatus
      },
    },
    {
      dataIndex: 'abnormalStatusName',
      title: '异常状态',
      width: 120,
      sorter: (a, b) => {
        return a.abnormalStatus - b.abnormalStatus
      },
    },
    {
      dataIndex: 'scanStatusName',
      title: '扫描状态',
      width: 120,
      sorter: (a, b) => {
        return a.scanStatus - b.scanStatus
      },
    },
    {
      dataIndex: 'carrierTypeName',
      title: '承运方类型',
      width: 120,
      sorter: (a, b) => {
        return a.carrierType - b.carrierType
      },
    },
    {
      dataIndex: 'carrierName',
      title: '承运方名称',
      width: 120,
      sorter: (a, b) => {
        return a.carrierName.length - b.carrierName.length
      },
    },
    {
      dataIndex: 'deliverymanName',
      title: '送货员姓名',
      width: 120,
      sorter: (a, b) => {
        return a.deliverymanName.length - b.deliverymanName.length
      },
    },
    {
      dataIndex: 'wmsOrderNo',
      title: 'WMS单号',
      width: 120,
      sorter: (a, b) => {
        return a.wmsOrderNo != b.wmsOrderNo
      },
    },
    {
      dataIndex: 'orderTypeName',
      title: '订单类型',
      width: 120,
      sorter: (a, b) => {
        return a.orderType - b.orderType
      },
    },
    {
      dataIndex: 'orderBusinessTypeName',
      title: '业务类型',
      width: 120,
      sorter: (a, b) => {
        return a.orderBusinessType - b.orderBusinessType
      },
    },
    {
      dataIndex: 'deliveryMethodTypeName',
      title: '配送方式',
      width: 120,
      sorter: (a, b) => {
        return a.deliveryMethodType - b.deliveryMethodType
      },
    },
    {
      dataIndex: 'transportTypeName',
      title: '运输模式',
      width: 120,
      sorter: (a, b) => {
        return a.transportType - b.transportType
      },
    },
    {
      dataIndex: 'temperatureRequirementName',
      title: '温度要求',
      width: 120,
      sorter: (a, b) => {
        return a.temperatureRequirement - b.temperatureRequirement
      },
    },
    {
      dataIndex: 'lineName',
      title: '线路',
      width: 120,
      sorter: (a, b) => {
        return a.lineName == b.lineName
      },
    },
    {
      dataIndex: 'memo',
      title: '备注',
      width: 120,
      sorter: (a, b) => {
        return a.memo == b.memo
      },
    },
    ...expData,
    {
      dataIndex: 'orderDate',
      title: '订单下单日期',
      width: 120,
      sorter: (a, b) => {
        return +new Date(a.orderDate) - +new Date(b.orderDate)
      },
    },
    {
      dataIndex: 'estimatedPickupStartTime',
      title: '预计提货时间',
      width: 120,
      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: 120,
      sorter: (a, b) => {
        return a.transportAging - b.transportAging
      },
    },
    ...shipper.init(self), //发
    ...consignee.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
      },
    },
  ]
}