import myClass from '@/views/TMS/transportation/$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 shipbillColumns = (self, isperson) => {


  return [
    { dataIndex: 'id', title: 'ID', hidden: true },
    { dataIndex: 'shipbillId', title: '运单Id', hidden: true },
    {
      dataIndex: 'shipbillNo',
      title: '运单号',
      width: 160,
      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();
                let routeUrl = self.$router.resolve({
                  path: '/localDetails',
                  query: {shipbillId:record.shipbillId},
                });
                return window.open(routeUrl.href, '_blank');

               // return self.$emit('view', record)
              },
            },
          },
          [self._v(txt ? txt : '')]
        )
      },
    },

    {
      dataIndex: 'cargoOwnerName',
      title: '货主',
      sorter: (a, b) => {
        return a.cargoOwnerName != b.cargoOwnerName
      },
    },

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

      sorter: (a, b) => {
        if (!a.orderNo || !b.orderNo) {
          return
        }
        return a.orderNo.replace(/[^0-9]/gi, '') - b.orderNo.replace(/[^0-9]/gi, '')
      },
    },


    {
      dataIndex: 'orderTypeName',
      title: '订单类型',
      sorter: (a, b) => {
        return a.orderType - b.orderType
      },
    },

    {
      dataIndex: 'deliveryMethodTypeName',
      title: '配送方式',
      align: 'center',
      sorter: (a, b) => {
        return a.deliveryMethodType - b.deliveryMethodType
      },
    },
    {
      dataIndex: 'transportTypeName',
      title: '运输模式',
      sorter: (a, b) => {
        return a.transportType - b.transportType
      },
    },



    ...consignee.init(self), //收
    ...shipper.init(self), //发
    {
      dataIndex: 'totalPcs',
      title: '总件数',
      width: 120,
      sorter: (a, b) => {
        return a.totalPcs - b.totalPcs
      },
    },
    {
      dataIndex: 'totalVolume',
      title: '总体积',
      width: 120,
      sorter: (a, b) => {
        return a.totalVolume - b.totalVolume
      },
    },
    {
      dataIndex: 'totalWeight',
      title: '总重量',
      width: 120,
      sorter: (a, b) => {
        return a.totalWeight - b.totalWeight
      },
    },
    {
      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
      },
    },

    // {
    //   key: 'operation',
    //   title: '操作',
    //   fixed: 'right',
    //   align: 'center',
    //   width:140,
    //   scopedSlots: { customRender: 'operation' },
    // }

  ]
}
