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 default (self, expData = []) => {
  return [
    {
      dataIndex: 'shipbillNo',
      sorter: (a, b) => {
        if (!a.shipbillNo || !b.shipbillNo) return
        return a.shipbillNo.replace(/[^0-9]/gi, '') - b.shipbillNo.replace(/[^0-9]/gi, '')
      },
      title: '运单号',
      width: 120,
      customRender: (txt, record) => {
        return self._c(
          'a',
          {
            attrs: {
              href: 'javascript:void(0)',
            },
            on: {
              click: (event) => {
                event.stopPropagation()
                return self.toView(record)
              },
            },
          },
          [self._v(txt)]
        )
      },
    },
    {
      dataIndex: 'expenseNo',
      title: '费用单号',
      width: 120,
      sorter: (a, b) => {
        return a.expenseNo - b.expenseNo
      },
    },
    {
      dataIndex: 'expenseCode',
      title: '费用编码',
      width: 120,
      sorter: (a, b) => {
        return a.expenseCode - b.expenseCode
      },
    },
    {
      dataIndex: 'expenseName',
      title: '费用名称',
      width: 120,
      sorter: (a, b) => {
        return a.expenseCode - b.expenseCode
      },
    },
    {
      dataIndex: 'expenseAccountCode',
      title: '费用科目编码',
      width: 120,
      sorter: (a, b) => {
        return a.expenseAccountCode - b.expenseAccountCode
      },
    },
    {
      dataIndex: 'expenseAccountName',
      title: '费用科目名称',
      width: 120,
      sorter: (a, b) => {
        return a.expenseAccountCode - b.expenseAccountCode
      },
    },
    {
      dataIndex: 'expenseTypeName',
      title: '费用类型',
      width: 120,
      sorter: (a, b) => {
        return a.expenseType - b.expenseType
      },
    },
    {
      dataIndex: 'taxAmt',
      title: '含税金额',
      width: 120,
      sorter: (a, b) => {
        return a.taxAmt - b.taxAmt
      },
    },
    {
      dataIndex: 'noTaxAmt',
      title: '未税金额',
      width: 120,
      sorter: (a, b) => {
        return a.noTaxAmt - b.noTaxAmt
      },
    },
    {
      dataIndex: 'taxPoint',
      title: '税点',
      width: 120,
      sorter: (a, b) => {
        return a.taxPoint - b.taxPoint
      },
    },
    {
      dataIndex: 'tax',
      title: '税额',
      width: 120,
      sorter: (a, b) => {
        return a.tax - b.tax
      },
    },
    {
      dataIndex: 'expenseMemo',
      title: '费用说明',
      width: 120,
      sorter: (a, b) => {
        return a.expenseMemo - b.expenseMemo
      },
    },
    {
      dataIndex: 'billingSourceName',
      title: '费用来源',
      width: 120,
      sorter: (a, b) => {
        return a.billingSource - b.billingSource
      },
    },
    {
      dataIndex: 'checkStatusName',
      title: '结算状态',
      width: 120,
      sorter: (a, b) => {
        return a.checkStatus - b.checkStatus
      },
    },
    {
      dataIndex: 'cargoOwnerName',
      title: '货主',
      width: 120,
      sorter: (a, b) => {
        return a.cargoOwnerCode - b.cargoOwnerCode
      },
    },
    {
      dataIndex: 'orderNo',
      title: '订单号',
      width: 120,
      sorter: (a, b) => {
        return a.orderNo - b.orderNo
      },
    },
    {
      dataIndex: 'settlementCompany',
      title: '结算公司',
      width: 120,
      sorter: (a, b) => {
        return a.settlementCompany - b.settlementCompany
      },
    },
    {
      dataIndex: 'settlementDepartment',
      title: '结算部门',
      width: 120,
      sorter: (a, b) => {
        return a.settlementDepartment - b.settlementDepartment
      },
    },
    {
      dataIndex: 'payAmount',
      title: '支出总价',
      width: 120,
      sorter: (a, b) => {
        return a.payAmount - b.payAmount
      },
    },
    {
      dataIndex: 'contractPayAmount',
      title: '合同支出总价',
      width: 120,
      sorter: (a, b) => {
        return a.contractPayAmount - b.contractPayAmount
      },
    },
    // {
    //   dataIndex: 'transportationPrice',
    //   title: '运费',
    //   width: 120,
    //   sorter: (a, b) => {
    //     return a.transportationPrice - b.transportationPrice
    //   },
    // },
    // {
    //   dataIndex: 'pickUpFee',
    //   title: '提货费',
    //   width: 120,
    //   sorter: (a, b) => {
    //     return a.pickUpFee - b.pickUpFee
    //   },
    // },
    // {
    //   dataIndex: 'deliveryFee',
    //   title: '送货费',
    //   width: 120,
    //   sorter: (a, b) => {
    //     return a.deliveryFee - b.deliveryFee
    //   },
    // },
    {
      dataIndex: 'synchronousStatus',
      title: '同步状态',
      width: 120,
      sorter: (a, b) => {
        return a.synchronousStatus - b.synchronousStatus
      },
    },
    {
      dataIndex: 'synchronousDate',
      title: '同步时间',
      width: 120,
      sorter: (a, b) => {
        return +new Date(a.synchronousDate) - +new Date(b.synchronousDate)
      },
    },

    {
      dataIndex: 'synchronousFailReason',
      title: '同步失败原因',
      width: 120,
      sorter: (a, b) => {
        return a.synchronousFailReason.length - b.synchronousFailReason.length
      },
    },
    {
      dataIndex: 'billingStatusName',
      title: '计费状态',
      width: 120,
      sorter: (a, b) => {
        return a.billingStatus - b.billingStatus
      },
    },
    {
      dataIndex: 'costDate',
      title: '计费时间',
      width: 120,
      sorter: (a, b) => {
        return +new Date(a.costDate) - +new Date(b.costDate)
      },
    },
    {
      dataIndex: 'costContract',
      title: '计费合同',
      width: 120,
      sorter: (a, b) => {
        return a.costContract - b.costContract
      },
    },
    {
      dataIndex: 'costPriceTable',
      title: '计费价格表',
      width: 120,
      sorter: (a, b) => {
        return a.costPriceTable - b.costPriceTable
      },
    },
    {
      dataIndex: 'costType',
      title: '计费类别',
      width: 120,
      sorter: (a, b) => {
        return a.costType - b.costType
      },
    },
    {
      dataIndex: 'costFailReason',
      title: '计费失败原因',
      width: 120,

    },
    {
      dataIndex: 'checkStausName',
      title: '核算状态',
      width: 120,
      sorter: (a, b) => {
        return a.checkStaus - b.checkStaus
      },
    },
    {
      dataIndex: 'settlementDate',
      title: '核算时间',
      width: 120,
      sorter: (a, b) => {
        return +new Date(a.settlementDate) - +new Date(b.settlementDate)
      },
    },
    {
      dataIndex: 'statusName',
      title: '运单状态',
      width: 120,
      sorter: (a, b) => {
        return a.status - b.status
      },
    },
    {
      dataIndex: 'abnormalStatusName',
      title: '异常状态',
      width: 120,
      sorter: (a, b) => {
        return a.abnormalStatus - b.abnormalStatus
      },
    },
    {
      dataIndex: 'carrierTypeName',
      title: '承运方类型',
      width: 120,
      sorter: (a, b) => {
        return a.carrierType - b.carrierType
      },
    },
    {
      dataIndex: 'loadingBillNo',
      title: '调度单号',
      width: 120,
      sorter: (a, b) => {
        return a.loadingBillNo - b.loadingBillNo
      },
    },
    {
      dataIndex: 'carrierName',
      title: '承运方名称',
      width: 120,
      sorter: (a, b) => {
        return a.carrierName.length - b.carrierName.length
      },
    },
    {
      dataIndex: 'deliveryName',
      title: '送货员姓名',
      width: 120,
      sorter: (a, b) => {
        return a.deliveryName.length - b.deliveryName.length
      },
    },
    {
      dataIndex: 'vehicleCode',
      title: '车牌号',
      width: 120,
      sorter: (a, b) => {
        if (!a.vehicleCode || !b.vehicleCode) return
        return a.vehicleCode.replace(/[^0-9]/gi, '') - b.vehicleCode.replace(/[^0-9]/gi, '')
      },
    },
    {
      dataIndex: 'affiliationName',
      title: '隶属机构',
      width: 120,
      sorter: (a, b) => {
        return a.affiliationCode - b.affiliationCode
      },
    },
    {
      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: 'memo',
      title: '备注',
      width: 120,
      sorter: (a, b) => {
        return a.memo - b.memo
      },
    },
    {
      dataIndex: 'orderDate',
      title: '下单时间',
      width: 120,
      sorter: (a, b) => {
        return +new Date(a.orderDate) - +new Date(b.orderDate)
      },
    },
    {
      dataIndex: 'submitDate',
      title: '提交时间',
      width: 120,
      sorter: (a, b) => {
        return +new Date(a.submitDate) - +new Date(b.submitDate)
      },
    },
    {
      dataIndex: 'auditDate',
      title: '审核时间',
      width: 120,
      sorter: (a, b) => {
        return +new Date(a.auditDate) - +new Date(b.auditDate)
      },
    },
    {
      dataIndex: 'loadingDate',
      title: '调度时间',
      width: 120,
      sorter: (a, b) => {
        return +new Date(a.loadingDate) - +new Date(b.loadingDate)
      },
    },
    {
      dataIndex: 'loadingAuditDate',
      title: '调度审核时间',
      width: 120,
      sorter: (a, b) => {
        return +new Date(a.loadingAuditDate) - +new Date(b.loadingAuditDate)
      },
    },
    {
      dataIndex: 'startDate',
      title: '实际启运时间',
      width: 120,
      sorter: (a, b) => {
        return +new Date(a.startDate) - +new Date(b.startDate)
      },
    },
    {
      dataIndex: 'deliveryDate',
      title: '实际送达时间',
      width: 120,
      sorter: (a, b) => {
        return +new Date(a.deliveryDate) - +new Date(b.deliveryDate)
      },
    },
    {
      dataIndex: 'receiptDate',
      title: '回单时间',
      width: 120,
      sorter: (a, b) => {
        return +new Date(a.receiptDate) - +new Date(b.receiptDate)
      },
    },
    {
      dataIndex: 'originalBackDate',
      title: '正本回单时间',
      width: 120,
      sorter: (a, b) => {
        return +new Date(a.originalBackDate) - +new Date(b.originalBackDate)
      },
    },
    {
      dataIndex: 'actualTime',
      title: '实际时效',
      width: 120,
      sorter: (a, b) => {
        return a.actualTime - b.actualTime
      },
    },
    {
      dataIndex: 'completeDate',
      title: '完成时间',
      width: 120,
      sorter: (a, b) => {
        return +new Date(a.completeDate) - +new Date(b.completeDate)
      },
    },
    ...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
      },
    },
    {
      dataIndex: '',
      title: '来源',
      width: 120,
      sorter: (a, b) => {
        return a.packageTotalVolume - b.packageTotalVolume
      },
    },
    {
      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)
      },
    },
  ]
}
