
export default class {
  constructor({ key, name, label, customRender }) {
    this.key = key
    this.name = name
    this.label = label
    this.customRender = customRender
  }
  init(self) {
    let baseName = this.key
    let title = this.name
    return [
      {
        dataIndex: baseName + 'TypeName',
        title: title + '类型',
        sorter: (a, b) => {
          return a[baseName + 'Type'] - b[baseName + 'Type']
        },
      },
      {
        dataIndex: baseName + 'UnitName',
        title: title + '单位',
        width: 100,
        sorter: (a, b) => {
          return a[baseName + 'UnitName'] != b[baseName + 'UnitName']
        },
      },
      {
        dataIndex: baseName + 'Name',
        title: title,
        sorter: (a, b) => {
          return a[baseName + 'Name'] != b[baseName + 'Name']
        },
      },
      {
        width: 150,

        dataIndex: baseName + 'ProvinceCity',
        sorter: (a, b) => {
          return a[baseName + 'ProvinceCity'] != b[baseName + 'ProvinceCity']
        },
        title: baseName == 'consignee' ?title+ '目的地' :title+ '始发地',
        customRender: (text, data) => {
          let provinceName = data[baseName + 'ProvinceName']
          let cityName = data[baseName + 'CityName']
          let districtName = data[baseName + 'DistrictName']
          let arr = [provinceName, cityName, districtName].filter((item) => item && item)
          return arr.join('-')
        },
      },
      {
        dataIndex: baseName + 'Contact',
        title: title + '联系人',
        sorter: (a, b) => {
          if (baseName + 'Contact') {
            return a[baseName + 'Contact'] != b[baseName + 'Contact']
          }
        },
      },
      {
        dataIndex: baseName + 'PhoneNumber',
        title: title + '手机号',
        sorter: (a, b) => {
          return a[baseName + 'PhoneNumber'] != b[baseName + 'PhoneNumber']
        },
      },
      {
        dataIndex: baseName + 'LandlineNumber',
        title: title + '座机号',
        sorter: (a, b) => {
          return a[baseName + 'LandlineNumber'] != b[baseName + 'LandlineNumber']
        },
      },
      {
        dataIndex: baseName + 'Email',
        title: title + '邮箱',
        sorter: (a, b) => {
          return a[baseName + 'Email'] != b[baseName + 'Email']
        },
      },
      {
        dataIndex: baseName + 'Address',
        title: title + '详细地址',
        sorter: (a, b) => {
          return a[baseName + 'Address'] != b[baseName + 'Address']
        },
      },
      {
        dataIndex: baseName + 'Memo',
        title: title + '备注',
        sorter: (a, b) => {
          return a[baseName + 'Memo'] !=b[baseName + 'Memo']
        },
      },
      {
        dataIndex: baseName + 'location',
        title: title + '位置',
        sorter: (a, b) => {
          return a[baseName + 'location'] - b[baseName + 'location']
        },
        customRender: (text, data) => {
          let Latitude = data[baseName + 'Latitude']
          let Longitude = data[baseName + 'Longitude']
          if (Longitude > 0 && Latitude > 0) {
            return '已定位'
          }
          return '未定位'
        },
      },
    ]
  }
}
