import myClass from '../$common/mainTable/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) => {
  let operation = []
  if (self.operation) {
    operation = [
      {
        key: 'operation',
        title: '操作',
        fixed: 'right',
        align: 'center',
        scopedSlots: { customRender: 'operation' },
        ...self.operation,
      },
    ]
  }
  return [
    { dataIndex: 'id', title: 'ID', hidden: true },
    { dataIndex: 'shipbillId', title: '运单Id', hidden: true },
    {
      dataIndex: 'shipbillNo',
      title: '运单号',
      width: 100,
      sorter: (a, b) => {
        if (!b.shipbillNo || !b.shipbillNo) return
        return a.shipbillNo.replace(/[^0-9]/gi, '') - b.shipbillNo.replace(/[^0-9]/gi, '')
      },
      customRender: (txt, record) => {
        return self._c(
          'a',
          {
            attrs: {
              href: 'javascript:void(0)',
            },
            on: {
              click: (event) => {
                event.stopPropagation()
                return self.$emit('view', record)
              },
            },
          },
          [self._v(txt ? txt : '')]
        )
      },
    },
    {
      dataIndex: 'cargoOwnerName',
      title: '货主',
      sorter: (a, b) => {
        return a.cargoOwnerName != b.cargoOwnerName
      },
    },

    {
      dataIndex: 'orderNo',
      title: '订单号',
      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: '所属部门',
      sorter: (a, b) => {
        return a.departmentName != b.departmentName
      },
    },
    {
      title: '自提司机',
      dataIndex: 'driverName',
      width: 120,
    },
    {
      title: '司机手机号',
      dataIndex: 'driverPhoneNumber',
      width: 120,
    },
    {
      title: '身份证号',
      dataIndex: 'idCrad',
      width: 120,
    },
    {
      dataIndex: 'vehiclePlateNumber',
      title: '车牌号',
      width: 120,
      align: 'center',
      sorter: (a, b) => {
        return a.vehiclePlateNumber != b.vehiclePlateNumber
      },
    },

    {
      dataIndex: 'wmsOrderNo',
      title: 'WMS单号',
      sorter: (a, b) => {
        if (!a.wmsOrderNo || !a.wmsOrderNo) return
        return a.wmsOrderNo.replace(/[^0-9]/gi, '') - b.wmsOrderNo.replace(/[^0-9]/gi, '')
      },
    },

    {
      dataIndex: 'orderTypeName',
      title: '订单类型',
      sorter: (a, b) => {
        return a.orderType - b.orderType
      },
    },
    {
      dataIndex: 'orderBusinessTypeName',
      title: '业务类型',
      sorter: (a, b) => {
        return a.orderBusinessType - b.orderBusinessType
      },
    },
    {
      dataIndex: 'deliveryMethodTypeName',
      title: '配送方式',
      align: 'center',
      sorter: (a, b) => {
        return a.deliveryMethodType - b.deliveryMethodType
      },
    },
    {
      dataIndex: 'transportTypeName',
      title: '运输模式',
      sorter: (a, b) => {
        return a.transportType - b.transportType
      },
    },
    {
      dataIndex: 'temperatureRequirementName',
      title: '温度要求',
      sorter: (a, b) => {
        return a.temperatureRequirement - b.temperatureRequirement
      },
    },

    {
      dataIndex: 'lineName',
      title: '线路',
      sorter: (a, b) => {
        return a.temperatureRequirement != b.temperatureRequirement
      },
    },
    {
      dataIndex: 'memo',
      title: '备注',
      width: 120,
      sorter: (a, b) => {
        return a.temperatureRequirement != b.temperatureRequirement
      },
    },
    {
      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
      },
    },

    // {
    //   dataIndex: 'statusName',
    //   title: '运单状态',
    //   align: 'center',
    //   sorter: (a, b) => {
    //     return a.status - b.status
    //   },
    // },
    // {
    //   dataIndex: 'transportStatusName',
    //   title: '运输状态',
    //   align: 'center',
    //   sorter: (a, b) => {
    //     return a.transportStatus - b.transportStatus
    //   },
    // },
    // {
    //   dataIndex: 'abnormalStatusName',
    //   title: '异常状态',
    //   align: 'center',
    //   sorter: (a, b) => {
    //     return a.abnormalStatus - b.abnormalStatus
    //   },
    // },
    // {
    //   dataIndex: 'scanStatusName',
    //   title: '扫描状态',
    //   align: 'center',
    //   sorter: (a, b) => {
    //     return a.scanStatus - b.scanStatus
    //   },
    // },
    // {
    //   dataIndex: 'carrierTypeName',
    //   title: '承运方类型',
    //   align: 'center',
    //   sorter: (a, b) => {
    //     return a.carrierType - b.carrierType
    //   },
    // },
    // {
    //   dataIndex: 'loadingBillNo',
    //   title: '调度单号',
    //   align: 'center',
    //   sorter: (a, b) => {
    //     if (!a.loadingBillNo || !a.loadingBillNo) return
    //     return a.loadingBillNo.replace(/[^0-9]/gi, '') - b.loadingBillNo.replace(/[^0-9]/gi, '')
    //   },
    // },

    // {
    //   dataIndex: 'carrierName',
    //   title: '承运方',
    //   align: 'center',
    //   sorter: (a, b) => {
    //     return a.carrier - b.carrier
    //   },
    // },
    // {
    //   dataIndex: 'deliverymanName',
    //   title: '送货员姓名',
    //   align: 'center',
    //   sorter: (a, b) => {
    //     return a.deliverymanName != b.deliverymanName
    //   },
    // },

    ...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: 80,
      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)
      },
    },
    ...operation,
  ]
}
