import { BasicColumn, FormSchema } from '@jdlinker/ui';
import { Badge, Space } from 'ant-design-vue';
import dayjs from 'dayjs';

export const statusMap = {
  online: <Badge status="success" text="在线" />,
  offline: <Badge status="error" text="离线" />,
  notActive: <Badge status="processing" text="禁用" />,
};

//列表数据
export const columns: BasicColumn[] = [
  {
    title: '设备编号',
    align: 'center',
    dataIndex: 'id',
  },
  {
    title: '设备名称',
    align: 'center',
    dataIndex: 'name',
  },
  {
    title: '产品名称',
    align: 'center',
    dataIndex: 'productName',
  },
  {
    title: '注册时间',
    align: 'center',
    dataIndex: 'registryTime',
    customRender: ({ text }) => {
      return <span>{text ? dayjs(text).format('YYYY-MM-DD HH:mm:ss') : ''}</span>;
    },
  },
  {
    title: '状态',
    align: 'center',
    dataIndex: 'state',
    customRender: ({ record }) => {
      return <Space size={0}>{statusMap[record.state.value]}</Space>;
    },
  },
];
//查询数据
export const searchFormSchema: FormSchema[] = [
  {
    label: '设备名称',
    field: 'name',
    component: 'JInput',
  },
  {
    label: '产品名称',
    field: 'productId',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'linker_device_product,name,id',
      placeholder: '请选择产品名称',
    },
  },
];
