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
  }
}
//表格运单配置
export default class {
  constructor({ key, name, label }) {
    this.key = key
    this.name = name
    this.label = label
    this.customRender = customRender
  }

  init(self) {
    let customRender = this.customRender
    let baseName = this.key
    let title = this.name
    let TYPE = this.key.toUpperCase()

    return [
      {
        dataIndex: baseName + 'TypeName',
        title: title + '类型',
        width: 120,
        // customRender: customRender(self, TYPE + '_TYPE'),
        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,
        width: 120,
        sorter: (a, b) => {
          return a[baseName + 'Name'] != b[baseName + 'Name']
        },
      },
      {
        width: 200,
        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('-')
        },
      },
      {
        width: 120,
        dataIndex: baseName + 'Contact',
        title: title + '联系人',
        sorter: (a, b) => {
          if (baseName + 'Contact') {
            return a[baseName + 'Contact'] != b[baseName + 'Contact']
          }
        },
      },
      {
        width: 160,
        dataIndex: baseName + 'PhoneNumber',
        title: title + '手机号',
        sorter: (a, b) => {
          return a[baseName + 'PhoneNumber'] != b[baseName + 'PhoneNumber']
        },
      },
      {
        width: 160,
        dataIndex: baseName + 'LandlineNumber',
        title: title + '座机号',
        sorter: (a, b) => {
          return a[baseName + 'LandlineNumber'] != b[baseName + 'LandlineNumber']
        },
      },
      {
        width: 160,
        dataIndex: baseName + 'Email',
        title: title + '邮箱',
        sorter: (a, b) => {
          return a[baseName + 'Email'] != b[baseName + 'Email']
        },
      },
      {
        width: 200,
        dataIndex: baseName + 'Address',
        title: title + '详细地址',
        sorter: (a, b) => {
          return a[baseName + 'Address'] != b[baseName + 'Address']
        },
      },
      {
        width: 160,
        dataIndex: baseName + 'Memo',
        title: title + '备注',
        sorter: (a, b) => {
          return a[baseName + 'Memo'] != b[baseName + 'Memo']
        },
      },

    ]
  }





}
