import { ColItem } from '@/api/common'
import { elTableAlignLeft, getIntervalValue } from '@/utils/constant'
import moment from 'moment'
import { IDeviceTypeParam, IPoint, IStandardParam, ITeam } from './api/common'

export const deviceTypeCols: ColItem[] = [
  { type: 'selection', width: '50px' },
  { type: 'index', label: '序号', width: '60px' },
  { prop: 'deviceTypeName', label: '设备类型', minWidth: '120px', ...elTableAlignLeft() },
  { prop: 'dataUploadTime', label: '数据刷新时间(min)', width: '140px' },
  { prop: 'icon', label: '图标', width: '100px', _slot: true }
]

export const deviceTypeParamCols: ColItem[] = [
  { type: 'selection', width: '50px' },
  { type: 'index', label: '序号', width: '60px' },
  { prop: 'targetName', label: '参数名称', minWidth: '120px', ...elTableAlignLeft() },
  { prop: 'targetCode', label: '字段名称', minWidth: '120px', ...elTableAlignLeft() },
  { prop: 'targetUnit', label: '单位', minWidth: '120px', ...elTableAlignLeft() },
  {
    prop: 'range',
    label: '量程',
    minWidth: '120px',
    ...elTableAlignLeft(),
    formatter: ({ targetMin, targetMax }: IDeviceTypeParam) => getIntervalValue(targetMin, targetMax)
  },
  {
    prop: 'isshow',
    label: '是否显示',
    width: '80px',
    _slot: true
  }
]

export const standardCols: ColItem[] = [
  { type: 'selection', width: '50px' },
  { type: 'index', label: '序号', width: '60px' },
  { prop: 'standardName', label: '指标标准名称', minWidth: '120px', ...elTableAlignLeft() },
  { prop: 'typeName', label: '设备类型', minWidth: '120px', ...elTableAlignLeft() },
  { prop: 'createUserName', label: '创建人', minWidth: '120px', ...elTableAlignLeft() },
  { prop: 'createTime', label: '创建时间', width: '170px' }
]

export const standardParamCols: ColItem[] = [
  { type: 'selection', width: '50px' },
  { type: 'index', label: '序号', width: '60px' },
  { prop: 'targetName', label: '参数名称', minWidth: '120px', ...elTableAlignLeft() },
  { prop: 'targetUnit', label: '单位', width: '80px', ...elTableAlignLeft() },
  { prop: 'lowerLimit', label: '下限', width: '80px', ...elTableAlignLeft() },
  { prop: 'upperLimit', label: '上限', width: '80px', ...elTableAlignLeft() },
  {
    prop: 'timeRange',
    label: '有效时段',
    width: '120px',
    ...elTableAlignLeft(),
    formatter: ({ biginTime, endTime }: IStandardParam) => getIntervalValue(biginTime, endTime)
  },
  { prop: 'warningName', label: '预警级别', width: '120px', ...elTableAlignLeft() },
  { prop: 'istidings', label: '是否推送预警消息', width: '140px', _slot: true }
]

export const deviceCols: ColItem[] = [
  { type: 'selection', width: '50px' },
  { type: 'index', label: '序号', width: '60px' },
  { prop: 'deviceCode', label: '设备编码', width: '130px', ...elTableAlignLeft() },
  { prop: 'deviceSn', label: 'SN序列号', width: '120px', ...elTableAlignLeft() },
  { prop: 'deviceTypeName', label: '设备类型名称', width: '160px', ...elTableAlignLeft() },
  { prop: 'deviceModel', label: '设备型号', width: '120px', ...elTableAlignLeft() },
  { prop: 'deviceName', label: '设备名称', minWidth: '130px', ...elTableAlignLeft() },
  { prop: 'deviceFirm', label: '设备厂商', width: '110px', ...elTableAlignLeft() },
  { prop: 'firmLiaison', label: '厂商联系人', width: '100px', ...elTableAlignLeft() },
  { prop: 'liaisonPhone', label: '联系人电话', width: '120px', ...elTableAlignLeft() },
  { prop: 'buyTime', label: '采购时间', width: '110px', ...elTableAlignLeft() },
  { prop: 'deviceState', label: '设备状态', width: '80px', _slot: true },
  { prop: 'remark', label: '备注', width: '120px', ...elTableAlignLeft() }
]

export const teamCols: ColItem[] = [
  { type: 'selection', width: '50px' },
  { type: 'index', label: '序号', width: '60px' },
  { prop: 'groupByName', label: '监测分组名称', minWidth: '150px', ...elTableAlignLeft() },
  {
    prop: 'siteCount',
    label: '监测点(个)',
    width: '130px',
    formatter: ({ siteIds }: ITeam) => (siteIds || []).length
  },
  { prop: 'remarks', label: '备注', minWidth: '130px', ...elTableAlignLeft() }
]

export const neighborCols: ColItem[] = [
  { type: 'selection', width: '50px' },
  { type: 'index', label: '序号', width: '60px' },
  { prop: 'siteName', label: '监测站点名称', minWidth: '150px', ...elTableAlignLeft() },
  { prop: 'deviceTypeName', label: '设备类型', minWidth: '130px', ...elTableAlignLeft() },
  { prop: 'upperSiteName', label: '上游监测站点名称', minWidth: '150px', ...elTableAlignLeft() },
  { prop: 'upperDeviceTypeName', label: '上游设备类型', minWidth: '130px', ...elTableAlignLeft() }
]

export const pointCols: ColItem[] = [
  { type: 'selection', width: '50px' },
  { type: 'index', label: '序号', width: '60px' },
  { prop: 'partitionName', label: '排水分区', minWidth: '100px', ...elTableAlignLeft() },
  { prop: 'groupByName', label: '监测分组', minWidth: '100px', ...elTableAlignLeft() },
  { prop: 'siteCode', label: '站点编码', minWidth: '130px', ...elTableAlignLeft() },
  { prop: 'siteName', label: '站点名称', minWidth: '130px', ...elTableAlignLeft() },
  { prop: 'deviceSn', label: '设备SN', minWidth: '100px', ...elTableAlignLeft() },
  { prop: 'deviceTypeName', label: '设备类型', minWidth: '100px', ...elTableAlignLeft() },
  { prop: 'deviceName', label: '设备名称', minWidth: '130px', ...elTableAlignLeft() },
  { prop: 'installPeople', label: '负责人', minWidth: '80px', ...elTableAlignLeft() },
  { prop: 'liaisonPhone', label: '联系方式', minWidth: '120px', ...elTableAlignLeft() },
  { prop: 'siteAddress', label: '安装地址', minWidth: '100px', ...elTableAlignLeft() },
  {
    prop: 'installTime',
    label: '安装时间',
    minWidth: '120px',
    ...elTableAlignLeft(),
    formatter: ({ installTime }: IPoint) => (installTime ? moment(installTime).format('YYYY-MM-DD') : '')
  },
  { prop: 'siteState', label: '站点状态', minWidth: '70px', _slot: true }
]
