import { energyAlarmApi } from '/@/api/alarmManagement/energyAlarm';
import { dict } from '/@/api';
import { ref } from 'vue';
import { getEnum } from '/@/api';

const orgId = ref('');
const result = JSON.parse(sessionStorage.getItem('ORGID')!);
orgId.value = result;
const tableKeyMap = [
  {
    title: '序号',
    dataIndex: 'address',
    width: 80,
    customRender: (text: any) => {
      return text.index + 1;
    },
  },
  {
    title: '告警编号',
    dataIndex: 'alarmCode',
  },
  {
    title: '告警描述',
    dataIndex: 'alarmTitle',
  },
  {
    title: '类型',
    dataIndex: 'dataSourcesTypeName',
  },
  {
    title: '优先级',
    dataIndex: 'priority',
  },
  {
    title: '状态',
    dataIndex: 'alarmLogState',
  },
  {
    title: '错误码',
    dataIndex: 'errorCode',
  },
  {
    title: '监测点位',
    dataIndex: 'monitoringPoints',
  },
  {
    title: '更新时间',
    dataIndex: 'updateTime',
  },
  {
    title: '重复次数',
    dataIndex: 'alarmRepetitions',
  },
];
export const notificationtableConfig = (look: any, status: any) => {
  return {
    title: '告警记录',
    api: energyAlarmApi.getTableList,
    headerActions: [{}],
    scroll: { x: 2000 },
    columns: tableKeyMap,
    // rowSelection: null, 选择按钮
    columnActions: {
      title: '操作',
      actions: [
        {
          label: '详情',
          name: 'FeedBackDetail',
          dynamicParams: ['uuid', 'appealType'],
          handle: (data: any) => {
            look.value.toggle(data);
          },
        },
        {
          label: '状态',
          name: 'FeedBackDetail',
          dynamicParams: ['uuid', 'appealType'],
          handle: (data: any) => {
            status.value.toggle(data);
          },
        },
      ],
    },

    formConfig: {
      schemas: [
        {
          field: 'dataSourcesType',
          label: '类型',
          component: 'nsSelectApi',
          // dynamicParams: {
          //   id: 'deviceName', //帮定上级联动数据
          // },
          componentProps: {
            api: () => dict({ params: { dicKey: 'ENERGY_TYPE' } }),
            immediate: true,
            allowClear: true,
            labelField: 'cnValue',
            valueField: 'id',
            placeholder: '请选择类型',
            showSearch: true,
            filterOption: (input: string, option: any) => {
              return option.cnValue.toLowerCase().indexOf(input.toLowerCase()) >= 0;
            },
            // autoSelectFirst: true,
          },
        },
        {
          field: 'priority',
          label: '优先级',
          component: 'nsSelectApi',
          // dynamicParams: {
          //   id: 'deviceName', //帮定上级联动数据
          // },
          componentProps: {
            api: () => getEnum({ params: { enumType: 'PriorityEnum' } }),
            immediate: true,
            allowClear: true,
            resultField: 'data',
            labelField: 'label',
            valueField: 'value',
            placeholder: '请选择告警优先级',
            showSearch: true,
            filterOption: (input: string, option: any) => {
              return option.label.toLowerCase().indexOf(input.toLowerCase()) >= 0;
            },
            // autoSelectFirst: true,
          },
        },
        {
          field: 'alarmLogState',
          label: '状态',
          component: 'nsSelectApi',
          // dynamicParams: {
          //   id: 'deviceName', //帮定上级联动数据
          // },
          componentProps: {
            api: () => getEnum({ params: { enumType: 'AlarmLogStateEnum' } }),
            immediate: true,
            allowClear: true,
            resultField: 'data',
            labelField: 'label',
            valueField: 'value',
            placeholder: '请选择状态',
            showSearch: true,
            filterOption: (input: string, option: any) => {
              return option.label.toLowerCase().indexOf(input.toLowerCase()) >= 0;
            },
            // autoSelectFirst: true,
          },
        },
        {
          field: 'errorCode',
          label: '错误码',
          component: 'NsSelectApi',
          componentProps: {
            allowClear: true,
            placeholder: '请选择错误码',
            autoSelectFirst: false,
            api: energyAlarmApi.getCodeList,
            resultField: 'data',
            labelField: 'errorCode',
            valueField: 'errorCode',
          },
        },
        {
          field: 'createTime',
          label: '数据日期',
          component: 'NsRangePicker',
          allowClear: true,
          fieldMap: ['startTime', 'endTime'],
          componentProps: {
            valueFormat: 'YYYY-MM-DD',
            placeholder: ['开始日期', '结束日期'],
          },
        },
      ],
    },
    params: { orgId: orgId.value },
    // pagination: { pageSizeOptions: false },
    rowKey: 'id',
  };
};
